コード例 #1
0
        public void WhenParametersAreNotSpecified_BindModel_SetsDefaultPropertyValues()
        {
            // Arrange.
            var binder = new SearchParametersBinder();

            // Act.
            Assert.IsTrue(binder.BindModel(_actionContext, _bindingContext));

            // Assert.
            var model = _bindingContext.Model as SearchParameters;

            Assert.IsNotNull(model);
            Assert.AreEqual(ProcessName, model.ProcessName);
            Assert.IsFalse(model.IncludeProcessMetadata);
            Assert.IsFalse(model.IncludeLayoutMetadata);
            Assert.IsNull(model.PageNumber);
            Assert.IsNull(model.PageSize);
            Assert.IsNull(model.SearchText);
            Assert.IsNull(model.LayoutId);
            Assert.IsNull(model.FilterId);
            Assert.IsTrue(model.ApplyDefaultFilter);
            Assert.AreEqual(0, model.FilterParameters.Count);
            Assert.AreEqual(0, model.SortDescriptors.Count);
            Assert.IsTrue(model.ApplyLayoutSortDescriptors);
            Assert.IsNull(model.Expand);
            Assert.IsNull(model.Join);
            Assert.IsNull(model.Filter);
        }
コード例 #2
0
        public void WhenParametersAreSpecified_BindModel_SetsPropertyValues()
        {
            // Arrange.
            const string SearchText = "Text to search";
            const int LayoutId = 1001;
            const int FilterId = 2001;
            const string Expand = "Test expand";
            const string Join = "Test join";
            const string Filter = "Test filter";

            SetupValue("includeProcessMetadata", true);
            SetupValue("includeLayoutMetadata", true);
            SetupValue("page", 2);
            SetupValue("pageSize", 100);
            SetupValue("searchText", SearchText);
            SetupValue("layoutId", LayoutId);
            SetupValue("filterId", FilterId);

            var filterParameters = new List<object> { "test", 123, new DateTime(2015, 5, 18) };
            SetupValue("filterParameters", JsonConvert.SerializeObject(filterParameters));

            var sortDescriptors = new[] { new { Name = "Field1", Direction = "Descending" }, new { Name = "Field2", Direction = "Ascending" } };
            SetupValue("sortFields", JsonConvert.SerializeObject(sortDescriptors));

            SetupValue("$expand", Expand);
            SetupValue("$join", Join);
            SetupValue("$filter", Filter);

            var binder = new SearchParametersBinder();

            // Act.
            Assert.IsTrue(binder.BindModel(_actionContext, _bindingContext));

            // Assert.
            var model = _bindingContext.Model as SearchParameters;

            Assert.IsNotNull(model);
            Assert.AreEqual(true, model.IncludeProcessMetadata);
            Assert.AreEqual(true, model.IncludeLayoutMetadata);
            Assert.AreEqual(2, model.PageNumber);
            Assert.AreEqual(100, model.PageSize);
            Assert.AreEqual(SearchText, model.SearchText);
            Assert.AreEqual(LayoutId, model.LayoutId);
            Assert.AreEqual(FilterId, model.FilterId);
            Assert.IsFalse(model.ApplyDefaultFilter);

            Assert.AreEqual(3, model.FilterParameters.Count);
            Assert.AreEqual("test", model.FilterParameters[0]);
            Assert.AreEqual(123L, model.FilterParameters[1]);
            Assert.AreEqual(new DateTime(2015, 5, 18), model.FilterParameters[2]);

            Assert.AreEqual(2, model.SortDescriptors.Count);
            Assert.AreEqual("Field1", model.SortDescriptors[0].ColumnName);
            Assert.AreEqual(SortDirection.Descending, model.SortDescriptors[0].Direction);
            Assert.AreEqual("Field2", model.SortDescriptors[1].ColumnName);
            Assert.AreEqual(SortDirection.Ascending, model.SortDescriptors[1].Direction);
            Assert.IsFalse(model.ApplyLayoutSortDescriptors);

            Assert.AreEqual(Expand, model.Expand);
            Assert.AreEqual(Join, model.Join);
            Assert.AreEqual(Filter, model.Filter);
        }
コード例 #3
0
        public void WhenFilterIdIsNull_BindModel_DisablesDefaultFilter()
        {
            // Arrange.
            var binder = new SearchParametersBinder();
            SetupValue("filterId", "null");

            // Act.
            Assert.IsTrue(binder.BindModel(_actionContext, _bindingContext));

            // Assert.
            var model = _bindingContext.Model as SearchParameters;
            Assert.IsNotNull(model);

            Assert.IsNull(model.FilterId);
            Assert.IsFalse(model.ApplyDefaultFilter);
        }
コード例 #4
0
        public void WhenFilterParametersDeserializationFails_BindModel_SetsModelError()
        {
            // Arrange.
            var binder = new SearchParametersBinder();
            SetupValue("filterParameters", "not json");

            // Act.
            Assert.IsFalse(binder.BindModel(_actionContext, _bindingContext));

            // Assert.
            Assert.IsNull(_bindingContext.Model);
            Assert.IsFalse(_bindingContext.ModelState.IsValid);
            Assert.IsTrue(_bindingContext.ModelState.ContainsKey("filterParameters"));
        }
コード例 #5
0
        public void WhenPageSizeIsOutOfRange_BindModel_SetsModelError()
        {
            // Arrange.
            var binder = new SearchParametersBinder();
            SetupValue("pageSize", 0);

            // Act.
            Assert.IsFalse(binder.BindModel(_actionContext, _bindingContext));

            // Assert.
            Assert.IsNull(_bindingContext.Model);
            Assert.IsFalse(_bindingContext.ModelState.IsValid);
            Assert.IsTrue(_bindingContext.ModelState.ContainsKey("pageSize"));
        }
コード例 #6
0
        public void WhenParameterConversionFails_BindModel_SetsModelError()
        {
            // Arrange.
            var binder = new SearchParametersBinder();
            SetupValue("page", "not a number");

            // Act.
            Assert.IsFalse(binder.BindModel(_actionContext, _bindingContext));

            // Assert.
            Assert.IsNull(_bindingContext.Model);
            Assert.IsFalse(_bindingContext.ModelState.IsValid);
            Assert.IsTrue(_bindingContext.ModelState.ContainsKey("page"));
        }