public void ByUserIdForUser_ThenReturnsVehiclesInSortedOrder() { var vehicle01 = new Vehicle { Name = "first", VehicleId = 4, SortOrder = 1 }; var vehicle02 = new Vehicle { Name = "second", VehicleId = 1, SortOrder = 3 }; var vehicle03 = new Vehicle { Name = "third", VehicleId = 2, SortOrder = 2 }; var vehicles = new List <Vehicle> { vehicle03, vehicle02, vehicle01 }; _vehicleRepo .Setup(vr => vr.GetVehicles(UserId)) .Returns(vehicles); var handler = new GetVehicleListForUser(_vehicleRepo.Object, _fillupRepo.Object); var result = handler.Execute(UserId); var acutal = result.ToArray(); Assert.Equal(vehicle01.Name, acutal[0].Name); Assert.Equal(vehicle03.Name, acutal[1].Name); Assert.Equal(vehicle02.Name, acutal[2].Name); }
public void AndRepositoryThrows_ThenWrapsException() { _vehicleRepo .Setup(r => r.GetVehicles(UserId)) .Throws <InvalidOperationException>(); var handler = new GetVehicleListForUser(_vehicleRepo.Object); var exception = Assert.Throws <BusinessServicesException>(() => handler.Execute(UserId)); Assert.NotNull(exception); Assert.IsType <InvalidOperationException>(exception.InnerException); }
public void ByUserIdForUser_ThenReturnsVehicles() { var vehicles = new List <Vehicle> { new Vehicle() }; _vehicleRepo .Setup(vr => vr.GetVehicles(UserId)) .Returns(vehicles); var result = new GetVehicleListForUser(_vehicleRepo.Object, _fillupRepo.Object).Execute(UserId); Assert.Equal(vehicles.Count, result.Count()); }
public void ByUserIdForUserWithNoVehicles_ThenReturnsEmptyCollection() { _vehicleRepo .Setup(r => r.GetVehicles(UserId)) .Returns(new Vehicle[] { }) .Verifiable(); var handler = new GetVehicleListForUser(_vehicleRepo.Object, _fillupRepo.Object); var result = handler.Execute(UserId); _vehicleRepo.Verify(); Assert.NotNull(result); Assert.Equal(0, result.Count()); }
public GetVehiclesController(GetVehicleListForUser getVehicleListForUser) { this.getVehicleListForUser = getVehicleListForUser; }