Ejemplo n.º 1
0
        public void CanDeleteValidEstablishments()
        {
            // Arrange - create a establishment
            var establishment = new Establishment {
                EstablishmentId = 2, Name = "Test"
            };

            // Arrange - create a local mock repository
            var localMock = new Mock <IEstablishmentRepository>();

            localMock.Setup(m => m.Establishments).Returns(new[]
            {
                new Establishment {
                    EstablishmentId = 1, Name = "P1"
                },
                establishment,
                new Establishment {
                    EstablishmentId = 3, Name = "P3"
                }
            }.AsQueryable());

            // Arrange - create a controller
            var controller = new EstablishmentController(localMock.Object);

            // Action - delete the product
            controller.Delete(establishment.EstablishmentId);

            // assert - ensure that the repository Delete method was called with the correct Product
            localMock.Verify(m => m.DeleteEstablishment(establishment));
        }
Ejemplo n.º 2
0
        public void CannotDeleteInvalidEstablishments()
        {
            // Arrange - create a controller
            var controller = new EstablishmentController(_mockRepository.Object);

            // Action - attempt to delete using a EstablishmentId that does not exist
            controller.Delete(95);

            // assert - ensure that the repository Delete method was not called
            _mockRepository.Verify(m => m.DeleteEstablishment(It.IsAny <Establishment>()), Times.Never());
        }