예제 #1
0
        public void PostVolumeTest()
        {
            var controller = new VolumesController(_context);
            var result     = controller.Post(_bookDTOs[0]);
            var created    = _context.Volumes.Last();

            // Assert
            Assert.Equal(_volumeDTOs.Count + 1, _context.Volumes.Count());
            Assert.Equal(_bookDTOs[0].Id, created.Id);
        }
예제 #2
0
        public void RemoveVolumeTest()
        {
            var controller = new VolumesController(_context);
            var result     = controller.Delete(_volumeDTOs[0].Id);
            var rents      = _context.Rents.ToList();

            //Assert
            Assert.Equal(_volumeDTOs.Count - 1, _context.Volumes.Count());
            Assert.Equal(_rentDTOs.Count - 3, _context.Rents.Count());

            for (int i = 0; i < rents.Count; i++)
            {
                Assert.False(rents[i].VolumeId == _volumeDTOs[0].Id);
            }
        }
예제 #3
0
        private static void FillDatabaseWithAdditionalChecks(BookLibraryContext context)
        {
            // Entity Controllers

            var authorsController         = new AuthorsController(new AuthorsRepository(context), null);
            var editionsController        = new EditionsController(new EditionsRepository(context), null);
            var genresController          = new GenresController(new GenresRepository(context), null);
            var volumesController         = new VolumesController(new VolumesRepository(context), null);
            var volumeExemplarsController = new VolumeExemplarsController(new VolumeExemplarsRepository(context), null);
            var worksController           = new WorksController(new WorksRepository(context), null);
            var workKindsController       = new WorkKindsController(new WorkKindsRepository(context), null);

            // Entity Link Controllers

            var editionVolumeLinksController = new EditionVolumeLinksController(new EditionVolumeLinksRepository(context), null);
            var volumeWorkLinksController    = new VolumeWorkLinksController(new VolumeWorkLinksRepository(context), null);
            var workAuthorLinksController    = new WorkAuthorLinksController(new WorkAuthorLinksRepository(context), null);

            // Filling and checking

            IActionResult result;
            Author        authorJackLondon;
            Author        authorTheodoreDreiser;
            Genre         genreBellesletres;
            Genre         genreRealism;
            Work          workMartenEden;
            Work          workWhiteFang;
            Work          workFinancier;
            Work          workSisterCarrie;

            result = authorsController.Get(0);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));

            result = authorsController.Put(new Author {
                Id = 0, Name = "Jack London"
            });
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));

            result = authorsController.Post(null);
            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            Assert.IsTrue(((BadRequestObjectResult)result).Value.Equals("Entity is null."));

            result = authorsController.Post(new Author {
                Name = "Jack London"
            });
            Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));
            Assert.IsInstanceOfType(((CreatedAtActionResult)result).Value, typeof(Author));
            authorJackLondon = (Author)((CreatedAtActionResult)result).Value;
            Assert.IsTrue(authorJackLondon.Id != 0);

            result = authorsController.Post(new Author {
                Name = "Theodore Dreiser"
            });
            Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));
            Assert.IsInstanceOfType(((CreatedAtActionResult)result).Value, typeof(Author));
            authorTheodoreDreiser = (Author)((CreatedAtActionResult)result).Value;

            Assert.IsTrue(authorTheodoreDreiser.Id != authorJackLondon.Id);

            result = authorsController.GetCount();
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(((OkObjectResult)result).Value, typeof(int));
            Assert.IsTrue((int)((OkObjectResult)result).Value == 2);

            authorTheodoreDreiser.Name = "Theodore Herman Albert Dreiser";
            result = authorsController.Put(authorTheodoreDreiser);
            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.IsInstanceOfType(((OkObjectResult)result).Value, typeof(Author));
            authorTheodoreDreiser = (Author)((OkObjectResult)result).Value;
            Assert.IsTrue(authorTheodoreDreiser.Name == "Theodore Herman Albert Dreiser");

            genreBellesletres = (Genre)((CreatedAtActionResult)genresController.Post(new Genre {
                Name = "Belles-letres"
            })).Value;
            genreRealism      = (Genre)((CreatedAtActionResult)genresController.Post(new Genre {
                Name = "Realism"
            })).Value;

            workMartenEden = (Work)((CreatedAtActionResult)worksController.Post(new Work {
                Name = "Marten Eden", GenreId = genreBellesletres.Id
            })).Value;
            workWhiteFang  = (Work)((CreatedAtActionResult)worksController.Post(new Work {
                Name = "White Fang", GenreId = genreBellesletres.Id
            })).Value;

            workFinancier    = (Work)((CreatedAtActionResult)worksController.Post(new Work {
                Name = "Financier", GenreId = genreRealism.Id, AltGenreId = genreBellesletres.Id
            })).Value;
            workSisterCarrie = (Work)((CreatedAtActionResult)worksController.Post(new Work {
                Name = "Sister Carrie", GenreId = genreRealism.Id, AltGenreId = genreBellesletres.Id
            })).Value;

            result = workAuthorLinksController.Post(new WorkAuthorLink {
                WorkId = workMartenEden.Id, AuthorId = authorJackLondon.Id
            });
            Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));
            result = workAuthorLinksController.Post(new WorkAuthorLink {
                WorkId = workWhiteFang.Id, AuthorId = authorJackLondon.Id
            });
            Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));

            result = workAuthorLinksController.Post(new WorkAuthorLink {
                WorkId = workFinancier.Id, AuthorId = authorTheodoreDreiser.Id
            });
            Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));
            result = workAuthorLinksController.Post(new WorkAuthorLink {
                WorkId = workSisterCarrie.Id, AuthorId = authorTheodoreDreiser.Id
            });
            Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));
        }