public void LocationTemplateModelClass_Constructor_SetsMapsPropertyToEmptyCollection() { LocationTemplateModel testOutput = new LocationTemplateModel(); Assert.IsNotNull(testOutput.Maps); Assert.AreEqual(0, testOutput.Maps.Count); }
/// <summary> /// Save a location template to a stream. /// </summary> /// <param name="locations">The list of locations to include in the template.</param> /// <param name="destination">The stream to save the location template to.</param> public static void Save(IEnumerable <Location> locations, Stream destination) { LocationTemplateModel locationTemplateModel = new LocationTemplateModel(); locationTemplateModel.Maps.Add(BuildNetworkMapModel(locations)); Serializer serialiser = GetSerializer(); using (StreamWriter writer = new StreamWriter(destination)) { writer.WriteLine("%WTL"); serialiser.Serialize(writer, locationTemplateModel); } }
internal static LocationCollection LoadXmlLocationTemplate(Stream str) { try { using (XmlReader reader = XmlReader.Create(str)) { if (reader == null) { throw new TimetableLoaderException(Resources.Error_CouldNotCreateXmlReader); } reader.MoveToContent(); if (reader.Name != "LocationTemplateModel") { throw new TimetableLoaderException(Resources.Error_XmlDoesNotContainLocationTemplateModel); } if (!int.TryParse(reader.GetAttribute("version"), out int version)) { throw new TimetableLoaderException(Resources.Error_XmlLocationTemplateDoesNotSpecifyVersion); } if (version > Versions.CurrentLocationTemplate) { throw new TimetableLoaderException(string.Format(CultureInfo.CurrentCulture, Resources.Error_XmlLocationTemplateUnsupportedVersion, version)); } // Version-detection code goes here! if (version < 3) { return(LoadLocationsVersion0(reader)); } XmlSerializer deserialiser = new XmlSerializer(typeof(LocationTemplateModel)); LocationTemplateModel templateModel = (LocationTemplateModel)deserialiser.Deserialize(reader); if (templateModel == null || templateModel.Maps == null || templateModel.Maps.Count == 0 || templateModel.Maps[0].LocationList == null) { return(null); } return(new LocationCollection(templateModel.Maps[0].LocationList.Select(l => l.ToLocation()))); } } catch (TimetableLoaderException) { throw; } catch (Exception ex) { throw new TimetableLoaderException(Resources.Error_GenericLoaderError, ex); } }
public void LocationTemplateModelClass_Constructor_SetsVersionPropertyTo3() { LocationTemplateModel testOutput = new LocationTemplateModel(); Assert.AreEqual(3, testOutput.Version.Value); }
public void LocationTemplateModelClass_ParameterlessConstructorSetsVersionPropertyTo3() { LocationTemplateModel model = new LocationTemplateModel(); Assert.AreEqual(3, model.Version); }
public void LocationTemplateModelClass_Constructor_CreatesObjectWithMapsPropertyThatIsNotNull() { LocationTemplateModel testOutput = new LocationTemplateModel(); Assert.IsNotNull(testOutput.Maps); }