FromObject() public method

Serializes the specified obj.
public FromObject ( object obj, ISerializerOptions options ) : object>.IDictionary
obj object The obj.
options ISerializerOptions
return object>.IDictionary
        public void Simple_With_Name()
        {
            // arrange
            var expected = "test";
            var obj = new TestModel();

            var ser = new Serializer();
            var options = new SerlizerOptions { CheckForObjectName = true };

            // act
            var result = ser.FromObject(obj, options);

            // assert
            Assert.AreEqual(expected, result.Keys.First());
        }
Ejemplo n.º 2
0
        public void Simple()
        {
            // arrange
            var expected = "test";
            var obj = new Dictionary<string, object>() {
                { "name", expected }
            };

            var ser = new Serializer();
            var options = new SerlizerOptions();

            // act
            var result = ser.FromObject(obj, options);

            // assert
            Assert.AreEqual(expected, result["name"]);
        }
Ejemplo n.º 3
0
        public void Simple_With_Name()
        {
            // arrange
            var expected = "test";
            var obj = new Dictionary<string, object>() {
                { Serializer.ModelNameKey, expected },
                { "name", "value" }
            };

            var ser = new Serializer();
            var options = new SerlizerOptions { CheckForObjectName = true };

            // act
            var result = ser.FromObject(obj, options);

            // assert
            Assert.AreEqual(expected, result.Keys.First());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the content.
        /// </summary>
        /// <returns></returns>
        protected internal override string GetContent()
        {
            XmlSerializer xmlSerializer = new XmlSerializer {
                CheckForObjectName = true,
                MaxSerializableLevelsSupported = null
            };

            Serializer serializer = new Serializer() {
                SerializePublicMembers = SerializePublicMembers,
                FollowFrameworkIgnoreAttributes = FollowFrameworkIgnoreAttributes
            };

            var response = BuildResponse(Model, serializer.FromObject(Model, xmlSerializer));

            Dictionary<string, object> wrapper = new Dictionary<string, object>();
            wrapper.Add("response", response);

            return xmlSerializer.Serialize(wrapper);
        }
Ejemplo n.º 5
0
        public void Should_Not_Contain_ModelName()
        {
            // arrange
            var expected = "test";
            var obj = new Dictionary<string, object>() {
                { Serializer.ModelNameKey, expected },
                { "name", "value" }
            };

            var ser = new Serializer();
            var options = new SerlizerOptions { CheckForObjectName = true };

            // act
            var result = ser.FromObject(obj, options);

            // assert
            var model = result.First();
            Assert.AreEqual(expected, model.Key);
            Assert.IsInstanceOf<IDictionary<string, object>>(model.Value);

            var modelValue = model.Value as IDictionary<string,object>;
            Assert.IsFalse(modelValue.ContainsKey(Serializer.ModelNameKey));
        }