public async Task InvokeAsync_ValidationErrors() { var mockDomainClient = new CitiesMockDomainClient(); ValidationResult[] validationErrors = new ValidationResult[] { new ValidationResult("Foo", new string[] { "Bar" }) }; mockDomainClient.InvokeCompletedResult = Task.FromResult(new InvokeCompletedResult(null, validationErrors)); Cities.CityDomainContext ctx = new Cities.CityDomainContext(mockDomainClient); var ex = await ExceptionHelper.ExpectExceptionAsync <DomainOperationException>( () => ctx.EchoAsync("TestInvoke"), string.Format(Resource.DomainContext_InvokeOperationFailed_Validation, "Echo")); // verify the exception properties Assert.AreEqual(OperationErrorStatus.ValidationFailed, ex.Status); CollectionAssert.AreEqual(validationErrors, (ICollection)ex.ValidationErrors); }
public async Task InvokeAsync_DomainOperationException() { var mockDomainClient = new CitiesMockDomainClient(); DomainOperationException exception = new DomainOperationException("Operation Failed!", OperationErrorStatus.ServerError, 42, "StackTrace"); mockDomainClient.InvokeCompletedResult = Task.FromException <InvokeCompletedResult>(exception); Cities.CityDomainContext ctx = new Cities.CityDomainContext(mockDomainClient); var ex = await ExceptionHelper.ExpectExceptionAsync <DomainOperationException>( () => ctx.EchoAsync("TestInvoke"), string.Format(Resource.DomainContext_InvokeOperationFailed, "Echo", exception.Message)); // verify the exception properties Assert.AreEqual(null, ex.InnerException); Assert.AreEqual(ex.StackTrace, exception.StackTrace); Assert.AreEqual(ex.Status, exception.Status); Assert.AreEqual(ex.ErrorCode, exception.ErrorCode); }
public async Task InvokeAsync_Cancel_DomainClientCancel() { var mockDomainClient = new CitiesMockDomainClient(); Cities.CityDomainContext ctx = new Cities.CityDomainContext(mockDomainClient); // If cancellation results in request beeing cancelled the result should be cancelled var tcs = new TaskCompletionSource <InvokeCompletedResult>(); using var cts = new CancellationTokenSource(); mockDomainClient.InvokeCompletedResult = tcs.Task; var invokeTask = ctx.EchoAsync("TestInvoke", cts.Token); cts.Cancel(); tcs.TrySetCanceled(cts.Token); await ExceptionHelper.ExpectExceptionAsync <TaskCanceledException>(() => invokeTask); Assert.IsTrue(invokeTask.IsCanceled); }
public async Task InvokeAsync_Cancel_DomainClientCompletes() { var mockDomainClient = new CitiesMockDomainClient(); Cities.CityDomainContext ctx = new Cities.CityDomainContext(mockDomainClient); // If the web requires returns a value even if cancelled // It should still return a result var tcs = new TaskCompletionSource <InvokeCompletedResult>(); using var cts = new CancellationTokenSource(); mockDomainClient.InvokeCompletedResult = tcs.Task; var invokeTask = ctx.EchoAsync("TestInvoke", cts.Token); cts.Cancel(); tcs.SetResult(new InvokeCompletedResult("Res")); var res = await invokeTask; Assert.AreEqual("Res", res.Value); }