Ejemplo n.º 1
0
        public void SimpleArray()
        {
            var request = new HttpRequest();
            request.Form.Add("Ages[]", "8");
            request.Form.Add("Ages[]", "32");

            var modelMapper = new ModelMapper();
            var actual = (SimpleArrayViewModel)modelMapper.Map(typeof(SimpleArrayViewModel), request, "");

            Assert.Equal(8, actual.Ages[0]);
            Assert.Equal(32, actual.Ages[1]);
        }
Ejemplo n.º 2
0
        public void SimpleMapping()
        {
            var request = new HttpRequest();
            request.Form.Add("UserName", "Jonas");
            request.Form.Add("FirstName", "Arne");

            var modelMapper = new ModelMapper();
            var user = (UserViewModel)modelMapper.Map(typeof(UserViewModel), request, "");

            Assert.Equal("Jonas", user.UserName);
            Assert.Equal("Arne", user.FirstName);
        }
        public void SimpleMapping()
        {
            var request = new HttpRequest();
            request.Form.Add("UserName", "Jonas");
            request.Form.Add("FirstName", "Arne");

            var modelMapper = new ModelMapper();
            var actual = modelMapper.Bind<UserViewModel>(request, "");

            Assert.Equal("Jonas", actual.UserName);
            Assert.Equal("Arne", actual.FirstName);
        }
Ejemplo n.º 4
0
        public void Nested()
        {
            var request = new HttpRequest();
            request.Form.Add("Author.UserName", "Jonas");
            request.Form.Add("Author.FirstName", "Arne");
            request.Form.Add("Rating", "22");

            var modelMapper = new ModelMapper();
            var actual = (RatingViewModel)modelMapper.Map(typeof(RatingViewModel), request, "");

            Assert.Equal("Jonas", actual.Author.UserName);
            Assert.Equal("Arne", actual.Author.FirstName);
        }
        public void Decode()
        {
            var request = new HttpRequest();
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded;charset=ASCII");
            request.Body = new MemoryStream();
            request.Body.Write(Encoding.ASCII.GetBytes("hello=world"), 0, "hello=world".Length);
            request.Body.Position = 0;

            var decoder = new UrlFormattedDecoder();
            decoder.Decode(request);

            Assert.Equal("world", request.Form["hello"]);
        }
        public void Array_Indexed()
        {
            var request = new HttpRequest();
            request.Form.Add("users[0].FirstName", "Hobbe");
            request.Form.Add("users[0].Age", "32");
            request.Form.Add("users[1].FirstName", "Kalle");
            request.Form.Add("users[2].Age", "10");

            var modelMapper = new ModelMapper();
            var actual = modelMapper.Bind<UserViewModel[]>(request, "users");

            Assert.Equal("Hobbe", actual[0].FirstName);
            Assert.Equal("Kalle", actual[1].FirstName);
        }
        public void Array_Associative()
        {
            var request = new HttpRequest();
            request.Form.Add("Users[Jonas].FirstName", "Hobbe");
            request.Form.Add("Users[Jonas].Age", "32");
            request.Form.Add("Users[Arne].FirstName", "Kalle");
            request.Form.Add("Users[Arne].Age", "10");

            var modelMapper = new ModelMapper();
            var actual = modelMapper.Bind<Dictionary<string, UserViewModel>>(request, "Users");

            Assert.Equal("Hobbe", actual["Jonas"].FirstName);
            Assert.Equal("Kalle", actual["Arne"].FirstName);
        }
        public void Array_AssociativeNumeric()
        {
            var request = new HttpRequest();
            request.Form.Add("Users['0'].FirstName", "Hobbe");
            request.Form.Add("Users['0'].Age", "32");
            request.Form.Add("Users['1'].FirstName", "Kalle");
            request.Form.Add("Users['1'].Age", "10");

            var modelMapper = new ModelMapper();
            var actual = modelMapper.Bind<SimpleAssocArrayViewModel>(request, "");

            Assert.Equal("Hobbe", actual.Users["0"].FirstName);
            Assert.Equal("Kalle", actual.Users["1"].FirstName);
        }