Esempio n. 1
0
        public async Task TestValidation(int num, bool hasErrors, bool doNotValidateSaveChanges)
        {
            //SETUP
            var config = new GenericBizRunnerConfig {
                TurnOffCaching = true, DoNotValidateSaveChanges = doNotValidateSaveChanges
            };
            var options = SqliteInMemory.CreateOptions <TestDbContext>();

            using (var context = new TestDbContext(options))
            {
                context.Database.EnsureCreated();
                var utData = NonDiBizSetup.SetupDtoMapping <ServiceLayerBizInDto>(config);
                utData.AddDtoMapping <ServiceLayerBizOutDto>();
                var bizInstance = new BizActionInOutWriteDbAsync(context);
                var runner      = new ActionServiceInOutAsync <IBizActionInOutWriteDbAsync, BizDataIn, BizDataOut>(true, utData.WrappedConfig);
                var inDto       = new ServiceLayerBizInDto {
                    Num = num
                };

                //ATTEMPT
                var data = await runner.RunBizActionDbAndInstanceAsync <ServiceLayerBizOutDto>(context, bizInstance, inDto);

                //VERIFY
                bizInstance.HasErrors.ShouldEqual(hasErrors);
                if (hasErrors)
                {
                    context.LogEntries.Any().ShouldBeFalse();
                }
                else
                {
                    context.LogEntries.Single().LogText.ShouldEqual(num.ToString());
                }
            }
        }
Esempio n. 2
0
        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());
                }
            }
        }