public void TimeSectionValuesRoundTrip() { var ms = new MemoryStream(); var fio = new FileIO(ms); var fw = new FormattedWriter(fio); var wc = new WriteContext(fw); wc.Description = new TeaFileDescription(); wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >(); Time.Scale = Timescale.FromEpoch(33, 77); wc.Description.Timescale = Time.Scale; ISectionFormatter f = new TimeSectionFormatter(); f.Write(wc); ms.Position = 0; var fr = new FormattedReader(fio); var rc = new ReadContext(fr); rc.Description.Should().Not.Be.Null(); rc.Description.ItemDescription = wc.Description.ItemDescription; f.Read(rc); rc.Description.Timescale.Value.Epoch.Should().Be(33); rc.Description.Timescale.Value.TicksPerDay.Should().Be(77); Executing.This(() => f.Read(rc)).Should().Throw <EndOfStreamException>(); }
public void EventTimeAttributeRoundTrip() { Time.Scale = Timescale.Net; var ms = new MemoryStream(); var fio = new FileIO(ms); var fw = new FormattedWriter(fio); var wc = new WriteContext(fw); wc.Description = new TeaFileDescription(); wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >(); wc.Description.Timescale = Time.Scale; ISectionFormatter f = new TimeSectionFormatter(); f.Write(wc); ms.Position = 0; var fr = new FormattedReader(fio); var rc = new ReadContext(fr); rc.Description.Should().Not.Be.Null(); rc.Description.ItemDescription = wc.Description.ItemDescription; rc.Description.ItemDescription.Fields.ForEach(ff => ff.IsEventTime = ff.IsTime = false); // reset flags f.Read(rc); rc.Description.ItemDescription.Fields.Count(ff => ff.IsTime).Should().Be(1); rc.Description.ItemDescription.Fields.Count(ff => ff.IsEventTime).Should().Be(1); rc.Description.Timescale.Value.Epoch.Should().Be(0); rc.Description.Timescale.Value.TicksPerDay.Should().Be(TimeSpan.TicksPerDay); }
public void FirstTimeFieldIsAutomaticallyEventTime() { var ms = new MemoryStream(); var fio = new FileIO(ms); var fw = new FormattedWriter(fio); var wc = new WriteContext(fw); wc.Description = new TeaFileDescription(); wc.Description.ItemDescription = ItemDescription.FromAnalysis <C2>(); wc.Description.Timescale = Time.Scale; ISectionFormatter f = new TimeSectionFormatter(); f.Write(wc); ms.Position = 0; var fr = new FormattedReader(fio); var rc = new ReadContext(fr); rc.Description.Should().Not.Be.Null(); rc.Description.ItemDescription = ItemDescription.FromAnalysis <C2>(); f.Read(rc); var fields = rc.Description.ItemDescription.Fields; fields[0].IsEventTime.Should().Be.True(); fields[1].IsEventTime.Should().Be.False(); }
public void TimeSectionRoundTrip() { var ms = new MemoryStream(); var fio = new FileIO(ms); var fw = new FormattedWriter(fio); var wc = new WriteContext(fw); wc.Description = new TeaFileDescription(); wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >(); wc.Description.Timescale = Time.Scale; ISectionFormatter f = new TimeSectionFormatter(); f.Write(wc); ms.Position = 0; ms.Length.Should().Be(24); // epoch(8) ticksperday(8) fieldcount(4) + timefieldoffset(4) = 24 var fr = new FormattedReader(fio); var rc = new ReadContext(fr); rc.Description.Should().Not.Be.Null(); rc.Description.ItemDescription = wc.Description.ItemDescription; // this makes the test a bit weaker, but we need some item description here f.Read(rc); rc.Description.Should().Not.Be.Null(); rc.Description.Timescale.HasValue.Should().Be.True(); }
public void ItemSectionRoundTrip() { var ms = new MemoryStream(); var fio = new FileIO(ms); var fw = new FormattedWriter(fio); var wc = new WriteContext(fw); wc.Description = new TeaFileDescription(); var writeID = wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <OHLCV> >(); ISectionFormatter f = new ItemSectionFormatter(); f.Write(wc); ms.Position = 0; var fr = new FormattedReader(fio); var rc = new ReadContext(fr); rc.Description.Should().Not.Be.Null(); f.Read(rc); rc.Description.Should().Not.Be.Null(); var id = rc.Description.ItemDescription; id.ItemTypeName.Should().Be(typeof(Event <OHLCV>).GetLanguageName()); id.ItemSize.Should().Be(wc.Description.ItemDescription.ItemSize); id.Fields.Select(ff => ff.Name).Should().Have.SameValuesAs("Time", "Open", "High", "Low", "Close", "Volume"); id.Fields.Select(ff => ff.Index).Should().Have.SameValuesAs(0, 1, 2, 3, 4, 5); id.Fields.Select(ff => ff.FieldType).Should().Have.SameValuesAs(FieldType.Int64, FieldType.Double, FieldType.Double, FieldType.Double, FieldType.Double); id.Fields.Select(ff => ff.Offset).Should().Have.SameValuesAs(writeID.Fields.Select(ff => ff.Offset)); ms.Position.Should().Be(ms.Length); // very important, all bytes must have been read }
public void TimeSectionRoundTripFieldIsNotInItemDescriptionError() { var ms = new MemoryStream(); var fio = new FileIO(ms); var fw = new FormattedWriter(fio); var wc = new WriteContext(fw); wc.Description = new TeaFileDescription(); wc.Description.ItemDescription = ItemDescription.FromAnalysis <Event <C> >(); wc.Description.Timescale = Time.Scale; ISectionFormatter f = new TimeSectionFormatter(); f.Write(wc); ms.Position = 0; var fr = new FormattedReader(fio); var rc = new ReadContext(fr); rc.Description.Should().Not.Be.Null(); rc.Description.ItemDescription = ItemDescription.FromAnalysis <C2>(); Executing.This(() => f.Read(rc)).Should().Throw <FileFormatException>(); }