I have two Interface one of which is a callback interface and one implementaion class as following.
[ServiceContract(CallbackContract = typeof(IMonitorCallback))]
interface IMonitor
{
[OperationContract(IsOneWay = true)]
Task AddMonitor(Monitor mo);
[OperationContract(IsOneWay = true)]
Task RemoveMonitor(Monitor mo);
}
interface IMonitorCallback
{
[OperationContract]
void OnAdded(Monitor data);
[OperationContract]
void OnRemoved(Monitor data);
}
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single)]
public class Monitor : IMonitor
{
public Task AddMonitor(Monitor mo)
{}
public Task RemoveMonitor(Monitor mo)
{}
}
Now i want to call this method from unit test one after the another (in a single test method). I am able to call the AddMonitor but when i call the Remove method its not hitting the service method. Code is given below.
[TestClass]
public class Test
{
private Monitor monitor = null;
private IMonitor proxy = null;
private DuplexChannelFactory<IMonitor> channelFactory;
private ManualResetEvent mutex = new ManualResetEvent(false);
// This class for callback implementation
private MonitorCallback monitorCallback = null;
public void TestInitialize()
{
this.monitor = new Monitor();
// Hosting is done here
this.monitor.Initialize();
this.monitorCallback = new MonitorCallback();
this.monitorCallback.OnDataValueChanged += () =>
{
if (null != this.valueChangedMutex)
{
this.valueChangedMutex.Set();
}
};
this.channelFactory = new DuplexChannelFactory<IMonitor>(this.monitorCallback,
new NetTcpBinding(),
this.clientAddress);
try
{
this.proxy = this.channelFactory.CreateChannel();
}
catch
{
if (null != proxy)
{
((ICommunicationObject)proxy).Abort();
this.proxy = null;
}
throw;
}
}
[TestMethod]
[TestCategory("StatusMonitor")]
public async Task TestRemoveMonitor()
{
this.mutex.Reset();
await this.proxy.AddMonitor(mo);
this.mutex.WaitOne(30000);
this.mutex.Reset();
await this.proxy.RemoveMonitor(mo);
this.mutex.WaitOne(10000);
}
}
Can someone provide me a solution for this.