コード例 #1
0
        public void WriteBytes_causes_stream_to_be_created_but_only_on_first_call()
        {
            var createCalls = 0;

              var lazyStreamByteWriter = new LazyStreamByteWriter(delegate
              {
            ++createCalls;
            return null;
              });

              Assert.AreEqual(0, createCalls);

              lazyStreamByteWriter.WriteBytes(new byte[] {1});

              Assert.AreEqual(1, createCalls);

              lazyStreamByteWriter.WriteBytes(new byte[] {1});

              // Second call doesn't attempt to create stream
              Assert.AreEqual(1, createCalls);
        }
コード例 #2
0
        public void WriteBytes_does_not_create_stream_if_passed_null_bytes()
        {
            var createCalls = 0;

              var lazyStreamByteWriter = new LazyStreamByteWriter(delegate
              {
            ++createCalls;
            return null;
              });

              Assert.AreEqual(0, createCalls);

              lazyStreamByteWriter.WriteBytes(null);

              Assert.AreEqual(0, createCalls);
        }
コード例 #3
0
        public void WriteBytes_writes_then_flushes_stream()
        {
            var stream = Substitute.For<Stream>();
              var lazyStreamByteWriter = new LazyStreamByteWriter(() => stream);

              var bytes = new byte[] {1, 2, 3};
              lazyStreamByteWriter.WriteBytes(bytes);

              stream.Received(1).Write(bytes, 0, bytes.Length);
              stream.Received(1).Flush();
        }