public async void GetAsyncByName() { // Arrange var expectedCustomers = new Page <Customer> { Items = new Customer[] { customers[5] }, TotalSize = 1 }; CustomersRepositoryMock .Setup(x => x.GetAsyncByName("6")) .ReturnsAsync(expectedCustomers.Items); foreach (Customer customer in customers) { VehiclesRepositoryMock .Setup(x => x.GetByCustomerId(customer.Id, SearchVehicleStatus.Any)) .ReturnsAsync(customer.Vehicles); } // Act var result = await ServiceUnderTest.GetAsyncByName("6", pagingOptions); // Assert Assert.True(EqualityHelper.SamePageOfCustomers(expectedCustomers, result)); }
public async void GetAsyncByInvalidName() { // Arrange var expectedCustomers = new Page <Customer> { Items = new Customer[] { }, TotalSize = 0 }; CustomersRepositoryMock .Setup(x => x.GetAsyncByName("Invalid Name")) .ReturnsAsync(expectedCustomers.Items); // Act var result = await ServiceUnderTest.GetAsyncByName("Invalid Name", pagingOptions); // Assert Assert.True(EqualityHelper.SamePageOfCustomers(expectedCustomers, result)); }
public async void GetByStatus() { // Arrange var expectedCustomers = new Page <Customer> { Items = new Customer[] { new Customer { Id = 3, Name = "Customer 3", AddressLn1 = "Address 3", Vehicles = new Vehicle[] { new Vehicle { VIN = "333", RegNo = "3333", IsActive = true } } }, new Customer { Id = 6, Name = "Customer 6", AddressLn1 = "Address 6", Vehicles = new Vehicle[] { new Vehicle { VIN = "444", RegNo = "4444", IsActive = true }, new Vehicle { VIN = "666", RegNo = "6666", IsActive = true } } } }, TotalSize = 2 }; CustomersRepositoryMock .Setup(x => x.GetAsyncByName(string.Empty)) .ReturnsAsync(customers); foreach (Customer customer in customers) { VehiclesRepositoryMock .Setup(x => x.GetByCustomerId(customer.Id, SearchVehicleStatus.Active)) .ReturnsAsync(customer.Vehicles == null? null : customer.Vehicles.Where(v => v.IsActive).ToArray()); } // Act var result = await ServiceUnderTest.GetAsyncByName(string.Empty, pagingOptions, true, SearchVehicleStatus.Active); // Assert Assert.True(EqualityHelper.SamePageOfCustomers(expectedCustomers, result)); }