public void DeletePet_Should_Throw_ArgumentNullException_When_Pet_Is_Null()
        {
            // Arrange
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);

            // Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => petRepository.DeletePet("", null));
        }
        public void DeletePet_Should_Throw_ArgumentException_When_Pet_Does_Not_Exist()
        {
            // Arrange
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);
            var pet           = new Mock <IPet>();

            // Act & Assert
            Assert.ThrowsException <ArgumentException>(() => petRepository.DeletePet("", pet.Object));
        }
Example #3
0
        public ActionResult Delete(Guid id, FormCollection collection)
        {
            try
            {
                petRepository.DeletePet(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("DeletePet"));
            }
        }
        public void DeletePet_Should_Remove_Pet_From_PetList()
        {
            // Arrange
            var users         = new Mock <IUserRepository>();
            var petRepository = new PetRepository(users.Object);
            var pet           = new Mock <IPet>();

            // Act
            petRepository.CreatePet("", pet.Object);
            petRepository.DeletePet("", pet.Object);

            // Assert
            Assert.IsTrue(!petRepository.Pets.Contains(pet.Object));
        }
        public void DeletePet_ReturnsProperCount()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PetDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var currentUser = new Mock <ICurrentUserService>();

            currentUser.SetupGet(c => c.UserId).Returns("testuser");
            var currentUserService = currentUser.Object;

            var fakePetOne = new FakePet {
            }.Generate();
            var fakePetTwo = new FakePet {
            }.Generate();
            var fakePetThree = new FakePet {
            }.Generate();

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Pets.AddRange(fakePetOne, fakePetTwo, fakePetThree);

                var service = new PetRepository(context, new SieveProcessor(sieveOptions));
                service.DeletePet(fakePetTwo);

                context.SaveChanges();

                //Assert
                var petList = context.Pets.ToList();

                petList.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                petList.Should().ContainEquivalentOf(fakePetOne);
                petList.Should().ContainEquivalentOf(fakePetThree);
                Assert.DoesNotContain(petList, p => p == fakePetTwo);

                context.Database.EnsureDeleted();
            }
        }
Example #6
0
        public ActionResult DeletePet(int id)
        {
            _petRepository.DeletePet(id);

            return(Ok("Your pet's data has been deleted :("));
        }