Beispiel #1
0
        public void FSS005()
        {
            // arrange
            var fixture      = new Fixture();
            var sessionKey   = fixture.Create <string>();
            var path         = fixture.Create <string>();
            var expectedPath = Path.Combine(path, sessionKey);

            var sessionStateSerializer = new BinarySessionStateSerializer();
            var sessionState           = new Dictionary <string, object>();

            var directoryMock = new Mock <IDirectory>();

            directoryMock.Setup(m => m.Exists(path))
            .Returns(true);

            var fileMock = new Mock <IFile>();
            var storage  = new FileSessionStorage(directoryMock.Object, fileMock.Object, sessionStateSerializer, path);

            // act
            storage.Save(sessionKey, sessionState);

            // assert
            directoryMock.Verify(m => m.Create(path), Times.Never);
        }
Beispiel #2
0
        public void FSS003()
        {
            // arrange
            var fixture      = new Fixture();
            var sessionKey   = fixture.Create <string>();
            var path         = fixture.Create <string>();
            var expectedPath = Path.Combine(path, sessionKey);

            var sessionStateSerializer = new BinarySessionStateSerializer();
            var sessionState           = new Dictionary <string, object>()
            {
                { "one", 1 }
            };
            var serializedSessionState = sessionStateSerializer.Serialize(sessionState);

            var directoryMock = new Mock <IDirectory>();

            var fileMock = new Mock <IFile>();

            fileMock
            .Setup(m => m.Exists(expectedPath))
            .Returns(true);

            fileMock
            .Setup(m => m.WriteAllBytes(expectedPath, It.IsAny <byte[]>()))
            .Callback <string, byte[]>((sessionKey, bytes) => serializedSessionState = bytes);

            var storage = new FileSessionStorage(directoryMock.Object, fileMock.Object, sessionStateSerializer, path);

            // act
            storage.Save(sessionKey, sessionState);

            // assert
            fileMock.Verify(m => m.WriteAllBytes(expectedPath, It.IsAny <byte[]>()), Times.Once);


            var expectedSessionState = new Dictionary <string, object>()
            {
                { "one", 1 },
            };

            var deserializedSessionState = sessionStateSerializer.Deserialize(serializedSessionState);

            deserializedSessionState.Should().BeEquivalentTo(expectedSessionState);
        }