Exemple #1
0
        public void GetNextLine_MultiSources_CorrectDataReturned()
        {
            //arrange
            var streams   = new MemoryStream[] { _x12StreamWOLines, _x12StreamLineAsDelimiter, _x12StreamWithLines };
            var feeder    = LineFeederCreator.CreateLineFeeder(streams.Select(s => new StreamReader(s, Encoding.UTF8)), KindOfTextData.X12, false, false, "*", null); //segment delimiter can be anything, but null here
            var tuplesFed = new List <Tuple <ExternalLine, int> >();

            //act
            var tupleFed = feeder.GetNextLine();

            while (tupleFed != null)
            {
                tuplesFed.Add(tupleFed);
                tupleFed = feeder.GetNextLine();
            }

            //assert
            feeder.Should().BeOfType <LineFeeder>();
            tuplesFed.Count.Should().Be(100); // 17 + 37 + 46
            tuplesFed[0].Item1.Text.Should().Be("ISA*00*          *00*          *ZZ*AV09311993     *01*030240928      *031023*1758*U*00401*557988899*1*T*:~");
            tuplesFed[0].Item2.Should().Be(1);
            tuplesFed[16].Item1.Text.Should().Be("IEA*1*557988899");
            tuplesFed[16].Item2.Should().Be(1);
            tuplesFed[17].Item1.Text.Should().Be("ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>\r");
            tuplesFed[17].Item2.Should().Be(2);
            tuplesFed[53].Item1.Text.Should().Be("IEA*1*000003438");
            tuplesFed[53].Item2.Should().Be(2);
            tuplesFed[54].Item1.Text.Should().Be("ISA*00*          *01*SECRET    *ZZ*SUBMITTERS.ID  *ZZ*RECEIVERS.ID   *030101*1253*^*00501*000000905*1*T*:~");
            tuplesFed[54].Item2.Should().Be(3);
            tuplesFed[99].Item1.Text.Should().Be("IEA*1*000000905");
            tuplesFed[99].Item2.Should().Be(3);
        }
        public void GetNextLine_ThreeSources_CorrectDataReturned()
        {
            //arrange
            var streams = new MemoryStream[] { _firstStream, _secondStream, _thirdStream };
            var feeder  = LineFeederCreator.CreateLineFeeder(streams.Select(s => new StreamReader(s, Encoding.UTF8)), KindOfTextData.Raw, false, false, null, null);

            //act
            var first    = feeder.GetNextLine();
            var second   = feeder.GetNextLine();
            var third    = feeder.GetNextLine();
            var fourth   = feeder.GetNextLine();
            var fifth    = feeder.GetNextLine();
            var sixth    = feeder.GetNextLine();
            var seventh  = feeder.GetNextLine();
            var eighth   = feeder.GetNextLine();
            var ninth    = feeder.GetNextLine();
            var tenth    = feeder.GetNextLine();
            var eleventh = feeder.GetNextLine();

            //assert
            feeder.Should().BeOfType <LineFeeder>();
            first.Item1.Text.Should().Be("First of First");
            first.Item2.Should().Be(1);
            second.Item1.Text.Should().Be("Second of First");
            second.Item2.Should().Be(1);
            third.Item1.Text.Should().Be("Third of First");
            third.Item2.Should().Be(1);
            fourth.Item1.Text.Should().Be("First of Second");
            fourth.Item2.Should().Be(2);
            fifth.Item1.Text.Should().Be("Second of Second");
            fifth.Item2.Should().Be(2);
            sixth.Item1.Text.Should().Be("First of Third");
            sixth.Item2.Should().Be(3);
            seventh.Item1.Text.Should().Be("Second of Third");
            seventh.Item2.Should().Be(3);
            eighth.Item1.Text.Should().Be("Third of Third");
            eighth.Item2.Should().Be(3);
            ninth.Item1.Text.Should().Be("Fourth of Third");
            ninth.Item2.Should().Be(3);
            tenth.Should().BeNull();
            eleventh.Should().BeNull();
        }
        public void GetNextLineAsync_TwoLinerAsEnumerableSynced_CorrectDataReturned()
        {
            // Note that this test actually creates LineFeeder (with a single constituent LineFeederForSource)

            //arrange
            var feeder = LineFeederCreator.CreateLineFeeder(Enumerable.Repeat(new StreamReader(_twoLinerStream, Encoding.UTF8), 1), KindOfTextData.Raw, false, false, null, null);

            //act
            var first  = feeder.GetNextLineSynced();
            var second = feeder.GetNextLineSynced();
            var third  = feeder.GetNextLineSynced();
            var fourth = feeder.GetNextLineSynced();

            //assert
            feeder.Should().BeOfType <LineFeeder>();
            first.Item1.Text.Should().Be("First Line");
            first.Item2.Should().Be(1);
            second.Item1.Text.Should().Be("Second Line");
            second.Item2.Should().Be(1);
            third.Should().BeNull();
            fourth.Should().BeNull();
        }