public Services.TripSearchRequest ToService(IDestinationRepository repo) { return(new TripSearchRequest( // TODO Refactor repo.FindByName(StartLocation).FirstOrNone().ValueOr((Domain.Destination)null), repo.FindByName(EndLocation).FirstOrNone().ValueOr((Domain.Destination)null), StartTime )); }
public Option <Domain.TripOffer, string> ToDomain(IDestinationRepository destRepo) { return (destRepo.FindByName(StartLocation) .FirstOrNone() .WithException($"Start location '{StartLocation}' could not matched!") .FlatMap(start => destRepo.FindByName(EndLocation) .FirstOrNone() .WithException($"End location '{EndLocation}' could not matched!") .Map(end => new Domain.TripOffer(StarTime, start, EndTime - StarTime, end, new Domain.User(null, OfferedBy)) ) )); }
public void TestSearchByName() { Assert.AreEqual("Linz", repo.FindByName("linz").FirstOrNone().ValueOr(() => null)?.Name); Assert.AreEqual("Waidhofen an der Ybbs", repo.FindByName("waid").FirstOrNone().ValueOr(() => null)?.Name); Assert.AreEqual("Waidhofen an der Ybbs", repo.FindByName("Waid").FirstOrNone().ValueOr(() => null)?.Name); Assert.IsNull(repo.FindByName("ybba").FirstOrNone().ValueOr(() => null)); Assert.IsNull(repo.FindByName("bla").FirstOrNone().ValueOr(() => null)); Assert.IsNull(repo.FindByName("lanzen").FirstOrNone().ValueOr(() => null)); Assert.IsNull(repo.FindByName("Ander").FirstOrNone().ValueOr(() => null)); }