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 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 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 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");
            }
        }
Exemplo n.º 5
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.");
            }
        }