Example #1
0
        public void TestLoadAndRunDynamicSecondImpl()
        {
            var cities = new Cities();

            cities.ReadCities(CitiesTestFile);

            ILinks links = LinksFactory.Create(cities,
                                               "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.TestLinksValidConstructor");

            Assert.AreEqual(42, links.ReadLinks("nonsense"));

            ILinks links2 = LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Links");

            Assert.AreNotEqual(links.GetType(), links2.GetType());

            try
            {
                LinksFactory.Create(cities,
                                    "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.Lab5Test.TestLinksInvalidConstructor");
                Assert.Fail("Should throw a NotSupportedException, because it doesn't have the right constructor");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.Lab10Test.TestLinksNoInterface");
                Assert.Fail("Should throw a NotSupportedException, because ILinks is not implemented");
            }
            catch (NotSupportedException)
            {
            }
        }
Example #2
0
        public void TestLoadAndRunDynamicClassicImpl()
        {
            var cities = new Cities();

            cities.ReadCities(CitiesTestFile);

            ILinks links = LinksFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Links");

            links.ReadLinks(LinksTestFile);

            Assert.AreEqual(28, cities.Count);

            // test available cities
            List <Link> resultLinks = links.FindShortestRouteBetween("Zürich", "Basel", TransportMode.Rail);

            var expectedLinks = new List <Link>();

            expectedLinks.Add(new Link(new City("Zürich", "Switzerland", 7000, 1, 2),
                                       new City("Aarau", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Aarau", "Switzerland", 7000, 1, 2),
                                       new City("Liestal", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Liestal", "Switzerland", 7000, 1, 2),
                                       new City("Basel", "Switzerland", 7000, 1, 2), 0));

            Assert.IsNotNull(resultLinks);
            Assert.AreEqual(expectedLinks.Count, resultLinks.Count);

            for (int i = 0; i < resultLinks.Count; i++)
            {
                Assert.IsTrue(
                    (expectedLinks[i].FromCity.Name == resultLinks[i].FromCity.Name &&
                     expectedLinks[i].ToCity.Name == resultLinks[i].ToCity.Name) ||
                    (expectedLinks[i].FromCity.Name == resultLinks[i].ToCity.Name &&
                     expectedLinks[i].ToCity.Name == resultLinks[i].FromCity.Name));
            }

            try
            {
                resultLinks = links.FindShortestRouteBetween("doesNotExist", "either", TransportMode.Rail);
                Assert.Fail("Should throw a KeyNotFoundException");
            }
            catch (KeyNotFoundException)
            {
            }
        }