public void GetDeleteViewModel_GivenValidCarId_ShouldReturnCarDeleteViewModel() { int carId = 1; IMapper mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap <Car, CarDeleteViewModel>())); Mock <IDbRepository <Car> > mockRepository = new Mock <IDbRepository <Car> >(); mockRepository .Setup(x => x.GetById(1)) .Returns(new Car() { Id = 1, Brand = "TestBrand", CarModel = "TestModel", HasAirConditioner = true, Year = 1234, OwnerId = 1, Image = new byte[1024] }); CarsService service = new CarsService(mockRepository.Object, mapper); // act CarDeleteViewModel result = service.GetDeleteViewModel(carId); // assert result.Should().BeEquivalentTo(new CarDeleteViewModel() { Id = 1, Brand = "TestBrand", CarModel = "TestModel" }); }
public void GetDeleteViewModel_GivenNonExistingId_ShouldReturnNull() { // arrange int carId = 1; Mock <IDbRepository <Car> > mockRepository = new Mock <IDbRepository <Car> >(); mockRepository .Setup(x => x.GetById(It.IsAny <int>())) .Returns <Car>(null); CarsService service = new CarsService(mockRepository.Object, null); // act CarDeleteViewModel result = service.GetDeleteViewModel(carId); // assert result.Should().BeEquivalentTo <CarDeleteViewModel>(null); }