示例#1
0
        public void TestAddStationInfo()
        {
            // create new List collection of type StationData
            var stationInfo = new List <StationData>();

            try
            {
                // confirm created collection is empty
                Assert.Null(stationInfo);
            }
            // prints exception error stack trace
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            try
            {
                // create new stationData object using the object initializer
                var stationData = new StationData
                {
                    Longitude = "longitude",
                    Latitude  = "latitude",
                    StationId = "stationId",
                    Csv       = "csv",
                    Json      = "json"
                };
                // confirm expected values match what was added to object above
                Assert.AreEqual(stationData.Longitude, "longitude");
                Assert.AreEqual(stationData.Latitude, "latitude");
                Assert.AreEqual(stationData.StationId, "stationId");
                Assert.AreEqual(stationData.Csv, "csv");
                Assert.AreEqual(stationData.Json, "json");
                // adds stationData to stationInfo list
                stationInfo.Add(stationData);
                // confirm stationInfo is no longer null
                Assert.NotNull(stationInfo);
                // confirms StationInfo only contains the single stationData object added
                Assert.AreEqual(stationInfo.Count, 1);
                Assert.AreNotEqual(stationInfo.Count, 2);
            }
            // prints exception error stack trace
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
        }