public async void StartHostAndClient_SimpleSyncMethodSyncCallWithAsync_Success() { bool @continue = false; var thread = new System.Threading.Thread(() => { using (var host = new WcfExampleServiceHost("localhost:10000")) { host.Start(); @continue = true; while (@continue) { System.Threading.Thread.Sleep(10); } host.Close(); } }); thread.Start(); while (!@continue) { System.Threading.Thread.Sleep(10); } var client = new WcfExampleServiceAsyncClient("localhost:10000"); SimpleSyncMethodResponseModel responseSimpleSyncMethod = client.SimpleSyncMethod(new SimpleSyncMethodRequestModel { Message = "Hello World" }); Assert.IsNotNull(responseSimpleSyncMethod); Assert.AreEqual("SimpleSyncMethod: Hello World", responseSimpleSyncMethod.Message); @continue = false; thread.Join(); }
public async void StartHostAndClient_SimpleSyncMethodAsyncCall_Success() { using (var host = new WcfExampleServiceHost("localhost:10000")) { host.Start(); var client = new WcfExampleServiceAsyncClient("localhost:10000"); SimpleSyncMethodResponseModel responseSimpleSyncMethod = await client.SimpleSyncMethodAsync(new SimpleSyncMethodRequestModel { Message = "Hello World" }); Assert.IsNotNull(responseSimpleSyncMethod); Assert.AreEqual("SimpleSyncMethod: Hello World", responseSimpleSyncMethod.Message); host.Close(); } }
public async void StartHostAndClient_SimpleSyncMethodSyncCallWithAsync_ThrowsException() { // If I uses using - then unit test never ends. // using (var host = new WcfExampleServiceHost("localhost:10000")) // { var host = new WcfExampleServiceHost("localhost:10000"); host.Start(); var client = new WcfExampleServiceAsyncClient("localhost:10000"); SimpleSyncMethodResponseModel responseSimpleSyncMethod = null; Assert.Throws<CommunicationException>(() => { try { responseSimpleSyncMethod = client.SimpleSyncMethod(new SimpleSyncMethodRequestModel { Message = "Hello World" }); } catch (Exception ex) { throw; } }); Assert.IsNull(responseSimpleSyncMethod); // Close client. client.Abort(); client.Close(); var d = client as IDisposable; d.Dispose(); // If I close and disponse - then unit test never ends. // host.Close(); // host.Dispose(); // } }
public async void StartHostAndClient_SimpleTaskMethodAsyncCall_Success() { using (var host = new WcfExampleServiceHost("localhost:10000")) { host.Start(); var client = new WcfExampleServiceAsyncClient("localhost:10000"); SimpleTaskMethodResponseModel responseSimpleTaskMethod = await client.SimpleTaskMethod(new SimpleTaskMethodRequestModel { Size = 100 }); Assert.IsNotNull(responseSimpleTaskMethod); Assert.IsNotNull(responseSimpleTaskMethod.Result); Assert.AreEqual(100, responseSimpleTaskMethod.Result.Length); host.Close(); } }
public async void StartHostAndClient_SimpleTaskMethodSyncCall2_Success() { using (var host = new WcfExampleServiceHost("localhost:10000")) { host.Start(); var client = new WcfExampleServiceAsyncClient("localhost:10000"); Task<SimpleTaskMethodResponseModel> responseSimpleTaskMethod = client.SimpleTaskMethod(new SimpleTaskMethodRequestModel { Size = 100 }); Assert.IsNotNull(responseSimpleTaskMethod); while (!responseSimpleTaskMethod.IsCompleted) { // Do some work! await Task.Factory.StartNew(() => System.Threading.Thread.Sleep(10)); } Assert.IsTrue(responseSimpleTaskMethod.IsCompleted); Assert.IsFalse(responseSimpleTaskMethod.IsCanceled); Assert.IsFalse(responseSimpleTaskMethod.IsFaulted); Assert.IsNotNull(responseSimpleTaskMethod.Result); Assert.IsNotNull(responseSimpleTaskMethod.Result.Result); Assert.AreEqual(100, responseSimpleTaskMethod.Result.Result.Length); host.Close(); } }
public async void StartHostAndClient_SimpleTaskMethodSyncCall1_Success() { using (var host = new WcfExampleServiceHost("localhost:10000")) { host.Start(); var client = new WcfExampleServiceAsyncClient("localhost:10000"); Task<SimpleTaskMethodResponseModel> responseSimpleTaskMethod = client.SimpleTaskMethod(new SimpleTaskMethodRequestModel { Size = 100 }); Assert.IsNotNull(responseSimpleTaskMethod); await responseSimpleTaskMethod; Assert.IsTrue(responseSimpleTaskMethod.IsCompleted); Assert.IsFalse(responseSimpleTaskMethod.IsCanceled); Assert.IsFalse(responseSimpleTaskMethod.IsFaulted); Assert.IsNotNull(responseSimpleTaskMethod.Result); Assert.IsNotNull(responseSimpleTaskMethod.Result.Result); Assert.AreEqual(100, responseSimpleTaskMethod.Result.Result.Length); host.Close(); } }