public void GetAll_ShouldReturnAllDrivesAsDriveIndexViewModel() { // arrange Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >(); mockRepository.Setup(m => m.GetAll()) .Returns(new List <Drive>() { new Drive() { Id = 1 }, new Drive() { Id = 2 } }.AsQueryable()); IMapper mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Drive, DriveIndexViewModel>() .ForMember(dest => dest.From, opt => opt.MapFrom(source => source.From.Name)) .ForMember(dest => dest.To, opt => opt.MapFrom(source => source.To.Name)) .ForMember(dest => dest.AvailableSeats, opt => opt.MapFrom(source => source.DeclaredSeats - source.DrivesPassengers.Count)) .ForMember(dest => dest.Date, opt => opt.MapFrom(source => source.DateTime.ToString("dd/MM/yyyy"))) .ForMember(dest => dest.Time, opt => opt.MapFrom(source => source.DateTime.ToString("HH:mm"))))); IDrivesService service = new DrivesService(mockRepository.Object, mapper, null); // act var result = service.GetAll(); // assert result.Count().Should().Be(2); }