public void TestCreateTodoOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabase();
                var controller = new ToDoController();

                var mapper      = BizRunnerHelpers.CreateEmptyMapper();
                var bizInstance = new CreateTodoBizLogic(context);
                var service     = new ActionService <ICreateTodoBizLogic>(context, bizInstance, mapper);

                //ATTEMPT
                var dto = new CreateTodoDto()
                {
                    Name       = "Test",
                    Difficulty = 3,
                };
                var response = controller.Post(dto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(201);
                var rStatus = response.CheckCreateResponse("GetSingleTodo", new { id = 7 }, dto);
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Success");
            }
        }
        public void TestCreateTodoOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                context.SeedDatabase();
                var controller = new ToDoController();

                var noCachingConfig = new GenericBizRunnerConfig {
                    TurnOffCaching = true
                };
                var utData      = new NonDiBizSetup(noCachingConfig);
                var bizInstance = new CreateTodoBizLogic(context);
                var service     = new ActionService <ICreateTodoBizLogic>(context, bizInstance, utData.WrappedConfig);

                //ATTEMPT
                var dto = new CreateTodoDto()
                {
                    Name       = "Test",
                    Difficulty = 3,
                };
                var response = controller.Post(dto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(201);
                var rStatus = response.CheckCreateResponse("GetSingleTodo", new { id = 7 }, context.TodoItems.Find(7));
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Success");
            }
        }
示例#3
0
        public void TestCreateTodoViaBizLogicWithErrorOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                var service = new CreateTodoBizLogic(context);

                //ATTEMPT
                var dto = new CreateTodoDto
                {
                    Name       = "Test!",
                    Difficulty = 3
                };
                var result = service.BizAction(dto);

                //VERIFY
                service.HasErrors.ShouldBeTrue(service.GetAllErrors());
                service.GetAllErrors().ShouldEqual("Business logic says the name canot end with !");
            }
        }
示例#4
0
        public void TestCreateTodoViaBizLogicOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

            using (var context = new ExampleDbContext(options))
            {
                context.Database.EnsureCreated();
                var service = new CreateTodoBizLogic(context);

                //ATTEMPT
                var dto = new CreateTodoDto
                {
                    Name       = "Test",
                    Difficulty = 3
                };
                var result = service.BizAction(dto);
                context.SaveChanges();

                //VERIFY
                service.HasErrors.ShouldBeFalse(service.GetAllErrors());
                context.TodoItems.Single().Name.ShouldEqual("Test");
            }
        }