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 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 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 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 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 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 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 TestCallHasNoOutputBad() { //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(input)); //VERIFY ex.Message.ShouldEqual("Your call of IBizActionInOutAsync needed 'In, Async' but the Business class had a different setup of 'InOut, Async'"); }
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'"); }