public async Task TestActionServiceInOutDatabaseValidationOk(int num, bool hasErrors) { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var bizInstance = new BizActionInOutWriteDbAsync(context); var runner = new ActionServiceAsync <IBizActionInOutWriteDbAsync>(context, bizInstance, _wrappedConfig); var input = new ServiceLayerBizInDto { Num = num }; //ATTEMPT var data = await runner.RunBizActionAsync <BizDataOut>(input); //VERIFY bizInstance.HasErrors.ShouldEqual(hasErrors); if (hasErrors) { context.LogEntries.Any().ShouldBeFalse(); input.SetupSecondaryDataCalled.ShouldBeFalse(); data.ShouldBeNull(); } else { context.LogEntries.Single().LogText.ShouldEqual(num.ToString()); data.Output.ShouldEqual(num.ToString()); } } }
public async Task TestActionServiceAsyncInOutAsyncDtosOk(int num, bool hasErrors) { //SETUP var mapper = SetupHelpers.CreateMapper <ServiceLayerBizInDtoAsync, ServiceLayerBizOutDtoAsync>(); var bizInstance = new BizActionInOutAsync(); var runner = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, bizInstance, mapper, _noCachingConfig); var input = new ServiceLayerBizInDtoAsync { Num = num }; //ATTEMPT var data = await runner.RunBizActionAsync <ServiceLayerBizOutDtoAsync>(input); //VERIFY bizInstance.HasErrors.ShouldEqual(hasErrors); if (hasErrors) { data.ShouldBeNull(); bizInstance.Message.ShouldEqual("Failed with 1 error"); } else { data.Output.ShouldEqual(num.ToString()); } }
public async Task TestGetDtoGenericActionsDtoBad() { //SETUP var service = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, new BizActionInOutAsync(), _mapper, _noCachingConfig); //ATTEMPT var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.GetDtoAsync <ServiceLayerBizOutDto>()); //VERIFY ex.Message.ShouldEqual("Indirect copy to biz action. from type = ServiceLayerBizOutDto, to type BizDataIn. Expected a DTO of type GenericActionToBizDto<BizDataIn,ServiceLayerBizOutDto>"); }
public async Task TestGetDtoGenericActionsDtoOutOnlyBad() { //SETUP var service = new ActionServiceAsync <IBizActionOutOnly>(_emptyDbContext, new BizActionOutOnly(), _mapper, _noCachingConfig); //ATTEMPT var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await service.GetDtoAsync <ServiceLayerBizInDto>()); //VERIFY ex.Message.ShouldEqual("The action with interface of IBizActionOutOnly does not have an input, but you called it with a method that needs an input."); }
public async Task TestGetDtoDirectOk() { //SETUP var service = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, new BizActionInOutAsync(), _mapper, _noCachingConfig); //ATTEMPT var data = await service.GetDtoAsync <BizDataIn>(); //VERIFY data.ShouldNotBeNull(); data.ShouldBeType <BizDataIn>(); }
public async Task TestCallHasNoInputBad() { //SETUP var bizInstance = new BizActionInOutAsync(); var runner = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, bizInstance, _mapper, _noCachingConfig); //ATTEMPT var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await runner.RunBizActionAsync <string>()); //VERIFY ex.Message.ShouldEqual("Your call of IBizActionInOutAsync needed 'Out, Async' but the Business class had a different setup of 'InOut, Async'"); }
public async Task TestActionServiceOutOnlyDirectOk() { //SETUP var bizInstance = new BizActionOutOnlyAsync(); var runner = new ActionServiceAsync <IBizActionOutOnlyAsync>(_emptyDbContext, bizInstance, _mapper, _noCachingConfig); //ATTEMPT var data = await runner.RunBizActionAsync <BizDataOut>(); //VERIFY bizInstance.HasErrors.ShouldBeFalse(); data.Output.ShouldEqual("Result"); }
public async Task TestInputIsBad() { //SETUP var bizInstance = new BizActionInOutAsync(); var runner = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, bizInstance, _wrappedConfig); var input = "string"; //ATTEMPT var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await runner.RunBizActionAsync <string>(input)); //VERIFY ex.Message.ShouldEqual("Indirect copy to biz action. from type = String, to type BizDataIn. Expected a DTO of type GenericActionToBizDto<BizDataIn,String>"); }
public async Task TestGetDtoGenericActionsDtoOk() { //SETUP var service = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, new BizActionInOutAsync(), _mapper, _noCachingConfig); //ATTEMPT var data = await service.GetDtoAsync <ServiceLayerBizInDto>(); //VERIFY data.ShouldNotBeNull(); data.ShouldBeType <ServiceLayerBizInDto>(); data.SetupSecondaryDataCalled.ShouldEqual(true); }
public async Task TestGetDtoGenericActionsDtoAsyncOkAithAction() { //SETUP var service = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, new BizActionInOutAsync(), _wrappedConfig); //ATTEMPT var data = await service.GetDtoAsync <ServiceLayerBizInDtoAsync>(x => { x.Num = 2; }); //VERIFY data.ShouldNotBeNull(); data.ShouldBeType <ServiceLayerBizInDtoAsync>(); data.SetupSecondaryDataCalled.ShouldEqual(true); data.Num.ShouldEqual(2); }
public async Task TestActionServiceOutOnlyDtosOk() { //SETUP var mapper = SetupHelpers.CreateMapper <ServiceLayerBizInDto, ServiceLayerBizOutDto>(); var bizInstance = new BizActionOutOnlyAsync(); var runner = new ActionServiceAsync <IBizActionOutOnlyAsync>(_emptyDbContext, bizInstance, mapper, _noCachingConfig); //ATTEMPT var data = await runner.RunBizActionAsync <ServiceLayerBizOutDto>(); //VERIFY bizInstance.HasErrors.ShouldBeFalse(); data.Output.ShouldEqual("Result"); }
public async Task TestInputIsBad() { //SETUP var utData = new NonDiBizSetup(_noCachingConfig); var bizInstance = new BizActionOutOnlyAsync(); var runner = new ActionServiceAsync <IBizActionOutOnlyAsync>(_emptyDbContext, bizInstance, utData.WrappedConfig); var input = "string"; //ATTEMPT var ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await runner.RunBizActionAsync <string>(input)); //VERIFY ex.Message.ShouldEqual("Your call of IBizActionOutOnlyAsync needed 'InOut, Async' but the Business class had a different setup of 'Out, Async'"); }
public async Task TestActionServiceErrorInSetupOk() { //SETUP var bizInstance = new BizActionInOnlyAsync(); var runner = new ActionServiceAsync <IBizActionInOnlyAsync>(_emptyDbContext, bizInstance, _wrappedConfig); var input = await runner.GetDtoAsync <ServiceLayerBizInDto>(x => { x.RaiseErrorInSetupSecondaryData = true; }); //ATTEMPT await runner.RunBizActionAsync(input); //VERIFY bizInstance.HasErrors.ShouldEqual(true); bizInstance.Errors.Single().ErrorResult.ErrorMessage.ShouldEqual("Error in SetupSecondaryData"); }
public async Task TestSqlErrorHandlerWorksOkAsync(int sqlErrorCode, bool shouldThrowException) { IStatusGeneric CatchUniqueError(Exception e, DbContext context) { var dbUpdateEx = e as DbUpdateException; var sqliteError = dbUpdateEx?.InnerException as SqliteException; return(sqliteError?.SqliteErrorCode == sqlErrorCode ? new StatusGenericHandler().AddError("Unique constraint failed") : null); } //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); context.UniqueEntities.Add(new UniqueEntity { UniqueString = "Hello" }); context.SaveChanges(); var config = new GenericBizRunnerConfig { TurnOffCaching = true, SaveChangesExceptionHandler = CatchUniqueError }; var utData = NonDiBizSetup.SetupDtoMapping <ServiceLayerBizInDto>(config); utData.AddDtoMapping <ServiceLayerBizOutDto>(); var bizInstance = new BizActionCheckSqlErrorHandlerWriteDbAsync(context); var runner = new ActionServiceAsync <IBizActionCheckSqlErrorHandlerWriteDbAsync>(context, bizInstance, utData.WrappedConfig); //ATTEMPT try { await runner.RunBizActionAsync("Hello"); } //VERIFY catch (Exception e) { shouldThrowException.ShouldBeTrue(); return; } shouldThrowException.ShouldBeFalse(); runner.Status.GetAllErrors().ShouldEqual("Unique constraint failed"); } }
public async Task TestResetDtoDirectOk() { //SETUP var service = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, new BizActionInOutAsync(), _mapper, _noCachingConfig); var data = new BizDataIn { Num = 123 }; //ATTEMPT await service.ResetDtoAsync(data); //VERIFY data.ShouldNotBeNull(); data.Num.ShouldEqual(123); }
public async Task Test11ResetDtoGenericActionsOk() { //SETUP var service = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, new BizActionInOutAsync(), _mapper, _noCachingConfig); var data = new ServiceLayerBizInDto { Num = 123 }; //ATTEMPT await service.ResetDtoAsync(data); //VERIFY data.ShouldNotBeNull(); data.Num.ShouldEqual(123); data.SetupSecondaryDataCalled.ShouldBeTrue(); }
public async Task TestActionServiceOutOnlyDtosOk() { //SETUP var utData = NonDiBizSetup.SetupDtoMapping <ServiceLayerBizInDto>(_noCachingConfig); utData.AddDtoMapping <ServiceLayerBizOutDto>(); var bizInstance = new BizActionOutOnlyAsync(); var runner = new ActionServiceAsync <IBizActionOutOnlyAsync>(_emptyDbContext, bizInstance, utData.WrappedConfig); //ATTEMPT var data = await runner.RunBizActionAsync <ServiceLayerBizOutDto>(); //VERIFY bizInstance.HasErrors.ShouldBeFalse(); data.Output.ShouldEqual("Result"); }
public async Task TestActionServiceOutOnlyDtosDatabaseOk() { //SETUP var options = SqliteInMemory.CreateOptions <TestDbContext>(); using (var context = new TestDbContext(options)) { context.Database.EnsureCreated(); var mapper = SetupHelpers.CreateMapper <ServiceLayerBizInDto, ServiceLayerBizOutDto>(); var bizInstance = new BizActionOutOnlyWriteDbAsync(context); var runner = new ActionServiceAsync <IBizActionOutOnlyWriteDbAsync>(context, bizInstance, mapper, _noCachingConfig); //ATTEMPT var data = await runner.RunBizActionAsync <ServiceLayerBizOutDto>(); //VERIFY bizInstance.HasErrors.ShouldBeFalse(); context.LogEntries.Single().LogText.ShouldEqual("BizActionOutOnlyWriteDbAsync"); } }
public async Task TestActionServiceInOutDtosAsyncOk(int num, bool hasErrors) { //SETUP var bizInstance = new BizActionInOnlyAsync(); var runner = new ActionServiceAsync <IBizActionInOnlyAsync>(_emptyDbContext, bizInstance, _wrappedConfig); var input = new ServiceLayerBizInDtoAsync { Num = num }; //ATTEMPT await runner.RunBizActionAsync(input); //VERIFY bizInstance.HasErrors.ShouldEqual(hasErrors); if (hasErrors) { bizInstance.Message.ShouldEqual("Failed with 1 error"); } else { bizInstance.Message.ShouldEqual("All Ok"); } }
public async Task TestActionServiceAsyncInOutDirectOk(int num, bool hasErrors) { //SETUP var bizInstance = new BizActionInOutAsync(); var runner = new ActionServiceAsync <IBizActionInOutAsync>(_emptyDbContext, bizInstance, _wrappedConfig); var input = new BizDataIn { Num = num }; //ATTEMPT var data = await runner.RunBizActionAsync <BizDataOut>(input); //VERIFY bizInstance.HasErrors.ShouldEqual(hasErrors); if (hasErrors) { data.ShouldBeNull(); bizInstance.Message.ShouldEqual("Failed with 1 error"); } else { data.Output.ShouldEqual(num.ToString()); } }
public ActionAsyncController(ActionServiceAsync service) { _service = service; }