public void FSS008() { // arrange var fixture = new Fixture(); var sessionKeys = fixture.CreateMany <string>(); var path = fixture.Create <string>(); var filePaths = sessionKeys .Select(sessionKey => Path.Combine(path, sessionKey)) .ToList(); var sessionStateSerializer = new BinarySessionStateSerializer(); var sessionState = new Dictionary <string, object>(); var directoryMock = new Mock <IDirectory>(); directoryMock .Setup(m => m.Exists(path)) .Returns(true); directoryMock .Setup(m => m.GetFileNames(path)) .Returns(filePaths); var fileMock = new Mock <IFile>(); var storage = new FileSessionStorage(directoryMock.Object, fileMock.Object, sessionStateSerializer, path); // act var storedSessions = storage.StoredSessions; // assert storedSessions.Should().BeEquivalentTo(sessionKeys); }
public void FSS007() { // arrange var fixture = new Fixture(); var sessionKey = fixture.Create <string>(); var path = fixture.Create <string>(); var filePath = Path.Combine(path, sessionKey); var sessionStateSerializer = new BinarySessionStateSerializer(); var sessionState = new Dictionary <string, object>(); var directoryMock = new Mock <IDirectory>(); var fileMock = new Mock <IFile>(); fileMock.Setup(m => m.Exists(filePath)) .Returns(false); var storage = new FileSessionStorage(directoryMock.Object, fileMock.Object, sessionStateSerializer, path); // act storage.Delete(sessionKey); // assert fileMock.Verify(m => m.Delete(filePath), Times.Never); }
public void FSS001() { // 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 directoryMock = new Mock <IDirectory>(); var fileMock = new Mock <IFile>(); fileMock .Setup(m => m.Exists(expectedPath)) .Returns(false); var storage = new FileSessionStorage(directoryMock.Object, fileMock.Object, sessionStateSerializer, path); // act var sessionState = storage.Load(sessionKey); // assert sessionState.Should().NotBeNull(); sessionState.Count.Should().Be(0); fileMock.Verify(m => m.Exists(expectedPath), Times.Once); }
public void BSSS001() { // arrange var sessionState = new Dictionary <string, object>() { { "one", "value one" }, { "two", 2.0 } }; var serializer = new BinarySessionStateSerializer(); // act var bytes = serializer.Serialize(sessionState); var sessionStateFromBytes = serializer.Deserialize(bytes); // verify var expectedSessionState = new Dictionary <string, object>() { { "one", "value one" }, { "two", 2.0 } }; sessionStateFromBytes.Should().BeEquivalentTo(expectedSessionState); }
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); }
public void SSP001() { // arrange var sessionState = new Dictionary <string, object>() { { "one", 1 } }; var sessionSerializer = new BinarySessionStateSerializer(); var sessionStateProtector = new SessionStateProtector(sessionSerializer); var protectedSessionState = sessionStateProtector.Serialize(sessionState); Action action = () => sessionSerializer.Deserialize(protectedSessionState); // act, assert action.Should().Throw <System.Runtime.Serialization.SerializationException>(); }
public void FSS002() { // 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.ReadAllBytes(expectedPath)) .Returns(serializedSessionState); var storage = new FileSessionStorage(directoryMock.Object, fileMock.Object, sessionStateSerializer, path); // act var loadedSessionState = storage.Load(sessionKey); // assert loadedSessionState.Should().NotBeNull(); loadedSessionState.Should().BeEquivalentTo(sessionState); fileMock.Verify(m => m.Exists(expectedPath), Times.Once); fileMock.Verify(m => m.ReadAllBytes(expectedPath), Times.Once); }
public void SSP002() { // arrange var sessionState = new Dictionary <string, object>() { { "one", 1 } }; var sessionSerializer = new BinarySessionStateSerializer(); var sessionStateProtector = new SessionStateProtector(sessionSerializer); var protectedSessionState = sessionStateProtector.Serialize(sessionState); // act var deserializedSessionState = sessionStateProtector.Deserialize(protectedSessionState); // assert var expectedSessionState = new Dictionary <string, object>() { { "one", 1 } }; deserializedSessionState.Should().BeEquivalentTo(expectedSessionState); }