public void Should_Return_False_If_Id_Value_not_Set_in_Route() { var controllerContext = new HttpControllerContext(); var routeDictionary = new HttpRouteValueDictionary(new Dictionary <string, object>()); controllerContext.RouteData = new HttpRouteData(new HttpRoute(), routeDictionary); var actionContext = new HttpActionContext { ControllerContext = controllerContext }; var bindingContext = new ModelBindingContext { ModelMetadata = new ModelMetadata( new EmptyModelMetadataProvider(), typeof(object), () => new object(), typeof(StudentGetByIds), "foo") }; var sut = new IdsModelBinder(); var result = sut.BindModel(actionContext, bindingContext); result.ShouldBeFalse(); }
public void Should_Ignore_Trailing_Commas_In_Input_Guid_String() { var guidString = string.Format("{0},{1},", Guid.NewGuid(), Guid.NewGuid()); var controllerContext = new HttpControllerContext(); var routeDictionary = new HttpRouteValueDictionary( new Dictionary <string, object> { { "id", guidString } }); controllerContext.RouteData = new HttpRouteData(new HttpRoute(), routeDictionary); var actionContext = new HttpActionContext { ControllerContext = controllerContext }; var bindingContext = new ModelBindingContext { ModelMetadata = new ModelMetadata( new EmptyModelMetadataProvider(), typeof(object), () => new object(), typeof(StudentGetByIds), "foo") }; var sut = new IdsModelBinder(); var result = sut.BindModel(actionContext, bindingContext); result.ShouldBeTrue(); }
public void Should_Return_False_If_Id_Value_not_Set_in_Route() { var bindingContext = A.Fake <ModelBindingContext>(); RouteValueDictionary keyValuePairs = new RouteValueDictionary(); bindingContext.ActionContext.RouteData = new RouteData(keyValuePairs); var sut = new IdsModelBinder(); Task result = sut.BindModelAsync(bindingContext); result.IsCompleted.ShouldBeTrue(); }
public void Should_Ignore_Trailing_Commas_In_Input_Guid_String() { var guidString = string.Format("{0},{1},", Guid.NewGuid(), Guid.NewGuid()); var bindingContext = A.Fake <ModelBindingContext>(); RouteValueDictionary keyValuePairs = new RouteValueDictionary(); keyValuePairs.Add("id", guidString); bindingContext.ActionContext.RouteData = new RouteData(keyValuePairs); A.CallTo(() => bindingContext.ModelType).Returns(typeof(StudentGetByIds)); var sut = new IdsModelBinder(); Task result = sut.BindModelAsync(bindingContext); result.IsCompleted.ShouldBeTrue(); }