public void DeserializeThrowsIfSerializedValueIsNull() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert ExceptionHelper.ExpectArgumentExceptionNullOrEmpty( delegate { serializer.Deserialize(null, SerializationMode.Signed); }, "serializedValue"); }
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 DeserializeThrowsIfSerializedValueIsCorrupt() { // Arrange MvcSerializer serializer = new MvcSerializer(); // Act & assert Exception exception = ExceptionHelper.ExpectException<SerializationException>( delegate { serializer.Deserialize("This is a corrupted value.", SerializationMode.Plaintext); }, @"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 object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException("bindingContext"); } ValueProviderResult vpResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (vpResult == null) { // nothing found return null; } MvcSerializer serializer = new MvcSerializer(); string serializedValue = (string)vpResult.ConvertTo(typeof(string)); return serializer.Deserialize(serializedValue, _mode); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException("bindingContext"); } ValueProviderResult vpResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (vpResult == null) { // nothing found return(null); } string serializedValue = (string)vpResult.ConvertTo(typeof(string)); return(_serializer.Deserialize(serializedValue, _mode)); }