Example #1
0
        public void PopulateViewModel(IDotvvmRequestContext context, string serializedPostData)
        {
            var data = JObject.Parse(serializedPostData);

            if (data["viewModelCacheId"] == null)
            {
                diagStore.TrackFullPostBack(context.Route.RouteName, serializedPostData.Length);
            }

            defaultViewModelSerializer.PopulateViewModel(context, serializedPostData);
        }
        public void DefaultViewModelSerializer_NoEncryptedValues()
        {
            var oldViewModel = new TestViewModel()
            {
                Property1 = "a",
                Property2 = 4,
                Property3 = new DateTime(2000, 1, 1),
                Property4 = new List <TestViewModel2>()
                {
                    new TestViewModel2()
                    {
                        PropertyA = "t", PropertyB = 15
                    },
                    new TestViewModel2()
                    {
                        PropertyA = "xxx", PropertyB = 16
                    }
                },
                Property5 = null
            };

            context.ViewModel = oldViewModel;
            serializer.BuildViewModel(context);
            var result = context.GetSerializedViewModel();

            result = UnwrapSerializedViewModel(result);
            result = WrapSerializedViewModel(result);

            var newViewModel = new TestViewModel();

            context.ViewModel = newViewModel;
            serializer.PopulateViewModel(context, result);

            Assert.AreEqual(oldViewModel.Property1, newViewModel.Property1);
            Assert.AreEqual(oldViewModel.Property2, newViewModel.Property2);
            Assert.AreEqual(oldViewModel.Property3, newViewModel.Property3);
            Assert.AreEqual(oldViewModel.Property4[0].PropertyA, newViewModel.Property4[0].PropertyA);
            Assert.AreEqual(oldViewModel.Property4[0].PropertyB, newViewModel.Property4[0].PropertyB);
            Assert.AreEqual(oldViewModel.Property4[1].PropertyA, newViewModel.Property4[1].PropertyA);
            Assert.AreEqual(oldViewModel.Property4[1].PropertyB, newViewModel.Property4[1].PropertyB);
            Assert.AreEqual(oldViewModel.Property5, newViewModel.Property5);
        }