public void GetDetailsAdminModel_GivenNonExistingDriveId_ShouldReturnNull() { // arrange int driveId = 10; Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >(); mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId))) .Returns <Drive>(null); IDrivesService service = new DrivesService(mockRepository.Object, null, null); // act var result = service.GetDetailsAdminModel(driveId); // assert result.Should().BeNull(); }
public void GetDetailsAdminModel_GivenValidDriveId_ShouldReturnValidDriveAdminDetailsViewModel() { // arrange int driveId = 1; Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >(); mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId))) .Returns(new Drive() { Id = driveId }); IMapper mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Drive, DriveAdminDetailsViewModel>() .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"))) .ForMember(dest => dest.PassengersCount, opt => opt.MapFrom(source => source.DrivesPassengers.Count)) .ForMember(dest => dest.PassengersNames, opt => opt.MapFrom(source => source.DrivesPassengers .Select(d => d.Passenger.FirstName + " " + d.Passenger.LastName) .ToList())) .ForMember(dest => dest.DriverName, opt => opt.MapFrom(source => source.Driver.FirstName + " " + source.Driver.LastName)) .ForMember(dest => dest.CarIdentifier, opt => opt.MapFrom(source => source.Car.Brand + " " + source.Car.CarModel + " " + source.Car.Year)))); IDrivesService service = new DrivesService(mockRepository.Object, mapper, null); // act var result = service.GetDetailsAdminModel(driveId); // assert result.Should().Equals(new DriveAdminDetailsViewModel() { Id = driveId }); }