Esempio n. 1
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);
            }
        }