public void GetDetailsModel_GivenValidDriveIdAndUserIsNotDriver_ShouldReturnValidDetailsModelWithIsOwnerFalse() { // arrange int driveId = 1; int userId = 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, DriverId = 2 }); IMapper mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Drive, DriveDetailsViewModel>() .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.GetDetailsModel(driveId, userId); // assert result.Should().Equals(new DriveDetailsViewModel() { Id = driveId, UserIsOwner = false }); }
public void GetDetailsModel_GivenNonExistingId_ShouldReturnNull() { // arrange int driveId = 10; int userId = 1; 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.GetDetailsModel(driveId, userId); // assert result.Should().BeNull(); }