/// <summary> /// Adds a travel company destination the collection of those destination be used for the planning. /// </summary> /// <param name="readonlyTravelCompany"></param> public void AddTravelCompany(IReadOnlyTravelCompany readonlyTravelCompany) { CheckTc(readonlyTravelCompany); ContainsToAdd(readonlyTravelCompany); _companies.Add(readonlyTravelCompany); }
public void RemoveTravelCompany(IReadOnlyTravelCompany readonlyTravelCompany) { if (!TravelCompanySet.Remove(readonlyTravelCompany)) { throw new NonexistentTravelCompanyException(); } }
/// <summary> /// Removes a travel company from the collection of those destination be used for the planning /// </summary> /// <param name="readonlyTravelCompany"></param> public void RemoveTravelCompany(IReadOnlyTravelCompany readonlyTravelCompany) { CheckTc(readonlyTravelCompany); ContainsToRemove(readonlyTravelCompany); _companies.Remove(readonlyTravelCompany); }
/// <summary> /// Aux method for AddTravelCompany, for check Execption /// </summary> /// <param name="readonlyTravelCompany"></param> private void ContainsToAdd(IReadOnlyTravelCompany readonlyTravelCompany) { if (ContainsTravelCompany(readonlyTravelCompany)) { throw new TapDuplicatedObjectException("TravelCompany has already been added"); } }
/// <summary> /// Aux method for RemoveTravelCompany, for check Execption /// </summary> /// <param name="readonlyTravelCompany"></param> private void ContainsToRemove(IReadOnlyTravelCompany readonlyTravelCompany) { if (!ContainsTravelCompany(readonlyTravelCompany)) { throw new NonexistentTravelCompanyException("TravelCompany not exist"); } }
public void Setup() { travelCompany = travelCompanyFactory.Get(ExampleName); readOnlyTravelCompany = readOnlyTravelCompanyFactory.Get(ExampleName); pointA = "A"; pointB = "B"; }
/// <summary> /// Auxiliary method that controls if the company is null /// </summary> /// <param name="company"></param> public static void CheckTc(IReadOnlyTravelCompany company) { if (company == null) { throw new ArgumentNullException($"ROTC is null"); } }
public bool ContainsTravelCompany(IReadOnlyTravelCompany readonlyTravelCompany) { if (readonlyTravelCompany is null) { throw new ArgumentNullException(); } return(TravelCompanySet.Contains(readonlyTravelCompany)); }
public void AddTravelCompany(IReadOnlyTravelCompany readonlyTravelCompany) { if (readonlyTravelCompany is null) { throw new ArgumentNullException(); } if (!TravelCompanySet.Add(readonlyTravelCompany)) { throw new TapDuplicatedObjectException(); } }
/// <summary> /// Verifies if the travel company in the collection of those in use by the planner /// </summary> /// <param name="readonlyTravelCompany"></param> /// <returns></returns> public bool ContainsTravelCompany(IReadOnlyTravelCompany readonlyTravelCompany) { CheckTc(readonlyTravelCompany); return(_companies.Contains(readonlyTravelCompany)); }
public void PlannerInit() { planner = plannerFactory.CreateNew(); A = allDestinations[0]; B = allDestinations[1]; C = allDestinations[2]; D = allDestinations[3]; E = allDestinations[4]; F = allDestinations[5]; unreachable = allDestinations[6]; createdLegs = new Dictionary <Key, ILegDTO> { [new Key(rotcAName, A, B)] = getMockedLegDTO(A, B, 2, 1000, TransportType.Train), [new Key(rotcAName, B, A)] = getMockedLegDTO(B, A, 2, 10, TransportType.Train), [new Key(rotcAName, A, C)] = getMockedLegDTO(A, C, 1, 1, TransportType.Train), [new Key(rotcAName, C, A)] = getMockedLegDTO(C, A, 1, 1, TransportType.Train), [new Key(rotcAName, E, C)] = getMockedLegDTO(E, C, 20, 100, TransportType.Train), [new Key(rotcAName, C, E)] = getMockedLegDTO(C, E, 20, 100, TransportType.Train), [new Key(rotcAName, C, F)] = getMockedLegDTO(C, F, 3, 5, TransportType.Train), [new Key(rotcAName, F, D)] = getMockedLegDTO(F, D, 5, 4, TransportType.Train), [new Key(rotcAName, E, B)] = getMockedLegDTO(E, B, 1, 1, TransportType.Train), [new Key(rotcAName, D, B)] = getMockedLegDTO(D, B, 1, 1, TransportType.Train), [new Key(rotcAName, D, E)] = getMockedLegDTO(D, E, 3, 3, TransportType.Train), [new Key(rotcBName, A, E)] = getMockedLegDTO(A, E, 25, 100, TransportType.Plane), [new Key(rotcBName, A, F)] = getMockedLegDTO(A, F, 10, 20, TransportType.Plane), [new Key(rotcBName, F, E)] = getMockedLegDTO(F, E, 20, 45, TransportType.Plane), [new Key(rotcBName, F, B)] = getMockedLegDTO(F, B, 10, 3, TransportType.Plane), [new Key(rotcCName, A, B)] = getMockedLegDTO(A, B, 2, 1000, TransportType.Train), [new Key(rotcCName, B, A)] = getMockedLegDTO(B, A, 2, 10, TransportType.Train), [new Key(rotcCName, A, C)] = getMockedLegDTO(A, C, 1, 1, TransportType.Train), [new Key(rotcCName, C, A)] = getMockedLegDTO(C, A, 1, 1, TransportType.Train), [new Key(rotcCName, E, C)] = getMockedLegDTO(E, C, 20, 100, TransportType.Train), [new Key(rotcCName, C, E)] = getMockedLegDTO(C, E, 20, 100, TransportType.Train), [new Key(rotcCName, C, F)] = getMockedLegDTO(C, F, 3, 5, TransportType.Train), [new Key(rotcCName, F, D)] = getMockedLegDTO(F, D, 5, 4, TransportType.Train), [new Key(rotcCName, E, B)] = getMockedLegDTO(E, B, 1, 1, TransportType.Train), [new Key(rotcCName, D, B)] = getMockedLegDTO(D, B, 1, 1, TransportType.Train), [new Key(rotcCName, D, E)] = getMockedLegDTO(D, E, 3, 3, TransportType.Train), [new Key(rotcCName, A, E)] = getMockedLegDTO(A, E, 25, 100, TransportType.Plane), [new Key(rotcCName, A, F)] = getMockedLegDTO(A, F, 10, 20, TransportType.Plane), [new Key(rotcCName, F, E)] = getMockedLegDTO(F, E, 4, 45, TransportType.Plane), [new Key(rotcCName, F, B)] = getMockedLegDTO(F, B, 10, 3, TransportType.Plane) }; var rotcAList = new List <ILegDTO>(); var rotcBList = new List <ILegDTO>(); var rotcCList = new List <ILegDTO>(); foreach (var v in createdLegs) { if (v.Key.Item1.Equals(rotcAName)) { rotcAList.Add((v.Value)); } else if (v.Key.Item1.Equals(rotcBName)) { rotcBList.Add((v.Value)); } else if (v.Key.Item1.Equals(rotcCName)) { rotcCList.Add(v.Value); } } var queryableA = rotcAList.AsQueryable(); var queryableB = rotcBList.AsQueryable(); var queryableC = rotcCList.AsQueryable(); mockRotcA = new Mock <IReadOnlyTravelCompany>(MockBehavior.Strict); foreach (var destination in allDestinations) { mockRotcA .Setup(l => l.FindDepartures(destination, TransportType.Train)) .Returns(new ReadOnlyCollection <ILegDTO>(getLegsFromChosenDestination(rotcAName, destination, createdLegs))); } mockRotcA .Setup(lst => lst.FindLegs(It.IsAny <Expression <Func <ILegDTO, bool> > >())) .Returns( (Expression <Func <ILegDTO, bool> > p) => { return(new ReadOnlyCollection <ILegDTO>(queryableA.Where(p.Compile()).ToList())); }); mockRotcB = new Mock <IReadOnlyTravelCompany>(MockBehavior.Strict); mockRotcB .Setup(l => l.FindDepartures(A, TransportType.Plane)) .Returns(new ReadOnlyCollection <ILegDTO>(getLegsFromChosenDestination(rotcBName, A, createdLegs))); mockRotcB .Setup(l => l.FindDepartures(F, TransportType.Plane)) .Returns(new ReadOnlyCollection <ILegDTO>(getLegsFromChosenDestination(rotcBName, F, createdLegs))); mockRotcB .Setup(l => l.FindDepartures(B, TransportType.Plane)) .Returns(new ReadOnlyCollection <ILegDTO>(getLegsFromChosenDestination(rotcBName, B, createdLegs))); mockRotcB .Setup(l => l.FindDepartures(E, TransportType.Plane)) .Returns(new ReadOnlyCollection <ILegDTO>(getLegsFromChosenDestination(rotcBName, E, createdLegs))); mockRotcB .Setup(lst => lst.FindLegs(It.IsAny <Expression <Func <ILegDTO, bool> > >())) .Returns( (Expression <Func <ILegDTO, bool> > p) => { return(new ReadOnlyCollection <ILegDTO>(queryableB.Where(p.Compile()).ToList())); }); mockRotcC = new Mock <IReadOnlyTravelCompany>(MockBehavior.Strict); foreach (var destination in allDestinations) { mockRotcC .Setup(l => l.FindDepartures(destination, TransportType.Train | TransportType.Plane)) .Returns(new ReadOnlyCollection <ILegDTO>(getLegsFromChosenDestination(rotcCName, destination, createdLegs))); } mockRotcC .Setup(lst => lst.FindLegs(It.IsAny <Expression <Func <ILegDTO, bool> > >())) .Returns( (Expression <Func <ILegDTO, bool> > p) => { return(new ReadOnlyCollection <ILegDTO>(queryableC.Where(p.Compile()).ToList())); }); rotcA = mockRotcA.Object; rotcB = mockRotcB.Object; rotcC = mockRotcC.Object; }
public void SetUp() { Planner = plannerFactory.CreateNew(); A = Cities[0]; B = Cities[1]; C = Cities[2]; D = Cities[3]; E = Cities[4]; F = Cities[5]; U = Cities[6]; CreatedLegs = new Dictionary <Key, ILegDTO> { [new Key(trenord, A, B)] = GetMockLegDTO(A, B, 5, 1, Train), //da 2 a i [new Key(alitalia, A, B)] = GetMockLegDTO(A, B, 10, 1, Plane), [new Key(costa, A, F)] = GetMockLegDTO(A, F, 20, 10, Ship), [new Key(alitalia, B, D)] = GetMockLegDTO(B, D, 5, 1, Plane), [new Key(trenord, B, D)] = GetMockLegDTO(B, D, 4, 2, Train), [new Key(alitalia, B, E)] = GetMockLegDTO(B, E, 50, 5, Plane), [new Key(costa, D, F)] = GetMockLegDTO(D, F, 5, 4, Ship), [new Key(trenord, A, C)] = GetMockLegDTO(A, C, 6, 3, Train), [new Key(trenord, C, A)] = GetMockLegDTO(C, A, 6, 3, Train), [new Key(trenord, C, E)] = GetMockLegDTO(C, E, 7, 4, Train), [new Key(trenord, E, F)] = GetMockLegDTO(E, F, 8, 20, Train), [new Key(alitalia, E, D)] = GetMockLegDTO(E, D, 50, 10, Plane), [new Key(trenord, F, E)] = GetMockLegDTO(F, E, 4, 20, Train), [new Key(costa, F, D)] = GetMockLegDTO(F, D, 5, 4, Ship) }; var trenordOffers = new List <ILegDTO>(); var alitaliaOffers = new List <ILegDTO>(); var costaOffers = new List <ILegDTO>(); foreach (var leg in CreatedLegs) { if (leg.Key.Item1 == trenord) { trenordOffers.Add(leg.Value); } if (leg.Key.Item1 == alitalia) { alitaliaOffers.Add(leg.Value); } if (leg.Key.Item1 == costa) { costaOffers.Add(leg.Value); } } var trenordLegs = trenordOffers.AsQueryable(); var alitaliaLegs = alitaliaOffers.AsQueryable(); var costaLegs = costaOffers.AsQueryable(); /********************************* TRENORD ************************************/ MockTrenord = new Mock <IReadOnlyTravelCompany>(MockBehavior.Strict); foreach (var city in new[] { "A", "B", "C", "D", "E", "F" }) { MockTrenord .Setup(m => m.FindDepartures(city, Bus)) .Returns(GetDepartures(trenord, city, Bus).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Train)) .Returns(GetDepartures(trenord, city, Train).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Ship)) .Returns(GetDepartures(trenord, city, Ship).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Plane)) .Returns(GetDepartures(trenord, city, Plane).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Bus | Train)) .Returns(GetDepartures(trenord, city, Bus | Train).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Bus | Plane)) .Returns(GetDepartures(trenord, city, Bus | Plane).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Bus | Ship)) .Returns(GetDepartures(trenord, city, Bus | Ship).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Train | Plane)) .Returns(GetDepartures(trenord, city, Train | Plane).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Train | Ship)) .Returns(GetDepartures(trenord, city, Train | Ship).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Plane | Ship)) .Returns(GetDepartures(trenord, city, Plane | Ship).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Plane | Ship | Train)) .Returns(GetDepartures(trenord, city, Plane | Ship | Train).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Plane | Ship | Bus)) .Returns(GetDepartures(trenord, city, Plane | Ship | Bus).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Plane | Bus | Train)) .Returns(GetDepartures(trenord, city, Plane | Bus | Train).AsReadOnly); MockTrenord .Setup(m => m.FindDepartures(city, Bus | Ship | Train)) .Returns(GetDepartures(trenord, city, Bus | Ship | Train).AsReadOnly); } MockTrenord .Setup(m => m.FindLegs(It.IsAny <Expression <Func <ILegDTO, bool> > >())) .Returns((Expression <Func <ILegDTO, bool> > p) => trenordLegs.AsEnumerable().Where(p.Compile()).ToList().AsReadOnly()); /********************************* ALITALIA ************************************/ MockAlitalia = new Mock <IReadOnlyTravelCompany>(MockBehavior.Strict); foreach (var city in new[] { "A", "B", "C", "D", "E", "F" }) { MockAlitalia .Setup(m => m.FindDepartures(city, Bus)) .Returns(GetDepartures(alitalia, city, Bus).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Train)) .Returns(GetDepartures(alitalia, city, Train).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Plane)) .Returns(GetDepartures(alitalia, city, Plane).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Ship)) .Returns(GetDepartures(alitalia, city, Ship).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Bus | Train)) .Returns(GetDepartures(alitalia, city, Bus | Train).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Bus | Plane)) .Returns(GetDepartures(alitalia, city, Bus | Plane).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Bus | Ship)) .Returns(GetDepartures(alitalia, city, Bus | Ship).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Train | Plane)) .Returns(GetDepartures(alitalia, city, Train | Plane).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Train | Ship)) .Returns(GetDepartures(alitalia, city, Train | Ship).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Plane | Ship)) .Returns(GetDepartures(alitalia, city, Plane | Ship).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Plane | Ship | Train)) .Returns(GetDepartures(alitalia, city, Plane | Ship | Train).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Plane | Ship | Bus)) .Returns(GetDepartures(alitalia, city, Plane | Ship | Bus).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Train | Ship | Bus)) .Returns(GetDepartures(alitalia, city, Train | Ship | Bus).AsReadOnly); MockAlitalia .Setup(m => m.FindDepartures(city, Train | Plane | Bus)) .Returns(GetDepartures(alitalia, city, Train | Plane | Bus).AsReadOnly); } MockAlitalia .Setup(m => m.FindLegs(It.IsAny <Expression <Func <ILegDTO, bool> > >())) .Returns((Expression <Func <ILegDTO, bool> > p) => alitaliaLegs.AsEnumerable().Where(p.Compile()).ToList().AsReadOnly()); /********************************* COSTA ************************************/ MockCosta = new Mock <IReadOnlyTravelCompany>(MockBehavior.Strict); foreach (var city in new[] { "A", "B", "C", "D", "E", "F" }) { MockCosta .Setup(m => m.FindDepartures(city, Bus)) .Returns(GetDepartures(costa, city, Bus).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Train)) .Returns(GetDepartures(costa, city, Train).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Plane)) .Returns(GetDepartures(costa, city, Plane).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Ship)) .Returns(GetDepartures(costa, city, Ship).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Bus | Train)) .Returns(GetDepartures(costa, city, Bus | Train).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Bus | Plane)) .Returns(GetDepartures(costa, city, Bus | Plane).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Bus | Ship)) .Returns(GetDepartures(costa, city, Bus | Ship).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Train | Plane)) .Returns(GetDepartures(costa, city, Train | Plane).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Train | Ship)) .Returns(GetDepartures(costa, city, Train | Ship).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Plane | Ship)) .Returns(GetDepartures(costa, city, Plane | Ship).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Plane | Ship | Train)) .Returns(GetDepartures(costa, city, Plane | Ship | Train).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Plane | Ship | Bus)) .Returns(GetDepartures(costa, city, Plane | Ship | Bus).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Plane | Bus | Train)) .Returns(GetDepartures(costa, city, Plane | Bus | Train).AsReadOnly); MockCosta .Setup(m => m.FindDepartures(city, Bus | Ship | Train)) .Returns(GetDepartures(costa, city, Bus | Ship | Train).AsReadOnly); } MockCosta .Setup(m => m.FindLegs(It.IsAny <Expression <Func <ILegDTO, bool> > >())) .Returns((Expression <Func <ILegDTO, bool> > p) => costaLegs.AsEnumerable().Where(p.Compile()).ToList().AsReadOnly()); Trenord = MockTrenord.Object; Alitalia = MockAlitalia.Object; Costa = MockCosta.Object; }