public void ReadTest_file_is_empty_gives_empty_Dataset() { DatasourceReader reader = new DatasourceReader(@"Testdata\Empty.csv"); reader.ReadFile(); Assert.AreEqual(0, reader.Count); }
public void ReadTest_no_file_gives_no_content() { DatasourceReader reader = new DatasourceReader(null); reader.ReadFile(); Assert.AreEqual(0, reader.Count); }
public void ReadTest_file_is_valid_gives_two_Correspondances() { DatasourceReader reader = new DatasourceReader(@"Testdata\ValidTwoRows.csv"); reader.ReadFile(); Assert.AreEqual(2, reader.Count); Assert.AreEqual("1001", reader[0].Reportee); Assert.AreEqual("1002", reader[1].Reportee); }
public void ReadTest_file_not_found_throws_exception() { DatasourceReader reader = new DatasourceReader(@"C:\tullball\data.csv"); DirectoryNotFoundException exception = null; try { reader.ReadFile(); } catch (DirectoryNotFoundException ex) { exception = ex; } Assert.IsNotNull(exception); }
/// <summary> /// Start of console application specific logic. /// </summary> protected override void Execute() { // This is where magic happens // Fetch datasett fra en kommaseparert fil, der hver linje er en correspondence DatasourceReader reader = new DatasourceReader(this.Arguments.SourceFile); reader.ReadFile(); Correspondences corrColl = new Correspondences() { SystemUserCode = ConfigurationManager.AppSettings["systemUserCode"], ShipmentReference = Guid.NewGuid().ToString(), SequenceNo = null, Correspondence = new CorrespondencesCorrespondence[reader.Count] }; int index = 0; // For datasettet lages en XML fil med alle correspence fra csv fila // systemUserCode hentes fra app.config foreach (CorrespondenceInput correspondence in reader.GetEnumerable()) { corrColl.Correspondence[index++] = new CorrespondencesCorrespondence() { Reportee = correspondence.Reportee, ServiceCode = this.Arguments.ServiceCode, ServiceEdition = this.Arguments.ServiceEdition, SendersReference = Guid.NewGuid().ToString(), Content = new CorrespondencesCorrespondenceContent() { LanguageCode = correspondence.LanguageCode, MessageTitle = correspondence.MessageTitle, MessageBody = correspondence.MessageBody, MessageSummary = correspondence.MessageSummary, }, VisibleDateTime = correspondence.VisibleDateTime, VisibleDateTimeSpecified = true, IsReservable = correspondence.IsReservable, IsReservableSpecified = true, }; } string destfolder = ConfigurationManager.AppSettings["localPathToFilesToUpload"]; string name = Path.GetFileName(this.Arguments.SourceFile); if (name == null) { return; } string fileName = name.Replace(".csv", ".xml"); string destfile = destfolder.Contains("*") ? destfolder.Replace("*", fileName) : Path.Combine(destfolder, fileName); // XML filene lagres på local path ihht konfigurasjonen localPathToFilesToUpload using (FileStream fileStream = File.Create(destfile)) { XmlSerializer serializer = new XmlSerializer(corrColl.GetType()); serializer.Serialize(fileStream, corrColl); } XmlValidator.Validate(destfile); try { SftpClientHelper.TransferFiles(); File.Delete(destfile); } catch (Exception) { throw; } }