Esempio n. 1
0
        public void GetAllShouldReturnAllAnimalsFromCollection()
        {
            var db      = new InMemoryZooDb();
            var service = new AnimalsService(db);

            var allAnmals = service.GetAll().ToList();

            Assert.Equal(30, allAnmals.Count);
        }
Esempio n. 2
0
        public void GetDeadAnimalsCountShouldPropelryReturnCorrectValue()
        {
            var db      = new InMemoryZooDb();
            var service = new AnimalsService(db);

            var bear = db.GetAnimals().First();

            bear.IsAlive = false;
            var deadAnimalsCount = service.GetDeadAnimalsCount();

            Assert.Equal(1, deadAnimalsCount);
        }
Esempio n. 3
0
        public void GetMinHealthByAnimalTypeShouldPropelryReturnMinHealthValue()
        {
            var db      = new InMemoryZooDb();
            var service = new AnimalsService(db);

            var bear = db.GetAnimals().First(a => a.GetType().Name == "Bear");

            bear.Health = 65;
            var bearMinHealth = service.GetMinHealthByAnimalType("Bear");

            Assert.Equal(65, bearMinHealth);
        }
        public void GetAll_ShouldReturnAllAnimalsFromDatabase_WhickAreNotDeleted()
        {
            // Arrange
            var mockedEfRepository = new Mock <IEfRepository <Animal> >();
            var mockedUnitOfWork   = new Mock <ISaveContext>();

            mockedEfRepository.Setup(x => x.All);

            var animalsService = new AnimalsService(mockedEfRepository.Object, mockedUnitOfWork.Object);

            // Act
            var result = animalsService.GetAll();

            // Assert
            mockedEfRepository.Verify(x => x.All, Times.Once);
        }
        public void AddAnimal_ShouldAddToDatabase_WhenInputIsCorrect()
        {
            // Arrange
            var mockedEfRepository = new Mock <IEfRepository <Animal> >();
            var mockedUnitOfWork   = new Mock <ISaveContext>();
            var animal             = new Animal();

            mockedEfRepository.Setup(x => x.Add(animal));

            var animalsService = new AnimalsService(mockedEfRepository.Object, mockedUnitOfWork.Object);

            // Act
            animalsService.Add(animal);

            // Assert
            mockedEfRepository.Verify(x => x.Add(animal), Times.Once);
        }
        public void DeleteAnimal_ShouldSetIsDeleted_True_InDatabase()
        {
            // Arrange
            var mockedEfRepository = new Mock <IEfRepository <Animal> >();
            var mockedUnitOfWork   = new Mock <ISaveContext>();

            var animal = new Animal();

            mockedEfRepository.Setup(x => x.Delete(animal));

            var animalsService = new AnimalsService(mockedEfRepository.Object, mockedUnitOfWork.Object);

            // Act
            animalsService.Delete(animal);

            // Assert
            mockedEfRepository.Verify(x => x.Delete(animal), Times.Once);
        }
Esempio n. 7
0
 public AnimalListingsController(ILogger <AnimalListingsController> logger, AnimalsService animalsService)
 {
     _logger         = logger;
     _animalsService = animalsService;
 }