コード例 #1
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 !");
            }
        }
コード例 #2
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");
            }
        }