Ejemplo n.º 1
0
        public ActionResult Delete(Guid id, FormCollection collection)
        {
            try
            {
                vetRepository.DeleteVet(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("DeleteVet"));
            }
        }
Ejemplo n.º 2
0
        public void DeleteVet_ReturnsProperCount()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <VetClinicDbContext>()
                            .UseInMemoryDatabase(databaseName: $"VetDb{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 fakeVetOne = new FakeVet {
            }.Generate();
            var fakeVetTwo = new FakeVet {
            }.Generate();
            var fakeVetThree = new FakeVet {
            }.Generate();

            //Act
            using (var context = new VetClinicDbContext(dbOptions, currentUserService, new DateTimeService()))
            {
                context.Vets.AddRange(fakeVetOne, fakeVetTwo, fakeVetThree);

                var service = new VetRepository(context, new SieveProcessor(sieveOptions));
                service.DeleteVet(fakeVetTwo);

                context.SaveChanges();

                //Assert
                var vetList = context.Vets.ToList();

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

                vetList.Should().ContainEquivalentOf(fakeVetOne);
                vetList.Should().ContainEquivalentOf(fakeVetThree);
                Assert.DoesNotContain(vetList, v => v == fakeVetTwo);

                context.Database.EnsureDeleted();
            }
        }