本文整理汇总了C#中ParameterDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# ParameterDescriptor类的具体用法?C# ParameterDescriptor怎么用?C# ParameterDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParameterDescriptor类属于命名空间,在下文中一共展示了ParameterDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindPropertyFromService_WithData_WithEmptyPrefix_GetsBound
public async Task BindPropertyFromService_WithData_WithEmptyPrefix_GetsBound()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo(),
ParameterType = typeof(Person)
};
var operationContext = ModelBindingTestHelper.GetOperationBindingContext();
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
// Model
var boundPerson = Assert.IsType<Person>(modelBindingResult.Model);
Assert.NotNull(boundPerson);
Assert.NotNull(boundPerson.Address.OutputFormatter);
// ModelState
Assert.True(modelState.IsValid);
// For non user bound models there should be no entry in model state.
Assert.Empty(modelState);
}
示例2: GetContextConstructorParameters
public override ParameterDescriptor[] GetContextConstructorParameters(IConnectionInfo cxInfo)
{
var providerNameParameter = new ParameterDescriptor("providerName", "System.String");
var connectionStringParameter = new ParameterDescriptor("connectionString", "System.String");
return new[] { providerNameParameter, connectionStringParameter };
}
示例3: GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelBinder_EmptyPrefix_Success
public async Task GenericModelBinder_BindsCollection_ElementTypeFromGreedyModelBinder_EmptyPrefix_Success()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "parameter",
ParameterType = typeof(List<IFormCollection>)
};
// Need to have a key here so that the GenericModelBinder will recurse to bind elements.
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
{
request.QueryString = new QueryString("?index=10");
});
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
var model = Assert.IsType<List<IFormCollection>>(modelBindingResult.Model);
Assert.Equal(1, model.Count);
Assert.NotNull(model[0]);
Assert.Equal(0, modelState.Count);
Assert.Equal(0, modelState.ErrorCount);
Assert.True(modelState.IsValid);
}
示例4: BindParameter_WithModelBinderType_NoData_ReturnsNull
public async Task BindParameter_WithModelBinderType_NoData_ReturnsNull()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo()
{
BinderType = typeof(NullModelNotSetModelBinder)
},
ParameterType = typeof(string)
};
// No data is passed.
var operationContext = ModelBindingTestHelper.GetOperationBindingContext();
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.Null(modelBindingResult);
// ModelState (not set unless inner binder sets it)
Assert.True(modelState.IsValid);
Assert.Empty(modelState);
}
示例5: BindProperty_WithData_WithEmptyPrefix_GetsBound
public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo(),
ParameterType = typeof(Person)
};
var operationContext = ModelBindingTestHelper.GetOperationBindingContext();
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
// Model
var boundPerson = Assert.IsType<Person>(modelBindingResult.Model);
Assert.NotNull(boundPerson);
Assert.NotNull(boundPerson.Token);
// ModelState
Assert.True(modelState.IsValid);
Assert.Equal(0, modelState.Count);
}
示例6: Add
public void Add(ParameterDescriptor parameterDescriptor, string value, IWatchable watchable)
{
lock (_itemsLock)
{
_items.Add(new Tuple<ParameterDescriptor, string, IWatchable>(parameterDescriptor, value, watchable));
}
}
示例7: Arguments_HaveCorrectDescription_Returns_CorrectValue
public void Arguments_HaveCorrectDescription_Returns_CorrectValue(
string propertyName,
string expectedDescription)
{
//Arrange
var command = new CommandLineApplication();
var property = typeof(TestClass).GetProperty(propertyName);
var descriptor = new ParameterDescriptor(property);
//Act
descriptor.AddCommandLineParameterTo(command);
//Assert
var actualOption = command.Arguments.First();
Assert.Equal(propertyName, actualOption.Name);
Assert.Equal(expectedDescription, actualOption.Description);
//Arrange
command.Execute(new string[0] { });
//Assert
Assert.Equal(null, descriptor.Value); //Is this right assumption to test?
//Arrange
command.Execute(new string[] { "PassedValue" });
//Assert
Assert.Equal("PassedValue", descriptor.Value);
}
示例8: FromBodyOnActionParameter_EmptyBody_BindsToNullValue
public async Task FromBodyOnActionParameter_EmptyBody_BindsToNullValue()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo()
{
BinderModelName = "CustomParameter",
BindingSource = BindingSource.Body
},
ParameterType = typeof(Person)
};
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(
request =>
{
request.Body = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty));
request.ContentType = "application/json";
});
var httpContext = operationContext.HttpContext;
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
Assert.Null(modelBindingResult.Model);
Assert.Empty(modelState.Keys);
Assert.True(modelState.IsValid);
}
示例9: BindParameter_WithModelBinderType_NonGreedy_NoData
public async Task BindParameter_WithModelBinderType_NonGreedy_NoData()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo()
{
BinderType = typeof(NullResultModelBinder)
},
ParameterType = typeof(Person2)
};
// No data is passed.
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { });
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
// ModelState
Assert.True(modelState.IsValid);
Assert.Empty(modelState.Keys);
}
示例10: BindProperty_WithData_GetsBound
public async Task BindProperty_WithData_GetsBound(bool fallBackScenario)
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo(),
ParameterType = typeof(Person)
};
var prefix = fallBackScenario ? string.Empty : "Parameter1";
var queryStringKey = fallBackScenario ? "Token" : prefix + "." + "Token";
// any valid base64 string
var expectedValue = new byte[] { 12, 13 };
var value = Convert.ToBase64String(expectedValue);
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(
request =>
{
request.QueryString = QueryString.Create(queryStringKey, value);
});
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
// Model
var boundPerson = Assert.IsType<Person>(modelBindingResult.Model);
Assert.NotNull(boundPerson);
Assert.NotNull(boundPerson.Token);
Assert.Equal(expectedValue, boundPerson.Token);
// ModelState
Assert.True(modelState.IsValid);
Assert.Equal(2, modelState.Keys.Count);
Assert.Single(modelState.Keys, k => k == prefix);
Assert.Single(modelState.Keys, k => k == queryStringKey);
var key = Assert.Single(modelState.Keys, k => k == queryStringKey + "[0]");
Assert.NotNull(modelState[key].Value); // should be non null bug #2445.
Assert.Empty(modelState[key].Errors);
Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState);
key = Assert.Single(modelState.Keys, k => k == queryStringKey + "[1]");
Assert.NotNull(modelState[key].Value); // should be non null bug #2445.
Assert.Empty(modelState[key].Errors);
Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState);
}
示例11: Bind_should_invoke_internal_DataBinder_using_values_from_Request_Params
public void Bind_should_invoke_internal_DataBinder_using_values_from_Request_Params()
{
var http = new Mock<HttpContextBase>();
var attr = new DataBindAttribute();
var descriptor = new ParameterDescriptor("user", typeof (User));
http.SetupGet(ctx => ctx.Request.Params).Returns(new NameValueCollection{{"user.Name", "Lyle"}});
var result = attr.Bind(http.Object, descriptor);
Assert.IsAssignableFrom<User>(result);
Assert.AreEqual("Lyle", ((User) result).Name);
}
示例12: GetValue
public static object GetValue(Command cmd, ParameterDescriptor pd)
{
object value = null;
if (pd.SourceLocation == SourceLocation.FromCommand)
{
value = cmd.Arguments[pd.KeyInSource];
}
else
{
throw new Exception("Unknow SourceLocation");
}
return value;
}
示例13: BindProperty_WithData_WithPrefix_GetsBound
public async Task BindProperty_WithData_WithPrefix_GetsBound()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo()
{
BinderModelName = "CustomParameter",
},
ParameterType = typeof(Person)
};
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
{
request.QueryString = QueryString.Create("CustomParameter.Address.Zip", "1");
});
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
// Model
var boundPerson = Assert.IsType<Person>(modelBindingResult.Model);
Assert.NotNull(boundPerson);
Assert.NotNull(boundPerson.Address);
Assert.Equal(1, boundPerson.Address.Zip);
// ModelState
Assert.True(modelState.IsValid);
Assert.Equal(1, modelState.Keys.Count);
var key = Assert.Single(modelState.Keys, k => k == "CustomParameter.Address.Zip");
Assert.NotNull(modelState[key].Value);
Assert.Equal("1", modelState[key].Value.AttemptedValue);
Assert.Equal("1", modelState[key].Value.RawValue);
Assert.NotNull(modelState[key].Value);
Assert.Empty(modelState[key].Errors);
Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState);
}
示例14: BindProperty_WithData_WithEmptyPrefix_GetsBound
public async Task BindProperty_WithData_WithEmptyPrefix_GetsBound()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo(),
ParameterType = typeof(Person)
};
var data = "Some Data Is Better Than No Data.";
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(
request =>
{
request.QueryString = QueryString.Create("Address.Zip", "12345");
UpdateRequest(request, data, "Address.File");
});
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
// Model
var boundPerson = Assert.IsType<Person>(modelBindingResult.Model);
Assert.NotNull(boundPerson.Address);
var formCollection = Assert.IsAssignableFrom<FormCollection>(boundPerson.Address.FileCollection);
var file = Assert.Single(formCollection.Files);
Assert.Equal("form-data; name=Address.File; filename=text.txt", file.ContentDisposition);
var reader = new StreamReader(file.OpenReadStream());
Assert.Equal(data, reader.ReadToEnd());
// ModelState
Assert.True(modelState.IsValid);
Assert.Equal(2, modelState.Count);
Assert.Single(modelState.Keys, k => k == "Address.Zip");
var key = Assert.Single(modelState.Keys, k => k == "Address.File");
Assert.NotNull(modelState[key].Value); // should be non null bug #2445.
Assert.Empty(modelState[key].Errors);
Assert.Equal(ModelValidationState.Valid, modelState[key].ValidationState);
}
示例15: BindPropertyFromHeader_WithPrefix_GetsBound
public async Task BindPropertyFromHeader_WithPrefix_GetsBound()
{
// Arrange
var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
var parameter = new ParameterDescriptor()
{
Name = "Parameter1",
BindingInfo = new BindingInfo()
{
BinderModelName = "prefix",
},
ParameterType = typeof(Person)
};
// Do not add any headers.
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => {
request.Headers.Add("Header", new[] { "someValue" });
});
var modelState = new ModelStateDictionary();
// Act
var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
// Assert
// ModelBindingResult
Assert.NotNull(modelBindingResult);
Assert.True(modelBindingResult.IsModelSet);
// Model
var boundPerson = Assert.IsType<Person>(modelBindingResult.Model);
Assert.NotNull(boundPerson);
Assert.NotNull(boundPerson.Address);
Assert.Equal("someValue", boundPerson.Address.Street);
// ModelState
Assert.True(modelState.IsValid);
Assert.Equal(3, modelState.Count);
Assert.Single(modelState.Keys, k => k == "prefix.Address");
Assert.Single(modelState.Keys, k => k == "prefix");
var key = Assert.Single(modelState.Keys, k => k == "prefix.Address.Header");
Assert.NotNull(modelState[key].Value);
Assert.Equal("someValue", modelState[key].Value.RawValue);
Assert.Equal("someValue", modelState[key].Value.AttemptedValue);
}