public static void Develop() { String fileNameString = "in.txt"; { FileIOPermission f = new FileIOPermission(PermissionState.None); f.AllFiles = FileIOPermissionAccess.Write; f.Demand(); } { if (File.Exists(fileNameString)) { File.Delete(fileNameString); } } Stream stream = new FileStream(fileNameString, FileMode.CreateNew, FileAccess.ReadWrite); if (true) { IBeepingWriter writer = new BeepingWriter(stream); for (int i = 1; i < 10; i++) { writer.WriteBeep(new Beep((ushort)(3144 - 3100 / i), 100)); } } if (true) { IBeepingReader reader = new BeepingReader(stream); var beeps = reader.ReadBeeps(); } }
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 ); }
public void Play(IEnumerable <Beep> beeps) { Stream stream = new MemoryStream(); IBeeper beeper = new ConsoleBeeper(); IBeepStreamWriter streamWriter = new BeepStreamWriter(); IBeepingWriter writer = new BeepingWriter(stream, beeper, streamWriter); writer.WriteBeeps(beeps); stream.Dispose(); }
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); } ); }
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) ); }
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 ); }