public async Task WriteNext_Writes() { using (MemoryStream ms = new MemoryStream()) using (StreamWriter sr = new StreamWriter(ms)) { TwentyThreeAndMeV5Writer writer = new TwentyThreeAndMeV5Writer(sr, FileFormat.MyHeritageV2); await writer.Begin(); await sr.FlushAsync(); await ms.FlushAsync(); var length = ms.Length; await writer.WriteNext(new SNP { Rsid = "123123", Chromosome = "1", Position = "123", Result = "GG" }); await sr.FlushAsync(); await ms.FlushAsync(); Assert.NotEqual(length, ms.Length); await writer.End(); } }
public async Task WriteAllAsync_Writes() { int records = 5; Mock <IFormatReader> reader = new Mock <IFormatReader>(); reader.SetupGet <bool>(x => x.EndOfFile).Returns(true); reader.When(() => records-- > 0).SetupGet <bool>(x => x.EndOfFile).Returns(false); reader.Setup(x => x.ReadNext()).ReturnsAsync(new SNP() { Rsid = "123123", Chromosome = "1", Position = "123", Result = "GG" }); using (MemoryStream ms = new MemoryStream()) using (StreamWriter sr = new StreamWriter(ms)) { TwentyThreeAndMeV5Writer writer = new TwentyThreeAndMeV5Writer(sr, FileFormat.MyHeritageV2); await writer.Begin(); await writer.WriteAllAsync(reader.Object); await writer.End(); ms.Seek(0, SeekOrigin.Begin); string content = Encoding.UTF8.GetString(ms.ToArray()); Assert.Contains("123123\t1\t123\tGG", content); } }
public async Task End_WritesNewLineToTheEnd() { using (MemoryStream ms = new MemoryStream()) using (StreamWriter sr = new StreamWriter(ms)) { TwentyThreeAndMeV5Writer writer = new TwentyThreeAndMeV5Writer(sr, FileFormat.MyHeritageV2); await writer.Begin(); await writer.End(); Assert.True(ms.Length > 0); ms.Seek(0, SeekOrigin.Begin); string content = Encoding.UTF8.GetString(ms.ToArray()); content.EndsWith(Environment.NewLine); } }
public async Task Begin_WritesHeaderToStream() { using (MemoryStream ms = new MemoryStream()) using (StreamWriter sr = new StreamWriter(ms)) { TwentyThreeAndMeV5Writer writer = new TwentyThreeAndMeV5Writer(sr, FileFormat.MyHeritageV2); await writer.Begin(); await sr.FlushAsync(); await ms.FlushAsync(); Assert.True(ms.Length > 0); ms.Seek(0, SeekOrigin.Begin); string header = Encoding.UTF8.GetString(ms.ToArray()); Assert.Contains("# This data file generated by DnaFormatConverter at:", header); await writer.End(); } }
public async Task WriteNext_ReturnsOnNullSNP() { using (MemoryStream ms = new MemoryStream()) using (StreamWriter sr = new StreamWriter(ms)) { TwentyThreeAndMeV5Writer writer = new TwentyThreeAndMeV5Writer(sr, FileFormat.MyHeritageV2); await writer.Begin(); await sr.FlushAsync(); await ms.FlushAsync(); var length = ms.Length; await writer.WriteNext(null); await sr.FlushAsync(); await ms.FlushAsync(); Assert.Equal(length, ms.Length); await writer.End(); } }