public async Task WriteAsync(I06Output output) { var fileContents = output.XmlSerialize(); await _fileSystem.File.WriteAllTextAsync( Path.Combine(FileDirectory, $"Dukteriniu importas - {DateTime.Now:yyyy-MM-dd hh_mm_ss}.eip"), fileContents); }
public static string XmlSerialize(this I06Output data) { var emptyNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); var settings = new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true }; using var stringWriter = new StringWriter(); using var xmlWriter = XmlWriter.Create(stringWriter, settings); var serializer = new XmlSerializer(typeof(I06Output)); serializer.Serialize(xmlWriter, data, emptyNamespaces); return(stringWriter.ToString()); }
public async Task WhenXmlSerializing_OpenCloseTagsAreCreatedForEmptyFields() { //Arrange var fileSystemMoq = new Mock <IFileSystem>(); fileSystemMoq.Setup(f => f.File.ReadAllLinesAsync(It.IsAny <string>(), It.IsAny <Encoding>(), default)) .Returns(() => Task.FromResult(EipTestDataWithEmptyFields.Split(Environment.NewLine))); var logger = Mock.Of <ILogger>(); var eipReader = new EipReader(fileSystemMoq.Object, logger); var products = (await eipReader.GetParsedEipContentsAsync("dummy.txt")).ToArray(); var resultData = new I06Output(products.Select(p => new I07Output(p)).ToArray()); //Act var xmlString = resultData.XmlSerialize(); //Assert Assert.Contains("<DIM_01> </DIM_01>", xmlString); Assert.Contains("<I07_APRASYMAS1> </I07_APRASYMAS1>", xmlString); Assert.Contains("<I07_APRASYMAS2> </I07_APRASYMAS2>", xmlString); Assert.Contains("<I07_APRASYMAS3> </I07_APRASYMAS3>", xmlString); }