public void TrainTimeModelClass_Constructor_SetsFootnoteIdsPropertyToEmptyCollection()
        {
            TrainTimeModel testOutput = new TrainTimeModel();

            Assert.IsNotNull(testOutput.FootnoteIds);
            Assert.AreEqual(0, testOutput.FootnoteIds.Count);
        }
Ejemplo n.º 2
0
        public void TrainTimeModelClass_WriteXmlMethod_ThrowsArgumentNullException_IfParameterIsNull()
        {
            TrainTimeModel testObject = new TrainTimeModel();

            testObject.WriteXml(null);

            Assert.Fail();
        }
Ejemplo n.º 3
0
        public void TrainTimeExtensionsClass_ToYamlTrainTimeModelMethod_ReturnsObjectWithFootnoteIdsPropertyOfCorrectLength_WhenParameterIsNotNull()
        {
            TrainTime testParam = GetTestObject();

            TrainTimeModel testOutput = testParam.ToYamlTrainTimeModel();

            Assert.AreEqual(testParam.Footnotes.Count, testOutput.FootnoteIds.Count);
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ThrowsArgumentNullException_IfFirstParameterIsNull()
        {
            TrainTimeModel            testObject = null;
            Dictionary <string, Note> testParam1 = new Dictionary <string, Note>();

            _ = testObject.ToTrainTime(testParam1);

            Assert.Fail();
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ThrowsNullReferenceException_IfFirstParameterIsNull()
        {
            TrainTimeModel            testParam0 = null;
            Dictionary <string, Note> testParam1 = new Dictionary <string, Note>();

            _ = testParam0.ToTrainTime(testParam1);

            Assert.Fail();
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ThrowsKeyNotFoundException_IfSecondParameterIsEmptyCollection()
        {
            TrainTimeModel            testParam0 = GetTestObject();
            Dictionary <string, Note> testParam1 = new Dictionary <string, Note>();

            _ = testParam0.ToTrainTime(testParam1);

            Assert.Fail();
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ReturnsObjectWithEmptyFootnotesCollection_IfSecondParameterIsNull()
        {
            TrainTimeModel            testParam0 = GetTestObject();
            Dictionary <string, Note> testParam1 = null;

            TrainTime testOutput = testParam0.ToTrainTime(testParam1);

            Assert.IsNotNull(testOutput.Footnotes);
            Assert.AreEqual(0, testOutput.Footnotes.Count);
        }
Ejemplo n.º 8
0
        public void TrainTimeExtensionsClass_ToYamlTrainTimeModelMethod_ReturnsObjectWithAtPropertyThatIsNull_WhenParameterHasTimePropertyThatIsNull()
        {
            TrainTime testParam = GetTestObject();

            testParam.Time = null;

            TrainTimeModel testOutput = testParam.ToYamlTrainTimeModel();

            Assert.IsNull(testOutput.At);
        }
Ejemplo n.º 9
0
        public void TrainTimeExtensionsClass_ToYamlTrainTimeModelMethod_ReturnsObjectWithFootnoteIdsPropertyContainingCorrectValues_WhenParameterIsNotNull()
        {
            TrainTime testParam = GetTestObject();

            TrainTimeModel testOutput = testParam.ToYamlTrainTimeModel();

            for (int i = 0; i < testParam.Footnotes.Count; ++i)
            {
                Assert.AreEqual(testParam.Footnotes[i].Id, testOutput.FootnoteIds[i]);
            }
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ReturnsObjectWithTimePropertyEqualToNull_IfFirstParameterHasAtPropertyThatIsNull()
        {
            TrainTimeModel testParam0 = GetTestObject();

            testParam0.At = null;
            Dictionary <string, Note> testParam1 = GetNoteDictionaryWithContents(testParam0.FootnoteIds);

            TrainTime testOutput = testParam0.ToTrainTime(testParam1);

            Assert.IsNull(testOutput.Time);
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ThrowsFormatException_IfFirstParameterHasAtPropertyWithTimePropertyThatIsNonNumericString()
        {
            TrainTimeModel         testParam0    = GetTestObject();
            TimeOfDaySpecification testParamSpec = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.NonNumericValue);

            testParam0.At = testParamSpec.Model;
            Dictionary <string, Note> testParam1 = new Dictionary <string, Note>();

            _ = testParam0.ToTrainTime(testParam1);

            Assert.Fail();
        }
Ejemplo n.º 12
0
        public void TrainTimeExtensionsClass_ToYamlTrainTimeModelMethod_ReturnsObjectWithAtPropertyWithCorrectTimeProperty_WhenParameterHasTimePropertyThatIsNotNull()
        {
            TrainTime testParam = GetTestObject();

            TrainTimeModel testOutput = testParam.ToYamlTrainTimeModel();

            string expectedValue = testParam.Time.Hours24.ToString("d2", CultureInfo.InvariantCulture) + ":" +
                                   testParam.Time.Minutes.ToString("d2", CultureInfo.InvariantCulture) + ":" +
                                   testParam.Time.Seconds.ToString("d2", CultureInfo.InvariantCulture);

            Assert.AreEqual(expectedValue, testOutput.At.Time);
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ReturnsObjectWithFootnotesCollectionWithCorrectContents_IfSecondParameterIsCollectionWithAllElementsContainedInFootnoteIdsPropertyOfFirstParameter()
        {
            TrainTimeModel            testParam0 = GetTestObject();
            Dictionary <string, Note> testParam1 = GetNoteDictionaryWithContents(testParam0.FootnoteIds);

            TrainTime testOutput = testParam0.ToTrainTime(testParam1);

            Assert.AreEqual(testParam0.FootnoteIds.Count, testOutput.Footnotes.Count);
            for (int i = 0; i < testParam0.FootnoteIds.Count; ++i)
            {
                Assert.AreEqual(testParam0.FootnoteIds[i], testOutput.Footnotes[i].Id);
            }
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ReturnsObjectWithCorrectTimeProperty_IfFirstParameterHasAtPropertyWithTimePropertyThatIsMoreThanThreeNumbersInRangeSeparatedByColons()
        {
            TrainTimeModel         testParam0    = GetTestObject();
            TimeOfDaySpecification testParamSpec = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.HoursMinutesSecondsAndMore);

            testParam0.At = testParamSpec.Model;
            Dictionary <string, Note> testParam1 = GetNoteDictionaryWithContents(testParam0.FootnoteIds);

            TrainTime testOutput = testParam0.ToTrainTime(testParam1);

            Assert.AreEqual(testParamSpec.Hours.Value, testOutput.Time.Hours24);
            Assert.AreEqual(testParamSpec.Minutes.Value, testOutput.Time.Minutes);
            Assert.AreEqual(testParamSpec.Seconds.Value, testOutput.Time.Seconds);
        }
Ejemplo n.º 15
0
        public void TrainTimeModelClass_WriteXmlMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull()
        {
            TrainTimeModel testObject = new TrainTimeModel();

            try
            {
                testObject.WriteXml(null);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("writer", ex.ParamName);
            }
        }
        public void TrainTimeModelExtensionsClass_ToTrainTimeMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfFirstParameterIsNull()
        {
            TrainTimeModel            testObject = null;
            Dictionary <string, Note> testParam1 = new Dictionary <string, Note>();

            try
            {
                _ = testObject.ToTrainTime(testParam1);
                Assert.Fail();
            }
            catch (ArgumentNullException ex)
            {
                Assert.AreEqual("model", ex.ParamName);
            }
        }
        /// <summary>
        /// Convert a <see cref="TrainTime" /> instance to a <see cref="TrainTimeModel" /> instance.
        /// </summary>
        /// <param name="tt">The object to convert.</param>
        /// <returns>A <see cref="TrainTimeModel" /> instance containing the same data as the parameter.</returns>
        /// <exception cref="NullReferenceException">Thrown if the parameter is null.</exception>
        public static TrainTimeModel ToYamlTrainTimeModel(this TrainTime tt)
        {
            if (tt is null)
            {
                throw new NullReferenceException();
            }

            TrainTimeModel model = new TrainTimeModel
            {
                At = tt.Time?.ToYamlTimeOfDayModel(),
            };

            model.FootnoteIds.AddRange(tt.Footnotes.Select(n => n.Id));

            return(model);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Convert a <see cref="TrainTime"/> instance into a <see cref="TrainTimeModel"/> instance.
        /// </summary>
        /// <param name="time">The object to convert.</param>
        /// <returns>A <see cref="TrainTimeModel"/> instance containing the same data as the parameter.</returns>
        public static TrainTimeModel ToTrainTimeModel(this TrainTime time)
        {
            if (time is null)
            {
                throw new ArgumentNullException(nameof(time));
            }

            TrainTimeModel model = new TrainTimeModel
            {
                Time = time.Time?.ToTimeOfDayModel(),
            };

            model.FootnoteIds.AddRange(time.Footnotes.Select(n => n.Id));

            return(model);
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Populate this object's properties from XML.
 /// </summary>
 /// <param name="reader">Source of XML data.</param>
 public void ReadXml(XmlReader reader)
 {
     if (reader is null)
     {
         throw new ArgumentNullException(nameof(reader));
     }
     reader.ReadStartElement();
     reader.MoveToContent();
     if (reader.LocalName == "ArrivalTime")
     {
         ArrivalTime = new TrainTimeModel();
         ArrivalTime.ReadXml(reader);
         reader.MoveToContent();
     }
     if (reader.LocalName == "DepartureTime")
     {
         DepartureTime = new TrainTimeModel();
         DepartureTime.ReadXml(reader);
         reader.MoveToContent();
     }
     if (reader.LocalName == "Pass")
     {
         Pass = reader.ReadElementContentAsBoolean();
         reader.MoveToContent();
     }
     if (reader.LocalName == "LocationId")
     {
         LocationId = reader.ReadElementContentAsString();
         reader.MoveToContent();
     }
     if (reader.LocalName == "Path")
     {
         Path = reader.ReadElementContentAsString();
         reader.MoveToContent();
     }
     if (reader.LocalName == "Platform")
     {
         Platform = reader.ReadElementContentAsString();
         reader.MoveToContent();
     }
     if (reader.LocalName == "Line")
     {
         Line = reader.ReadElementContentAsString();
         reader.MoveToContent();
     }
     reader.ReadEndElement();
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Convert a serializable <see cref="TrainTimeModel"/> object into a <see cref="TrainTime"/> object.
        /// </summary>
        /// <param name="model">The object to load.</param>
        /// <param name="notes">Dictionary of footnotes occurring in the timetable.</param>
        /// <returns>A <see cref="TrainTime"/> instance.</returns>
        public static TrainTime ToTrainTime(this TrainTimeModel model, Dictionary <string, Note> notes)
        {
            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            TrainTime tt = new TrainTime {
                Time = model.Time?.ToTimeOfDay()
            };

            foreach (string noteId in model.FootnoteIds)
            {
                tt.Footnotes.Add(notes?[noteId]);
            }

            return(tt);
        }
        private static TrainTimeModel GetTestObject()
        {
            TimeOfDaySpecification timeSpec = new TimeOfDaySpecification(TimeOfDaySpecification.TimeOfDaySpecificationKind.HoursMinutesSeconds);
            TrainTimeModel         model    = new TrainTimeModel {
                At = timeSpec.Model
            };
            int noteCount = _rnd.Next(5);

            for (int i = 0; i < noteCount; ++i)
            {
                string noteId;
                do
                {
                    noteId = _rnd.NextHexString(8);
                } while (model.FootnoteIds.Contains(noteId));
                model.FootnoteIds.Add(noteId);
            }
            return(model);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Convert a <see cref="TrainTimeModel" /> instance to a <see cref="TrainTime" /> instance.
        /// </summary>
        /// <param name="model">The object to be converted.</param>
        /// <param name="notes">A dictionary of known footnotes, used to resolve ID-based references to footnotes in the model.</param>
        /// <returns>A <see cref="TrainTime" /> object containing the same data as the <c>model</c> parameter, with all references resolved.</returns>
        /// <exception cref="NullReferenceException">Thrown if the <c>model</c> parameter is null.</exception>
        public static TrainTime ToTrainTime(this TrainTimeModel model, IDictionary <string, Note> notes)
        {
            if (model is null)
            {
                throw new NullReferenceException();
            }

            TrainTime tt = new TrainTime {
                Time = model.At?.ToTimeOfDay()
            };

            foreach (string noteId in model.FootnoteIds)
            {
                Note note = notes?[noteId];
                if (note != null)
                {
                    tt.Footnotes.Add(notes?[noteId]);
                }
            }

            return(tt);
        }
Ejemplo n.º 23
0
        public void TrainTimeModelClass_Constructor_CreatesObjectWithFootnoteIdsPropertyThatIsNotNull()
        {
            TrainTimeModel testOutput = new TrainTimeModel();

            Assert.IsNotNull(testOutput.FootnoteIds);
        }