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>(); }