Beispiel #1
0
        public void ReadPassThrough()
        {
            var stream = MockRepository.GenerateStrictMock <Stream>();

            byte[] buffer = new byte[1];
            stream.Expect(s => s.Read(buffer, 0, 1)).Repeat.Once().Return(42);
            var channelStream = new ChannelStream(stream);
            var returned      = channelStream.Read(buffer, 0, 1);

            Assert.AreEqual(42, returned);
            stream.VerifyAllExpectations();
        }
Beispiel #2
0
        public void ReadFailureThrowsChannelFaultedException(Type exceptionType)
        {
            var stream = MockRepository.GenerateStub <Stream>();

            stream.Stub(s => s.Read(null, 0, 0))
            .IgnoreArguments()
            .Throw(Activator.CreateInstance(exceptionType, string.Empty) as Exception);

            var channelStream = new ChannelStream(stream);
            var buffer        = new byte[1];

            Assert.That(() => { channelStream.Read(buffer, 0, 1); },
                        Throws.Exception.TypeOf <ChannelFaultedException>());
        }