コード例 #1
0
        public void Position_Is_Updated_Correctly_During_Writes()
        {
            var count = 100;
            var ms = new ConcurrentStream(new MemoryStream());

            var validGuids = _GenerateCaptureService(count);

            var captureStream = new CaptureStream(ms, FileAccess.Write, _StateResolver);

            for (int i = 0; i < count; i++)
            {
                var mock = new Mock<ICaptureState>();
                mock.Setup(p => p.Guid).Returns(validGuids[i]);
                mock.Setup(p => p.Data).Returns(Guid.NewGuid().ToByteArray());

                captureStream.Write(mock.Object);
                Assert.Equal(i + 1, captureStream.Position);
            }
        }
コード例 #2
0
        public void CaptureStream_Supports_Writing_A_State_And_Then_Reading_It()
        {
            var stateController = new WeatherStateController(new WeatherSimulator());
            var stateResolver = new StateResolver();
            stateResolver.Add(stateController);

            var baseStream = new ConcurrentStream(new MemoryStream());
            var captureStream = new CaptureStream(baseStream, FileAccess.ReadWrite, stateResolver);

            Assert.True(captureStream.CanRead);
            Assert.True(captureStream.CanWrite);

            //write a state then read it back
            var expectedBytes = Guid.NewGuid().ToByteArray();

            captureStream.Write(new WeatherCaptureState(expectedBytes, stateController.Guid, DateTime.UtcNow, 0));

            //the read pointer is still at the start of the stream
            var readState = captureStream.Read();

            for (int i = 0; i < readState.Data.Length; i++)
            {
                Assert.Equal(expectedBytes[i], readState.Data[i]);
            }
        }