コード例 #1
0
        public void WriteBeeps_WriteBeeps_PositionAreEqual8()
        {
            Stream            stream       = new MemoryStream();
            IBeeper           beeper       = new StubConsoleBeeper();
            IBeepStreamWriter streamWriter = new BeepStreamWriter();
            IBeepingWriter    writer       = new BeepingWriter(
                stream,
                beeper,
                streamWriter
                );
            IEnumerable <Beep> beeps = new List <Beep>
            {
                new Beep(
                    38,
                    13
                    ),
                new Beep(
                    42,
                    69
                    )
            };

            writer.WriteBeeps(beeps);

            Assert.AreEqual(
                8,
                stream.Position
                );
        }
コード例 #2
0
        public void ReadBeep_ReadEmptyStream_ReadedBeepIsNull()
        {
            Stream            stream       = new MemoryStream();
            IBeeper           beeper       = new StubConsoleBeeper();
            IBeepStreamReader streamReader = new BeepStreamReader();
            IBeepingReader    reader       = new BeepingReader(
                stream,
                beeper,
                streamReader
                );

            var beep = reader.ReadBeep();

            Assert.IsNull(beep);
        }
コード例 #3
0
        public void WriteBeep_WriteNullBeep_ThrowNullReferenceException()
        {
            Stream            stream       = new MemoryStream();
            IBeeper           beeper       = new StubConsoleBeeper();
            IBeepStreamWriter streamWriter = new BeepStreamWriter();
            IBeepingWriter    writer       = new BeepingWriter(
                stream,
                beeper,
                streamWriter
                );

            Assert.ThrowsException <NullReferenceException>(
                () => {
                writer.WriteBeep(null);
            }
                );
        }
コード例 #4
0
        public void ReadBeep_ReadNormalBeep_WritedBeepAreEqualReadedBeep()
        {
            String fileName = "test.txt";
            {
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
            }
            Beep beep = new Beep(
                40,
                133
                );
            Stream stream = new FileStream(
                fileName,
                FileMode.CreateNew
                );
            {
                IBeepStreamWriter streamWriter = new BeepStreamWriter();

                streamWriter.WriteBeep(
                    stream,
                    beep
                    );
            }
            IBeeper           beeper       = new StubConsoleBeeper();
            IBeepStreamReader streamReader = new BeepStreamReader();
            IBeepingReader    reader       = new BeepingReader(
                stream,
                beeper,
                streamReader
                );

            Beep readedBeep = reader.ReadBeep();

            Assert.AreEqual <Beep>(
                beep,
                readedBeep
                );
        }
コード例 #5
0
        public void ReadBeeps_ReadSomeBeeps_BeepsAreEqual()
        {
            IEnumerable <Beep> beeps = new List <Beep>()
            {
                new Beep(
                    42,
                    133
                    ),
                new Beep(
                    666,
                    133
                    )
            };
            Stream  stream = new MemoryStream();
            IBeeper beeper = new StubConsoleBeeper();
            {
                IBeepStreamWriter streamWriter = new BeepStreamWriter();
                IBeepingWriter    writer       = new BeepingWriter(
                    stream,
                    beeper,
                    streamWriter
                    );

                writer.WriteBeeps(beeps);
            }
            IBeepStreamReader streamReader = new BeepStreamReader();
            IBeepingReader    reader       = new BeepingReader(
                stream,
                beeper,
                streamReader
                );

            IEnumerable <Beep> readedBeeps = reader.ReadBeeps();


            Assert.IsTrue(
                beeps.SequenceEqual(readedBeeps)
                );
        }
コード例 #6
0
        public void WriteBeep_WriteSomeBeep_PositionAreEqualTo4()
        {
            Stream            stream       = new MemoryStream();
            IBeeper           beeper       = new StubConsoleBeeper();
            IBeepStreamWriter streamWriter = new BeepStreamWriter();
            IBeepingWriter    writer       = new BeepingWriter(
                stream,
                beeper,
                streamWriter
                );

            writer.WriteBeep(
                new Beep(
                    40,
                    200
                    )
                );

            Assert.AreEqual(
                4,
                stream.Position
                );
        }