public async Task TestFundingSummaryPeriodEndReportGeneration() { string csv = string.Empty; DateTime dateTime = DateTime.UtcNow; string filename = $"10036143_1_Funding Summary Report {dateTime:yyyyMMdd-HHmmss}"; Mock <IReportServiceContext> reportServiceContextMock = new Mock <IReportServiceContext>(); reportServiceContextMock.SetupGet(x => x.JobId).Returns(1); reportServiceContextMock.SetupGet(x => x.SubmissionDateTimeUtc).Returns(DateTime.UtcNow); reportServiceContextMock.SetupGet(x => x.Ukprn).Returns(10036143); Mock <ILogger> logger = new Mock <ILogger>(); Mock <IDateTimeProvider> dateTimeProviderMock = new Mock <IDateTimeProvider>(); Mock <IStreamableKeyValuePersistenceService> storage = new Mock <IStreamableKeyValuePersistenceService>(); IValueProvider valueProvider = new ValueProvider(); ITopicAndTaskSectionOptions topicsAndTasks = TestConfigurationHelper.GetTopicsAndTasks(); storage.Setup(x => x.SaveAsync($"{filename}.csv", It.IsAny <string>(), It.IsAny <CancellationToken>())).Callback <string, string, CancellationToken>((key, value, ct) => csv = value).Returns(Task.CompletedTask); IIntUtilitiesService intUtilitiesService = new IntUtilitiesService(); IJsonSerializationService jsonSerializationService = new JsonSerializationService(); IXmlSerializationService xmlSerializationService = new XmlSerializationService(); DataStoreConfiguration dataStoreConfiguration = new DataStoreConfiguration() { ILRDataStoreConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreConnectionString, ILRDataStoreValidConnectionString = new TestConfigurationHelper().GetSectionValues <DataStoreConfiguration>("DataStoreSection").ILRDataStoreValidConnectionString }; IIlr1819ValidContext IlrValidContextFactory() { var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntitiesValid>().UseSqlServer(dataStoreConfiguration.ILRDataStoreValidConnectionString).Options; return(new ILR1819_DataStoreEntitiesValid(options)); } IIlr1819RulebaseContext IlrRulebaseValidContextFactory() { var options = new DbContextOptionsBuilder <ILR1819_DataStoreEntities>().UseSqlServer(dataStoreConfiguration.ILRDataStoreConnectionString).Options; return(new ILR1819_DataStoreEntities(options)); } IIlrProviderService ilrProviderService = new IlrProviderService(logger.Object, storage.Object, xmlSerializationService, dateTimeProviderMock.Object, intUtilitiesService, IlrValidContextFactory, IlrRulebaseValidContextFactory); IFM36ProviderService fm36ProviderService = new FM36ProviderService(logger.Object, storage.Object, jsonSerializationService, intUtilitiesService, IlrRulebaseValidContextFactory); IStringUtilitiesService stringUtilitiesService = new StringUtilitiesService(); dateTimeProviderMock.Setup(x => x.GetNowUtc()).Returns(dateTime); dateTimeProviderMock.Setup(x => x.ConvertUtcToUk(It.IsAny <DateTime>())).Returns(dateTime); var fundingSummaryPeriodEndModelBuilder = new FundingSummaryPeriodEndModelBuilder(); var report = new ReportService.Service.Reports.PeriodEnd.FundingSummaryPeriodEndReport(logger.Object, storage.Object, ilrProviderService, fm36ProviderService, stringUtilitiesService, dateTimeProviderMock.Object, valueProvider, topicsAndTasks, fundingSummaryPeriodEndModelBuilder); await report.GenerateReport(reportServiceContextMock.Object, null, false, CancellationToken.None); csv.Should().NotBeNullOrEmpty(); File.WriteAllText($"{filename}.csv", csv); TestCsvHelper.CheckCsv(csv, new CsvEntry(new FundingSummaryPeriodEndMapper(), 1)); }
public void ShouldSerializeObject() { var serializationService = new XmlSerializationService(); var pack = fixture.Create <Pack>(); string generatedXml = serializationService.Serialize(pack); string packInXmlFormat = string.Format(XmlPackFormat, pack.Guid, pack.Id, pack.Type, pack.Url); Assert.AreEqual(packInXmlFormat, generatedXml); }
public void ShouldDeserializeObject() { var serizalizationService = new XmlSerializationService(); var pack = fixture.Create <Pack>(); string xml = string.Format(XmlPackFormat, pack.Guid, pack.Id, pack.Type, pack.Url); Pack generatedPack = serizalizationService.Deserialize <Pack>(xml); Assert.AreEqual(pack.Id, generatedPack.Id); Assert.AreEqual(pack.Guid, generatedPack.Guid); Assert.AreEqual(pack.Type, generatedPack.Type); Assert.AreEqual(pack.Url, generatedPack.Url); }
public void spawning_CanDeserialize() { //Arrange var pathToXml = @"../../TestData/spawning.xml"; var xmlSerializationService = new XmlSerializationService(); var generalFileService = new LocalFileService(); //Act var xml = generalFileService.Get(pathToXml); var spawning = xmlSerializationService.Deserialize <spawning>(xml.Value).Value; //Assert Assert.IsNotNull(spawning); Assert.IsTrue(spawning.Items.Length > 0); }
public void gamestages_CanDeserialize() { //Arrange var pathToXml = @"../../TestData/gamestages.xml"; var xmlSerializationService = new XmlSerializationService(); var generalFileService = new LocalFileService(); //Act var xml = generalFileService.Get(pathToXml); var gameStages = xmlSerializationService.Deserialize <gamestages>(xml.Value).Value; //Assert Assert.IsNotNull(gameStages); Assert.IsTrue(gameStages.Items.Length > 0); }
public void entitygroups_CanDeserialize() { //Arrange var pathToXml = @"../../TestData/entitygroups.xml"; var xmlSerializationService = new XmlSerializationService(); var generalFileService = new LocalFileService(); //Act var xml = generalFileService.Get(pathToXml); var entityGroups = xmlSerializationService.Deserialize <entitygroups>(xml.Value).Value; //Assert Assert.IsNotNull(entityGroups); Assert.IsTrue(entityGroups.Items.Length > 0); }
public void entityclasses_CanDeserialize() { //Arrange var pathToXml = @"../../TestData/entityclasses.xml"; var xmlSerializationService = new XmlSerializationService(); var generalFileService = new LocalFileService(); //Act var xml = generalFileService.Get(pathToXml); var entityClasses = xmlSerializationService.Deserialize <entity_classes>(xml.Value).Value; //Serialize(entityClasses, @"C:\Users\Nate\Desktop\entityclassestest.xml"); //Assert Assert.IsNotNull(entityClasses); Assert.IsTrue(entityClasses.Items.Length > 0); }
public void WriteXml(XmlWriter writer) { var xmlSerializer = new XmlSerializationService(); writer.WriteAttributeString("id", Identifier); if (Data != null) { writer.WriteStartElement("wps", "Data", ModelNamespaces.Wps); if (!string.IsNullOrEmpty(MimeType)) { writer.WriteAttributeString("mimeType", MimeType); } if (!string.IsNullOrEmpty(Encoding)) { writer.WriteAttributeString("encoding", Encoding); } if (!string.IsNullOrEmpty(Schema)) { writer.WriteAttributeString("schema", Schema); } if (Data is string s) { writer.WriteRaw(s); } else { writer.WriteRaw(xmlSerializer.Serialize(Data, true)); } writer.WriteEndElement(); } if (Reference != null) { writer.WriteRaw(xmlSerializer.Serialize(Reference, true)); } if (Inputs != null) { foreach (var input in Inputs) { writer.WriteRaw(xmlSerializer.Serialize(input, true)); } } }
private static IMessage GetMessageFromFile(string fileName) { System.Console.WriteLine("Loading file.."); using (var stream = new FileStream(@"Files\" + fileName, FileMode.Open)) { try { IXmlSerializationService serializationService = new XmlSerializationService(); return(serializationService.Deserialize <Message>(stream)); } catch (Exception ex) { System.Console.WriteLine("File Load Error: Problem loading file... {0}", ex); throw; } } }
static void Main(string[] args) { Product product = new Product("name", "1", new DateTime(2018, 10, 07), 90); Product product1 = new Product("name", "1", new DateTime(2018, 10, 07), 90); Product product2 = new Product("name", "1", new DateTime(2018, 10, 07), 90); List <Product> products = new List <Product> { product, product1, product2 }; string filePath = @"C:\Progbase\Study\Term3\Lab3\Products.xml"; // пример вызова XmlSerializationService <List <Product> > xmlSerializerService = new XmlSerializationService <List <Product> >(); xmlSerializerService.Write(products, filePath, FileMode.Truncate); //Product newProduct = xmlSerializerService.Read(filePath, FileMode.Open); //Console.WriteLine(newProduct.Name); //Console.WriteLine(newProduct.Id); //Console.WriteLine(newProduct.DateOfManufacture); //Console.WriteLine(newProduct.Lifetime); //Console.WriteLine(newProduct.ExpirationDate); }
public static async Task <ValCurs> LoadValCursAsync(DateTime dateTime = default(DateTime)) { if (dateTime == default(DateTime)) { dateTime = DateTimeZones.NowMoscow; } var url = $"{UrlTemplate}{dateTime.ToString(DateFormat)}"; using (var client = new HttpClient()) { var response = await client.GetAsync(url); response.EnsureSuccessStatusCode(); // throw an exception if possible var data = await response.Content.ReadAsStreamAsync(); using (data) { return(await XmlSerializationService.Deserialize <ValCurs>(data)); } } }
public void ReadXml(XmlReader reader) { var serializer = new XmlSerializationService(); Code = reader.GetAttribute("exceptionCode"); Locator = reader.GetAttribute("locator"); var subtreeReader = reader.ReadSubtree(); subtreeReader.MoveToContent(); while (subtreeReader.Read()) { if (subtreeReader.NodeType == XmlNodeType.Element) { if (subtreeReader.LocalName.Equals("ExceptionText")) { _message = subtreeReader.ReadElementContentAsString(); } } } reader.Skip(); }