public void VerifyThatTheMethodIsCalledExactOneTime_WhenPassedParametersAreCorrect() { // Arrange var collectionOfCars = new List <Car> { new Car() { Id = Guid.NewGuid(), Manufacturer = "VW", Model = "Golf", ValidUntilVignette = DateTime.Now }, new Car() { Id = Guid.NewGuid(), Manufacturer = "BMW", Model = "e40", ValidUntilVignette = DateTime.Now }, new Car() { Id = Guid.NewGuid(), Manufacturer = "Lada", Model = "2105", ValidUntilVignette = DateTime.Now } }; var mockedRepo = new Mock <IEfGenericRepository <Car> >(); mockedRepo.Setup(m => m.All()).Returns(collectionOfCars); var service = new FilterService(mockedRepo.Object); // Act service.FilterExpiringVignetteCars(); // Assert mockedRepo.Verify(m => m.All(), Times.Exactly(1)); }
public void ShouldReturnIEnumerableCollection_WhenPassedParametersAreCorrect() { // Arrange var collectionOfCars = new List <Car> { new Car() { Id = Guid.NewGuid(), Manufacturer = "VW", Model = "Golf", ValidUntilVignette = DateTime.Now }, new Car() { Id = Guid.NewGuid(), Manufacturer = "BMW", Model = "e40", ValidUntilVignette = DateTime.Now }, new Car() { Id = Guid.NewGuid(), Manufacturer = "Lada", Model = "2105", ValidUntilVignette = DateTime.Now } }; var mockedRepo = new Mock <IEfGenericRepository <Car> >(); mockedRepo.Setup(m => m.All()).Returns(collectionOfCars); var service = new FilterService(mockedRepo.Object); // Act var result = service.FilterExpiringVignetteCars().ToList(); // Assert Assert.AreEqual(collectionOfCars.Count, result.Count); }