예제 #1
0
        public void DeserializeThrowsIfSerializedValueIsNull() {
            // Arrange
            MvcSerializer serializer = new MvcSerializer();

            // Act & assert
            ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(
                delegate {
                    serializer.Deserialize(null, SerializationMode.Signed);
                }, "serializedValue");
        }
예제 #2
0
        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.");
        }
예제 #3
0
        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.");
        }
예제 #4
0
            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);
            }
예제 #5
0
            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));
            }