public void TestFilter() { IUsable s1 = new UsableMock("s1"); IUsable s2 = new UsableMock("s2"); ITrackingDevice t1 = new TrackingMock(1); ITrackingDevice t2 = new TrackingMock(2); IList <IUsage> usage = new List <IUsage>(); IList <IUsage> okUsage = new List <IUsage>(); IUsage u; u = new UsageMock(s1.Availability.StartDate, t1, s1); usage.Add(u); usage.Add(u); okUsage.Add(u); okUsage.Add(u); u = new UsageMock(s1.Availability.StartDate, t1, s2); usage.Add(u); u = new UsageMock(s1.Availability.EndDate, t1, s1); usage.Add(u); okUsage.Add(u); u = new UsageMock(s1.Availability.EndDate.AddDays(1), t1, s1); usage.Add(u); DatePriceDescriptor dpd = new DatePriceDescriptor("p1", "p1test", s1.Availability); DateRangePacket tp = new DateRangePacket(dpd, s1, s1.Availability); IEnumerable <IUsage> result = tp.Filter(usage); IEnumerable <IUsage> expected = usage.Except(okUsage); Assert.AreEqual(expected.Count(), result.Count()); for (int i = 0; i < result.Count(); i++) { Assert.AreEqual(expected.ElementAt(i), result.ElementAt(i)); } }
private TreeNode[] CustomPacket(DateRangePacket packet) { TreeNode node = new TreeNode(); node.Text = packet.Name + ", " + packet.Description + ", prezzo :" + packet.Price + ", usufruibile per " + packet.Duration + " giorni"; return(new TreeNode[] { node }); }
protected override void Init() { DateRange date1 = new DateRange(10); DateRange date2 = new DateRange(12); IUsable service1 = new BasicService(new DatePriceDescriptor("Massaggio", "Massaggio sotto l'ombrellone", date1, 5.0)); IUsable service2 = new BasicService(new DatePriceDescriptor("Piscina termale 1h", "Accesso alla piscina termale per 1 ora", date2, 6.0)); IUsable service3 = new BasicService(new DatePriceDescriptor("Happy aperitivo", "Accesso alla zona happy aperitivo", date2, 4.0)); IUsable service4 = new BasicService(new DatePriceDescriptor("Doccia calda", "Accesso alla doccia calda", new DateRange(15), 0.5)); _services.Add(service1); _services.Add(service2); _services.Add(service3); _services.Add(service4); IPacket packet1 = new TicketPacket((new DatePriceDescriptor("Piscina termale x10", "Ticket per l'accesso alla piscina termale", date1, 48.0)), service2, 10); IPacket packet2 = new TicketPacket((new DatePriceDescriptor("Massaggio x3", "include 3 massaggi al prezzo di 2", date1, 10)), service1, 3); IPacket packet3 = new DateRangePacket((new DatePriceDescriptor("Doccia calda", "accesso alla doccia calsa", date1, 5)), service4, 15); _packets.Add(packet1); _packets.Add(packet2); _packets.Add(packet3); ISet <IPacket> bundleSet = new HashSet <IPacket>(); bundleSet.Add(packet2); bundleSet.Add(packet3); IBundle bundle1 = new Bundle(bundleSet, new DatePriceDescriptor("Welcome Pack", "Bundle di benvenuto ", date1, 12)); _bundles.Add(bundle1); IUsage usage1 = new UsageService(new DateTime(2017, 7, 16), new SimpleCard(0), service1); IUsage usage2 = new UsageService(new DateTime(2017, 7, 16), new SimpleCard(0), service2); IUsage usage3 = new UsageService(new DateTime(2017, 8, 10), new SimpleCard(1), service2); IPrenotationCoordinator prenotationCoordinator = CoordinatorManager.Instance.CoordinatorOfType <IPrenotationCoordinator>(); _usages.Add(usage1); _usages.Add(usage2); _usages.Add(usage3); }
public void TestDateRangePacketConstructor() { //The happy path takes in a legal action string, session ID, dateStart, //dateEnd, and id and it checks to make sure the values are correctly //set in the packet. string action = "Add Member"; string sessionID = "1209384209385"; string dateStart = "11-01-2017"; string dateEnd = "11-07-2017"; string id = "987654321"; DateRangePacket testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id); Assert.AreEqual(dateStart, testPacket.DateStart()); Assert.AreEqual(dateEnd, testPacket.DateEnd()); Assert.AreEqual(id, testPacket.ID()); //This test checks whether the ArgumentException gets thrown if a null //string is entered for the dateStart string. dateStart = null; Assert.ThrowsException <ArgumentException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentException gets thrown if a null //string is entered for the dateEnd string. dateStart = "11-01-2017"; dateEnd = null; Assert.ThrowsException <ArgumentException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentException gets thrown if a null //string is entered for the id string. dateEnd = "11-07-2017"; id = null; //This one is an argumentException because it fails to parse. Assert.ThrowsException <ArgumentException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentException gets thrown if a the //string for the id isn't a number. id = "Member #42"; Assert.ThrowsException <ArgumentException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentOutOfRangeException gets thrown if a the //string for the id is a number that is smaller then nine-digit number. id = "42"; Assert.ThrowsException <ArgumentOutOfRangeException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentOutOfRangeException gets thrown if a the //string for the id is a number that is larger then nine-digit number. id = "1000000000"; Assert.ThrowsException <ArgumentOutOfRangeException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentException gets thrown if a the //string for the dateStart isn't a legal date. dateStart = "hi"; id = "987654321"; Assert.ThrowsException <ArgumentException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); //This test checks whether the ArgumentException gets thrown if a the //string for the dateEnd isn't a legal date. dateStart = "11-01-2017"; dateEnd = "hi"; Assert.ThrowsException <ArgumentException>( () => testPacket = new DateRangePacket(action, sessionID, dateStart, dateEnd, id)); return; }