public void all_Licence_numbers_are_7_digit_integers() { var entities = new EntitiesContext(); var siteRepository = new EntityRepository<Site>(entities); var licenceRepository = new EntityRepository<Licence>(entities); var antennaRepository = new EntityRepository<Antenna>(entities); ISiteService siteService = new SiteService(siteRepository, licenceRepository, antennaRepository); var licences = siteService.GetLicences(); foreach (var licence in licences) { int n; int.TryParse(licence.SpectrumLicence, out n); var s = n.ToString(); var target = s.Length; //if (digitCount != 7) //{ //this.TestContext.WriteLine("\tInvalid Licence Number: " + s); //throw new ApplicationException("\tInvalid Licence Number: " + s); //} Assert.AreEqual(7, target); } }
public void Can_Validate_Station_Data() { var entities = new EntitiesContext(); var siteRepository = new EntityRepository<Site>(entities); var licenceRepository = new EntityRepository<Licence>(entities); var antennaRepository = new EntityRepository<Antenna>(entities); ISiteService siteService = new SiteService(siteRepository, licenceRepository, antennaRepository); XNamespace ns = "http://sd.ic.gc.ca/SLDR_Schema_Definition_en"; IEnumerable<XElement> spectrum_licences = siteService .GetLicences() .ToList() .Where(x => x.Antennas.Any()) .OrderBy(x => x.SpectrumLicence) //.Take(3) .Select(x => new XElement("spectrum_licence", new XElement("licence_number", x.SpectrumLicence), new XElement("office_number", 7), new XElement("company_code", x.CompanyCode), new XElement("reference_number", x.ReferenceNumber), new XElement("contact_name", x.ContactName), new XElement("business_telephone", x.Phone), new XElement("extension", x.PhoneExt), new XElement("email_address", x.Email), getStations(x) )); XDocument doc = new XDocument(new XElement("spectrum_licence_data_registry", spectrum_licences)); foreach (XElement e in doc.Root.DescendantsAndSelf()) { if (e.Name.Namespace == "") e.Name = ns + e.Name.LocalName; } XmlReaderSettings sldrSettings = new XmlReaderSettings(); sldrSettings.Schemas.Add(ns.NamespaceName, @"c:\temp\SLDR_Schema_Definition_en.xsd"); sldrSettings.ValidationType = ValidationType.Schema; sldrSettings.ValidationEventHandler += new ValidationEventHandler(validationCallBack); //using (MemoryStream stream = new MemoryStream()) using (FileStream stream = new FileStream(@"c:\temp\Silo_Station_Data.xml", FileMode.Create, FileAccess.ReadWrite)) { StreamWriter writer = new StreamWriter(stream, Encoding.Default); doc.Save(writer); stream.Flush(); stream.Seek(0, SeekOrigin.Begin); XmlReader data = XmlReader.Create(stream, sldrSettings); while (data.Read()) { } } Assert.IsNotNull(doc); }