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

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

                var controller = new ToDoController();
                var utData     = context.SetupSingleDtoAndEntities <ChangeDifficultyDto>(_genericServiceConfig);
                var service    = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var response = controller.Delete(2, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.OkStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Successfully deleted a Todo Item");
                context.TodoItems.Count().ShouldEqual(5);
            }
        }
        public void TestPutNameOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoController();
                var utData     = context.SetupSingleDtoAndEntities <ChangeNameDto>(_genericServiceConfig);
                var service    = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new ChangeNameDto()
                {
                    Id   = 2,
                    Name = "Test",
                };
                var response = controller.Name(dto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.OkStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Successfully updated the Todo Item");
            }
        }
        public void TestPutDifficultyValidationError()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoController();
                var utData     = context.SetupSingleDtoAndEntities <ChangeDifficultyDto>(_genericServiceConfig);
                var service    = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new ChangeDifficultyDto()
                {
                    Id         = 1,
                    Difficulty = 99,
                };
                var response = controller.Difficulty(dto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.ErrorsStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeFalse();
                rStatus.GetAllErrors().ShouldEqual("The field Difficulty must be between 1 and 5.");
            }
        }
        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");
            }
        }
Example #5
0
        public void TestJsonPatchOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoHybridController();
                var utData     = context.SetupEntitiesDirect(_genericServiceConfig);
                var service    = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var patch = new JsonPatchDocument <TodoItemHybrid>();
                patch.Replace(x => x.Difficulty, 5);
                var response = controller.Update(1, patch, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.OkStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Successfully updated the Todo Item Hybrid");
                context.TodoItemHybrids.First().Difficulty.ShouldEqual(5);
            }
        }
Example #6
0
        public async Task TestCreateTodoOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoHybridController();
                var utData     = context.SetupSingleDtoAndEntities <CreateTodoHybridDto>(_genericServiceConfig);
                var service    = new CrudServicesAsync(context, utData.ConfigAndMapper);

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

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

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

                //ATTEMPT
                context.SeedDatabase();

                //VERIFY
                context.TodoItems.Count().ShouldEqual(6);
            }
        }
Example #8
0
        public async Task TestDeleteReviewOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new BookController();
                var utData     = context.SetupSingleDtoAndEntities <AddReviewDto>(_genericServiceConfig);
                var service    = new CrudServicesAsync(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new AddReviewDto()
                {
                    BookId    = 1,
                    Title     = "Efcore in action",
                    VoterName = "test",
                    NumStars  = 5,
                    Comment   = "test comment",
                };
                var response = await controller.AddReview(dto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(200);


                //Delete review

                utData  = context.SetupSingleDtoAndEntities <RemoveReviewDto>(_genericServiceConfig);
                service = new CrudServicesAsync(context, utData.ConfigAndMapper);

                //ATTEMPT
                var removeReviewDto = new RemoveReviewDto()
                {
                    BookId   = 1,
                    ReviewId = 1
                };
                response = await controller.DeleteReview(removeReviewDto, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(200);
            }
        }
        public async Task TestGetOneNullReturn()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoController();
                var utData     = context.SetupSingleDtoAndEntities <ChangeNameDto>(_genericServiceConfig);
                var service    = new CrudServicesAsync(context, utData.ConfigAndMapper);

                //ATTEMPT
                var response = await controller.GetSingleAsync(99, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.ResultIsNullStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("The Todo Item was not found.");
            }
        }
        public void TestDeleteNotFound()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoController();
                var utData     = context.SetupSingleDtoAndEntities <ChangeDifficultyDto>(_genericServiceConfig);
                var service    = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var response = controller.Delete(99, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.ErrorsStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeFalse();
                rStatus.GetAllErrors().ShouldEqual("Sorry, I could not find the Todo Item you wanted to delete.");
            }
        }
        public async Task TestGetOneOk()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <ExampleDbContext>();

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

                var controller = new ToDoHybridController();
                var utData     = context.SetupEntitiesDirect(_genericServiceConfig);
                var service    = new CrudServicesAsync(context, utData.ConfigAndMapper);

                //ATTEMPT
                var response = await controller.GetSingleAsync(1, service);

                //VERIFY
                response.GetStatusCode().ShouldEqual(CreateResponse.OkStatusCode);
                var rStatus = response.CopyToStatus();
                rStatus.IsValid.ShouldBeTrue(rStatus.GetAllErrors());
                rStatus.Message.ShouldEqual("Success");
            }
        }