Example #1
0
        public void HouseholdService_ShouldCallGetAllOnce_WhenIndexGetIsCalled()
        {
            // Arrange
            var householdController = new HouseholdsController(householdServiceMock.Object, mappingServiceMock.Object, webHelperMock.Object);

            // Act
            householdController.Index();

            // Assert
            this.householdServiceMock.Verify(x => x.GetAll(), Times.Once);
        }
Example #2
0
        public void MappingService_ShouldCallMapAsManyTimesAsHouseholdsAreReturnedFromHouseholdService_WhenIndexGetIsCalled(int households)
        {
            // Arrange
            var householdController = new HouseholdsController(householdServiceMock.Object, mappingServiceMock.Object, webHelperMock.Object);
            var householdsFromDb    = new List <Household>();

            for (int i = 0; i < households; i++)
            {
                householdsFromDb.Add(new Household("_", "_", new byte[0]));
            }

            this.householdServiceMock.Setup(x => x.GetAll()).Returns(householdsFromDb);

            // Act
            householdController.Index();

            // Assert
            this.mappingServiceMock.Verify(x => x.Map <HouseholdsViewModel>(It.IsAny <object>()), Times.Exactly(households));
        }