public void Should_return_null_when_query_string_parameter_value_is_null() { ModelBindingContext context = CreateBindingContext("foo", null); ; var binder = new ModelBinder <TEntity, TRepository>(null); var binderResult = binder.BindModel(GetControllerContext("foo", ""), context).Value; binderResult.ShouldBeNull(); }
public void Should_get_entity_from_repository_by_id_on_query_string() { Guid guid = Guid.NewGuid(); var repository = MockRepository.GenerateMock <TRepository>(); var entity = new TEntity(); repository.Stub(r => r.GetById(guid)).Return(entity); var binder = new ModelBinder <TEntity, TRepository>(repository); ControllerContext controllerContext1 = GetControllerContext("fooId", guid.ToString()); //capitalize ControllerContext controllerContext2 = GetControllerContext("barid", guid.ToString()); //lowercase ModelBindingContext modelBindingContext = CreateBindingContext("fooid", guid.ToString()); var result = binder.BindModel(controllerContext1, modelBindingContext); Assert.That(result.Value, Is.EqualTo(entity)); ModelBindingContext modelBindingContext2 = CreateBindingContext("barid", guid.ToString()); result = binder.BindModel(controllerContext2, modelBindingContext2); Assert.That(result.Value, Is.EqualTo(entity)); }
public void BindModel_ExpectedFormValues_MapsFormCollectionToModel() { FakeHttpPost(); _table = _binder.BindModel(_controllerContext, _modelBindingContext) as Table; Assert.NotNull(_table); Assert.Equal(3, _table.Columns.Count()); Assert.Equal <int>(0, _table.Draw); Assert.Equal <int>(0, _table.Start); Assert.Equal <int>(10, _table.Length); Assert.Equal <bool>(true, _table.CheckboxColumn); Assert.Equal <bool>(false, _table.SaveAs); Assert.Equal <string[]>(new string[] { "Name00", "Name01" }, _table.ColumnNames); Assert.Equal <string>("global search value", _table.Search.Value); Column data0 = _table.Columns.ElementAt(0); Column data1 = _table.Columns.ElementAt(1); Column nonData = _table.Columns.ElementAt(2); Assert.Equal <string>("1", data0.Data); Assert.Equal <string>("2", data1.Data); Assert.Equal <string>("3", nonData.Data); Assert.Equal <bool>(true, data0.IsSearchable); Assert.Equal <bool>(true, data1.IsSearchable); Assert.Equal <bool>(false, nonData.IsSearchable); Assert.Equal <bool>(true, data0.IsSortable); Assert.Equal <bool>(true, data1.IsSortable); Assert.Equal <bool>(false, nonData.IsSortable); Assert.Equal <int>(0, _table.SortOrders.ElementAt(0).ColumnIndex); Assert.Equal <int>(1, _table.SortOrders.ElementAt(1).ColumnIndex); Assert.Equal <string>("desc", _table.SortOrders.ElementAt(0).Direction); Assert.Equal <string>("desc", _table.SortOrders.ElementAt(0).Direction); Assert.Equal <int>(0, data0.Search.ColumnIndex); Assert.Equal <int>(1, data1.Search.ColumnIndex); Assert.Equal <string>("SEARCH_00", data0.Search.Value); Assert.Equal <string>("SEARCH_01", data1.Search.Value); }
public void Should_throw_error_when_query_string_parameter_not_found() { const string badParameter = "Bad Value"; ControllerContext controllerContext = GetControllerContext("foo", badParameter); var context = new ModelBindingContext { ModelName = "foo" }; var binder = new ModelBinder <TEntity, TRepository>(null); binder.BindModel(controllerContext, context); }
public void Should_auto_append_id_when_looking_for_querystring_value() { Guid guid = Guid.NewGuid(); var repository = MockRepository.GenerateMock <TRepository>(); var entity = new TEntity(); repository.Stub(r => r.GetById(guid)).Return(entity); var binder = new ModelBinder <TEntity, TRepository>(repository); ControllerContext controllerContext = GetControllerContext("foo", guid.ToString()); ModelBindingContext context = CreateBindingContext("foo", guid.ToString()); object result = binder.BindModel(controllerContext, context).Value; Assert.That(result, Is.EqualTo(entity)); }
public void CamelCase_WithoutDrawWithValidation() { // Arrange var binder = new ModelBinder(); var modelBindingContext = TestHelper.MockModelBindingContextWithCamelCase(null, "13", "99", "mockSearchValue", "true"); var options = new Options(); // Act //var model = (Core.IDataTablesRequest)binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters).Model; binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters); var model = modelBindingContext.Result.IsModelSet ? (Core.IDataTablesRequest)modelBindingContext.Result.Model : null; // Assert Assert.Equal(null, model); }
public void InvalidRequest() { // Arrange var binder = new ModelBinder(); var modelBindingContext = TestHelper.MockModelBindingContextWithInvalidRequest(); var options = new Options(); // Act //var model = (Core.IDataTablesRequest)binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters).Model; binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters); var model = modelBindingContext.Result.IsModelSet ? (Core.IDataTablesRequest)modelBindingContext.Result.Model : null; // Assert Assert.Equal(null, model); }
public void HungarianNotation_WithoutDrawWithoutValidation() { // Arrange var binder = new ModelBinder(); var modelBindingContext = TestHelper.MockModelBindingContextWithHungarianNotation(null, "13", "99", "mockSearchValue", "true"); var options = new Options().UseHungarianNotation().DisableDrawValidation(); // Act //var model = (Core.IDataTablesRequest)binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters).Model; binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters); var model = modelBindingContext.Result.IsModelSet ? (Core.IDataTablesRequest)modelBindingContext.Result.Model : null; // Assert Assert.Equal(0, model.Draw); Assert.Equal(13, model.Length); Assert.Equal(99, model.Start); Assert.Equal("mockSearchValue", model.Search.Value); Assert.Equal(true, model.Search.IsRegex); }
public void CamelCase_WithAditionalParametersWithoutEnableAditionalParameters() { // Arrange var binder = new ModelBinder(); var modelBindingContext = TestHelper.MockModelBindingContextWithCamelCase("3", "13", "99", "mockSearchValue", "true", new Dictionary <string, object>() { { "firstParameter", "firstValue" }, { "secondParameter", 7 } }); var options = new Options(); // Act //var model = (Core.IDataTablesRequest)binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters).Model; binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters); var model = modelBindingContext.Result.IsModelSet ? (Core.IDataTablesRequest)modelBindingContext.Result.Model : null; // Assert Assert.Equal(3, model.Draw); Assert.Equal(null, model.AdditionalParameters); }
public void CamelCase_CompleteValues() { // Arrange var binder = new ModelBinder(); var modelBindingContext = TestHelper.MockModelBindingContextWithCamelCase("3", "13", "99", "mockSearchValue", "true"); var options = new Options(); // Act //var model = (Core.IDataTablesRequest)binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters).Model; binder.BindModel(modelBindingContext, options, TestHelper.ParseAdditionalParameters); var model = modelBindingContext.Result.IsModelSet ? (Core.IDataTablesRequest)modelBindingContext.Result.Model : null; // Assert Assert.Equal(3, model.Draw); Assert.Equal(13, model.Length); Assert.Equal(99, model.Start); Assert.Equal("mockSearchValue", model.Search.Value); Assert.Equal(true, model.Search.IsRegex); Assert.Equal(0, model.Columns.Count()); }