public void TimetableFileModelClass_Constructor_SetsTrainClassListPropertyToEmptyCollection() { TimetableFileModel testOutput = new TimetableFileModel(); Assert.IsNotNull(testOutput.TrainClassList); Assert.AreEqual(0, testOutput.TrainClassList.Count); }
public void TimetableFileModelClass_Constructor_SetsNoteDefinitionsPropertyToEmptyCollection() { TimetableFileModel testOutput = new TimetableFileModel(); Assert.IsNotNull(testOutput.NoteDefinitions); Assert.AreEqual(0, testOutput.NoteDefinitions.Count); }
/// <summary> /// Convert a <see cref="TimetableDocument" /> instance to a <see cref="TimetableFileModel" /> instance. /// </summary> /// <param name="doc">The object to convert.</param> /// <returns>A <see cref="TimetableFileModel" /> instance containing the same data as the parameter, in serialisable form.</returns> /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception> public static TimetableFileModel ToYamlTimetableFileModel(this TimetableDocument doc) { if (doc is null) { throw new NullReferenceException(); } TimetableFileModel fileModel = new TimetableFileModel { Version = Versions.CurrentTimetableDocument, FileOptions = doc.Options.ToYamlDocumentOptionsModel(), ExportOptions = doc.ExportOptions.ToYamlExportOptionsModel(), Title = doc.Title, Subtitle = doc.Subtitle, DateDescription = doc.DateDescription, WrittenBy = doc.WrittenBy, CheckedBy = doc.CheckedBy, TimetableVersion = doc.TimetableVersion, PublishedDate = doc.PublishedDate, }; fileModel.Maps.Add(BuildNetworkMapModel(doc)); fileModel.TrainList.AddRange(doc.TrainList.Select(t => t.ToYamlTrainModel())); fileModel.NoteDefinitions.AddRange(doc.NoteDefinitions.Select(n => n.ToYamlNoteModel())); fileModel.TrainClassList.AddRange(doc.TrainClassList.Select(c => c.ToYamlTrainClassModel())); fileModel.SignalboxHoursSets.AddRange(doc.SignalboxHoursSets.Select(s => s.ToYamlSignalboxHoursSetModel())); return(fileModel); }
public void TimetableFileModelClass_Constructor_SetsSignalboxHoursSetsPropertyToEmptyCollection() { TimetableFileModel testOutput = new TimetableFileModel(); Assert.IsNotNull(testOutput.SignalboxHoursSets); Assert.AreEqual(0, testOutput.SignalboxHoursSets.Count); }
/// <summary> /// Convert a <see cref="TimetableDocument"/> instance to a <see cref="TimetableFileModel"/> for serialization. /// </summary> /// <param name="document">The instance to be converted.</param> /// <returns>The data prepared for serialization.</returns> public static TimetableFileModel ToTimetableFileModel(this TimetableDocument document) { if (document is null) { throw new ArgumentNullException(nameof(document)); } TimetableFileModel fileModel = new TimetableFileModel { Version = Versions.CurrentTimetableDocument, Options = document.Options.ToDocumentOptionsModel(), ExportOptions = document.ExportOptions.ToExportOptionsModel(), Title = document.Title, Subtitle = document.Subtitle, DateDescription = document.DateDescription, WrittenBy = document.WrittenBy, CheckedBy = document.CheckedBy, TimetableVersion = document.TimetableVersion, PublishedDate = document.PublishedDate, }; NetworkMapModel nmm = new NetworkMapModel(); nmm.LocationList.AddRange(document.LocationList.Select(l => l.ToLocationModel())); nmm.Signalboxes.AddRange(document.Signalboxes.Select(b => b.ToSignalboxModel())); fileModel.Maps.Add(nmm); fileModel.NoteDefinitions.AddRange(document.NoteDefinitions.Select(n => n.ToNoteModel())); fileModel.TrainClassList.AddRange(document.TrainClassList.Select(tc => tc.ToTrainClassModel())); fileModel.TrainList.AddRange(document.TrainList.Select(t => t.ToTrainModel())); fileModel.SignalboxHoursSets.AddRange(document.SignalboxHoursSets.Select(h => h.ToSignalboxHoursSetModel())); return(fileModel); }
public void TimetableFileModelExtensionsClass_ToTimetableDocumentMethod_ThrowsArgumentNullException_IfParameterIsNull() { TimetableFileModel testObject = null; _ = testObject.ToTimetableDocument(); Assert.Fail(); }
public void TimetableDocumentExtensionsClass_ToTimetableFileModelMethod_ReturnsModelWithExportOptionsPropertyThatIsNotNull() { TimetableDocument document = new TimetableDocument(); TimetableFileModel result = document.ToTimetableFileModel(); Assert.IsNotNull(result.ExportOptions); }
public void TimetableFileModelExtensionsClassToTimetableDocumentMethodReturnsTimetableDocumentObjectWithExportOptionsPropertyThatIsNotNullIfExportOptionsPropertyOfParameterIsNotNull() { TimetableFileModel testSourceObject = new TimetableFileModel { ExportOptions = new ExportOptionsModel() }; TimetableDocument testResultObject = testSourceObject.ToTimetableDocument(); Assert.IsNotNull(testResultObject.ExportOptions); }
public void TimetableFIleModelExtensionsClass_ToTimetableDocumentMethod_ThrowsArgumentNullExceptionWithCorrectParamNameProperty_IfParameterIsNull() { TimetableFileModel testObject = null; try { _ = testObject.ToTimetableDocument(); Assert.Fail(); } catch (ArgumentNullException ex) { Assert.AreEqual("file", ex.ParamName); } }
public void TimetableFileModelExtensionsClassToTimetableDocumentMethodReturnsTimetableDocumentObjectWithExportOptionsPropertyWithCorrectDisplayLocoDiagramRowPropertyIfExportOptionsPropertyOfParameterIsNotNull() { Random random = new Random(); for (int i = 0; i < TestMultipleRuns; ++i) { bool testValue = random.NextBoolean(); TimetableFileModel testSourceObject = new TimetableFileModel { ExportOptions = new ExportOptionsModel { DisplayLocoDiagramRow = testValue } }; TimetableDocument testResultObject = testSourceObject.ToTimetableDocument(); Assert.AreEqual(testValue, testResultObject.ExportOptions.DisplayLocoDiagramRow); } }
public void TimetableDocumentExtensionsClass_ToTimetableFileModelMethod_ReturnsModelWithExportOptionsPropertyWithCorrectDisplayLocoDiagramRowValue() { Random random = new Random(); for (int i = 0; i < TestMultipleRuns; ++i) { bool testValue = random.NextBoolean(); TimetableDocument document = new TimetableDocument { ExportOptions = new DocumentExportOptions { DisplayLocoDiagramRow = testValue } }; TimetableFileModel result = document.ToTimetableFileModel(); Assert.AreEqual(testValue, result.ExportOptions.DisplayLocoDiagramRow); } }
/// <summary> /// Convert a <see cref="TimetableFileModel" /> instance to a <see cref="TimetableDocument" /> instance. /// </summary> /// <param name="model">The object to convert.</param> /// <returns>A <see cref="TimetableDocument" /> instance containing the same data as the parameter.</returns> /// <exception cref="NullReferenceException">Thrown if the parameter is <c>null</c>.</exception> public static TimetableDocument ToTimetableDocument(this TimetableFileModel model) { if (model is null) { throw new NullReferenceException(); } Dictionary <string, Signalbox> signalboxes = new Dictionary <string, Signalbox>(); Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_TimetableFileModelConversionVersion, model.Version); TimetableDocument document = new TimetableDocument { Version = model.Version, Options = model.FileOptions != null?model.FileOptions.ToDocumentOptions() : new DocumentOptions(), ExportOptions = model.ExportOptions != null?model.ExportOptions.ToDocumentExportOptions() : new DocumentExportOptions(), Title = model.Title ?? string.Empty, Subtitle = model.Subtitle ?? string.Empty, DateDescription = model.DateDescription ?? string.Empty, WrittenBy = model.WrittenBy ?? string.Empty, CheckedBy = model.CheckedBy ?? string.Empty, TimetableVersion = model.TimetableVersion ?? string.Empty, PublishedDate = model.PublishedDate ?? string.Empty, }; if (model.Maps != null && model.Maps.Count > 0 && model.Maps[0] != null) { if (model.Maps[0].LocationList != null) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_LocationCount, model.Maps[0].LocationList.Count); foreach (LocationModel loc in model.Maps[0].LocationList) { document.LocationList.Add(loc.ToLocation()); } Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_LocationsLoaded, document.LocationList.Count); } else { Log.Trace("No locations to load."); } if (model.Maps[0].Signalboxes != null) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_SignalboxCount, model.Maps[0].Signalboxes.Count); foreach (SignalboxModel box in model.Maps[0].Signalboxes) { Signalbox b = box.ToSignalbox(); document.Signalboxes.Add(b); if (!signalboxes.ContainsKey(b.Id)) { signalboxes.Add(b.Id, b); } } Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_SignalboxesLoaded, document.Signalboxes.Count); } else { Log.Trace("No signalboxes to load"); } } if (model.SignalboxHoursSets != null) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_SignalboxHoursSetCount, model.SignalboxHoursSets.Count); foreach (SignalboxHoursSetModel set in model.SignalboxHoursSets) { document.SignalboxHoursSets.Add(set.ToSignalboxHoursSet(signalboxes, document.SignalboxHoursSets)); } Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_SignalboxHoursSetsLoaded, document.SignalboxHoursSets.Count); } else { Log.Trace("No signalbox hours sets to load."); } if (model.NoteDefinitions != null) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_NoteDefinitionCount, model.NoteDefinitions.Count); foreach (NoteModel note in model.NoteDefinitions) { document.NoteDefinitions.Add(note.ToNote()); } Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_NoteDefinitionsLoaded, document.NoteDefinitions.Count); } else { Log.Trace("No note definitions to load."); } if (model.TrainClassList != null) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_TrainClassCount, model.TrainClassList.Count); foreach (TrainClassModel tc in model.TrainClassList) { document.TrainClassList.Add(tc.ToTrainClass()); } Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_TrainClassesLoaded, document.TrainClassList.Count); } else { Log.Trace("No train classes to load."); } Dictionary <string, Location> locationMap = document.LocationList.ToDictionary(o => o.Id); Dictionary <string, TrainClass> classMap = document.TrainClassList.ToDictionary(c => c.Id); Dictionary <string, Note> noteMap = document.NoteDefinitions.ToDictionary(n => n.Id); if (model.TrainList != null) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_TrainCount, model.TrainList.Count); foreach (TrainModel trn in model.TrainList) { document.TrainList.Add(trn.ToTrain(locationMap, classMap, noteMap, document.Options)); } Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_TrainsLoaded, document.TrainList.Count); } else { Log.Trace("No trains to load."); } return(document); }
public void TimetableFileModelClass_Constructor_CreatesObjectWithSignalboxHoursSetsPropertyThatIsNotNull() { TimetableFileModel testOutput = new TimetableFileModel(); Assert.IsNotNull(testOutput.SignalboxHoursSets); }
public void TimetableFileModelClass_Constructor_CreatesObjectWithTrainListPropertyThatIsNotNull() { TimetableFileModel testOutput = new TimetableFileModel(); Assert.IsNotNull(testOutput.TrainList); }
public void TimetableFileModelClass_Constructor_CreatesObjectWithNoteDefinitionsPropertyThatIsNotNull() { TimetableFileModel testOutput = new TimetableFileModel(); Assert.IsNotNull(testOutput.NoteDefinitions); }