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(); }