private DeserializationViewModel BuildModel()
        {
            var factory    = new DeserializerFactory <Person>();
            var ret        = new DeserializationViewModel();
            var defaultObj = new Person()
            {
                Name = new Name()
                {
                    FirstName  = "Firsty",
                    MiddleName = "Midler",
                    LastName   = "Laster"
                },
                Age     = 26,
                Address = new Address {
                    Street = "123 Some Street", City = "Some City", State = "MN"
                },
                Properties = new List <Property>()
            };

            defaultObj.Properties.Add(new Property("address", new Address {
                Street = "123 Some Street", City = "Some City", State = "MN"
            }));

            for (int i = 0; i < Enum.GetNames(typeof(DeserializerTypeEnum)).Length; i++)
            {
                var ser        = factory.GetDeserializer((DeserializerTypeEnum)i);
                var serialized = ser.Serialize(defaultObj);
                ret.DefaultData.Add(serialized);
            }

            return(ret);
        }
        public void Return_Excepted_Desirializer_If_Only_Default_Provided()
        {
            var           factory = new DeserializerFactory(_mock.Object);
            IDeserializer act     = factory.GetDeserializer("json");

            Assert.Equal(_mock.Object, act);
        }
        public void Return_Default_Desirializer_If_Content_Type_Is_Not_Registred(string contenType)
        {
            var           factory = new DeserializerFactory(_mock.Object);
            IDeserializer act     = factory.GetDeserializer(contenType);

            Assert.Equal(_mock.Object, act);
        }
        public void Return_Excepted_Desirializer_If_Custom_Registred()
        {
            var mock = new Mock <IDeserializer>();

            mock.Setup(deserializer => deserializer.ContentType)
            .Returns("xml");

            var factory = new DeserializerFactory(_mock.Object);

            factory.AddDeserializer(mock.Object);
            IDeserializer act = factory.GetDeserializer("json");

            Assert.Equal(_mock.Object, act);
        }
        [ValidateInput(false)]//Security Warning: Unsafe, can lead to XSS
        public ActionResult Deserialize(string data, int library)
        {
            var model = BuildModel();

            model.Data    = data;
            model.Library = (SerializationTypeEnum)library;

            var factory      = new DeserializerFactory <Person>();
            var deserializer = factory.GetDeserializer((DeserializerTypeEnum)library);
            var person       = deserializer.Deserialize(data);

            model.Output = person.ToString();

            return(View("Index", model));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get list of objects from database query
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="connection">DB Connection</param>
        /// <param name="command">DB Command to execute</param>
        /// <param name="transaction">Transaction to use</param>
        /// <returns></returns>
        public static IEnumerable <T> XQuery <T>(this IDbConnection connection, IDbCommand command, IDbTransaction transaction = null) where T : new()
        {
            connection.OpenIfNot();
            command.Connection     = connection;
            command.Transaction    = transaction;
            command.CommandTimeout = XyapperManager.CommandTimeout;
            command.Log();

            using (var reader = command.ExecuteReader())
            {
                var deserializer = DeserializerFactory.GetDeserializer <T>(reader);

                while (reader.Read())
                {
                    yield return(deserializer(reader));
                }
            }
            //connection.CloseAndDispose();
        }