示例#1
0
        public void TestAddCity()
        {
            var cities = new Cities();

            Assert.AreEqual(1, cities.AddCity(new City("Bern", "Schweiz", 75000, 47.4793198, 8.2129669189)));
            Assert.AreEqual(2, cities.AddCity(new City("Zurich", "Schweiz", 375000, 47.4793198, 8.2129669189)));
            Assert.AreEqual(3, cities.AddCity(new City("Aarau", "Schweiz", 25000, 47.4793198, 8.2129669189)));
        }
示例#2
0
        public void TestIndexer()
        {
            var cities = new Cities();

            // we call the overwritten method of the mock class
            cities.AddCity(new City("Bern", "Schweiz", 75000, 47.4793198, 8.2129669189));
            cities.AddCity(new City("Zurich", "Schweiz", 375000, 47.4793198, 8.2129669189));
            cities.AddCity(new City("Aarau", "Schweiz", 25000, 47.4793198, 8.2129669189));

            Assert.AreEqual("Bern", cities[0].Name);
            Assert.AreEqual("Zurich", cities[1].Name);
            Assert.AreEqual("Aarau", cities[2].Name);

            // check for invalid index
            try
            {
                var c = cities[-1];
                Assert.Fail("Invalid index not handled properly");
            }
            catch (ArgumentOutOfRangeException _iore)
            {
                Assert.IsTrue(_iore.Message.Length > 2, "IndexOutOfRangeException has no meaningful description");
            }
            catch
            {
                Assert.Fail("Wrong exception type thrown on invalid index");
            }

            try
            {
                var c = cities[100];
                Assert.Fail("Invalid index not handled properly");
            }
            catch (ArgumentOutOfRangeException _iore)
            {
                Assert.IsTrue(_iore.Message.Length > 2, "IndexOutOfRangeException has no meaningful description");
            }
            catch
            {
                Assert.Fail("Wrong exception type thrown on invalid index");
            }
        }