public void DeserializeThrowsIfSerializedValueIsEmpty() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Assert.ThrowsArgumentNullOrEmpty( delegate { serializer.Deserialize("", SerializationMode.Signed); }, "serializedValue"); }
public void DeserializeThrowsIfSerializedValueIsEmpty() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Assert.ThrowsArgumentNullOrEmpty( delegate { serializer.Deserialize(""); }, "serializedValue"); }
public void DeserializeThrowsIfSerializedValueIsNull() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Assert.ThrowsArgumentNullOrEmpty( delegate { serializer.Deserialize(null); }, "serializedValue"); }
public void DeserializeThrowsIfSerializedValueIsNull() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Assert.ThrowsArgumentNullOrEmpty( delegate { serializer.Deserialize(null, SerializationMode.Signed); }, "serializedValue"); }
public void SerializeAllowsNullValues() { // Arrange IMachineKey machineKey = new MockMachineKey(); // Act string serializedValue = MvcSerializer.Serialize(null, SerializationMode.EncryptedAndSigned, machineKey); // Assert Assert.AreEqual(@"All-LPgGI1dzEbp3B2FueVR5cGUuA25pbIYJAXozaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS8yMDAzLzEwL1NlcmlhbGl6YXRpb24vCQFpKWh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlAQ==", serializedValue); }
public void DeserializeThrowsIfSerializedValueIsNull() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert ExceptionHelper.ExpectArgumentExceptionNullOrEmpty( delegate { serializer.Deserialize(null, SerializationMode.Signed); }, "serializedValue"); }
public void SerializeAllowsNullValues() { // Arrange IMachineKey machineKey = new MockMachineKey(); // Act string serializedValue = MvcSerializer.Serialize(null, machineKey); // Assert Assert.Equal(@"Microsoft.Web.Mvc.MvcSerializer.v1-dwdhbnlUeXBlLgNuaWyGCQF6M2h0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vMjAwMy8xMC9TZXJpYWxpemF0aW9uLwkBaSlodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZQE=", serializedValue); }
public void DeserializeThrowsIfModeIsOutOfRange() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Assert.ThrowsArgumentOutOfRange( delegate { serializer.Serialize("blah", (SerializationMode)(-1)); }, "mode", @"The provided SerializationMode is invalid."); }
public void SerializeAllowsNullValues() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act string serializedValue = serializer.Serialize(null, SerializationMode.Plaintext); // Assert Assert.AreEqual(@"/wFk", serializedValue); }
public void SerializeThrowsIfModeIsOutOfRange() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Assert.ThrowsArgumentOutOfRange( delegate { serializer.Serialize(null, (SerializationMode)(-1)); }, "mode", @"The provided SerializationMode is invalid."); }
public void SerializeAndDeserializeRoundTripsValue() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act string serializedValue = serializer.Serialize(42, SerializationMode.Plaintext); object deserializedValue = serializer.Deserialize(serializedValue, SerializationMode.Plaintext); // Assert Assert.AreEqual(42, deserializedValue, "Value was not round-tripped properly."); }
public void SerializeAndDeserializeRoundTripsValue() { // Arrange IMachineKey machineKey = new MockMachineKey(); // Act string serializedValue = MvcSerializer.Serialize(42, SerializationMode.EncryptedAndSigned, machineKey); object deserializedValue = MvcSerializer.Deserialize(serializedValue, SerializationMode.EncryptedAndSigned, machineKey); // Assert Assert.AreEqual(42, deserializedValue, "Value was not round-tripped properly."); }
public void SerializeAndDeserializeRoundTripsValue() { // Arrange IMachineKey machineKey = new MockMachineKey(); // Act string serializedValue = MvcSerializer.Serialize(42, machineKey); object deserializedValue = MvcSerializer.Deserialize(serializedValue, machineKey); // Assert Assert.Equal(42, deserializedValue); }
public void DeserializeThrowsIfSerializedValueIsCorrupt() { // Arrange IMachineKey machineKey = new MockMachineKey(); // Act & assert Exception exception = Assert.Throws <SerializationException>( delegate { MvcSerializer.Deserialize("This is a corrupted value.", machineKey); }, @"Deserialization failed. Verify that the data is being deserialized using the same SerializationMode with which it was serialized. Otherwise see the inner exception."); Assert.NotNull(exception.InnerException); }
public void DeserializeThrowsIfSerializedValueIsCorrupt() { // Arrange IMachineKey machineKey = new MockMachineKey(); // Act & assert Exception exception = ExceptionHelper.ExpectException <SerializationException>( delegate { MvcSerializer.Deserialize("This is a corrupted value.", SerializationMode.Signed, machineKey); }, @"Deserialization failed. Verify that the data is being deserialized using the same SerializationMode with which it was serialized. Otherwise see the inner exception."); Assert.IsNotNull(exception.InnerException, "Inner exception was not propagated correctly."); }
public void SerializeThrowsIfModeIsOutOfRange() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert ExceptionHelper.ExpectArgumentOutOfRangeException( delegate { serializer.Serialize(null, (SerializationMode)(-1)); }, "mode", @"The provided SerializationMode is invalid. Parameter name: mode"); }
public static string Serialize <T>(this T toSerialize) { var serializer = new MvcSerializer(); return(serializer.Serialize(toSerialize, MvcSerializer.DefaultSerializationMode)); }
public static T Deserialize <T>(this string toDeserialize) { var serializer = new MvcSerializer(); return((T)serializer.Deserialize(toDeserialize, MvcSerializer.DefaultSerializationMode)); }