public void GetCar_Returns_Car() { var expectedResult = CarsTestData.GetCommonListOfCars().First(); var mockCarsDataService = new Mock <ICarsDataService>(); mockCarsDataService.Setup(m => m.GetCar(It.IsAny <int>())).Returns(expectedResult); var mockCarValidator = new Mock <IValidator <Car> >(); var serviceProvider = GetSerivceProvider(mockCarsDataService.Object, mockCarValidator.Object); var carsBusinessService = serviceProvider.GetRequiredService <ICarsBusinessService>(); var result = carsBusinessService.GetCar(It.IsAny <int>()); mockCarsDataService.Verify(m => m.GetCar(It.IsAny <int>()), Times.Once()); Assert.Equal(expectedResult, result); }
public void GetCars_Returns_Cars() { var expectedResult = CarsTestData.GetCommonListOfCars(); var mockCarsDataService = new Mock <ICarsDataService>(); mockCarsDataService.Setup(m => m.GetCars()).Returns(expectedResult); var mockCarValidator = new Mock <IValidator <Car> >(); var serviceProvider = GetSerivceProvider(mockCarsDataService.Object, mockCarValidator.Object); var carsBusinessService = serviceProvider.GetRequiredService <ICarsBusinessService>(); var result = carsBusinessService.GetCars(); mockCarsDataService.Verify(m => m.GetCars(), Times.Once()); Assert.Equal(expectedResult.Count(), result.Count()); foreach (var car in result) { Assert.Contains(expectedResult, i => i == car); } }