本文整理汇总了C#中Converter.ConvertDynamic方法的典型用法代码示例。如果您正苦于以下问题:C# Converter.ConvertDynamic方法的具体用法?C# Converter.ConvertDynamic怎么用?C# Converter.ConvertDynamic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Converter
的用法示例。
在下文中一共展示了Converter.ConvertDynamic方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert_DynamicObjectWithInvalidColumnName_ShouldThrowInvalidColumnException
public void Convert_DynamicObjectWithInvalidColumnName_ShouldThrowInvalidColumnException(Converter sut)
{
//Setup
var invalidColumnName = "address..zipCode";
var columns = new List<string>() {
"id",
"name",
"value"
};
var matrix = new List<List<object>>()
{
new List<object>() { 1, invalidColumnName, "firstName1" }
};
//Exercise
Action exercise = () => sut.ConvertDynamic(columns, matrix);
//Verify
exercise.ShouldThrow<ConverterInvalidColumnNameException>()
.Where(x => x.Message.Contains(invalidColumnName));
}
示例2: Convert_NestedDynamicObject_ShouldSucced
public void Convert_NestedDynamicObject_ShouldSucced(Converter sut)
{
//Setup
var columns = new List<string>() {
"id",
"name",
"value"
};
var matrix = new List<List<object>>()
{
new List<object>() { 1, "city.name", "cityName" },
new List<object>() { 1, "city.country.isoCode", "countryIsoCode" },
new List<object>() { 2, "school.name", "schoolName" }
};
//Exercise
var actual = sut.ConvertDynamic(columns, matrix);
//Verify
actual.Should().HaveCount(2)
.And.DeepContain(new Dictionary<string, object>()
{
{ "id", 1},
{ "city", new Dictionary<string, object>()
{
{ "name", "cityName" },
{ "country", new Dictionary<string, object>()
{
{ "isoCode", "countryIsoCode" }
}
}
}
}
})
.And.DeepContain(new Dictionary<string, object>()
{
{ "id", 2},
{ "school", new Dictionary<string, object>()
{
{ "name", "schoolName" }
}
}
});
}
示例3: Convert_DynamicObjectWithRepeatedColumns_ShouldThrowRepeatedColumnException
public void Convert_DynamicObjectWithRepeatedColumns_ShouldThrowRepeatedColumnException(Converter sut)
{
//Setup
var repeatedLabelName = "firstName";
var columns = new List<string>() {
"id",
"name",
"value"
};
var matrix = new List<List<object>>()
{
new List<object>() { 1, repeatedLabelName, "firstName1" },
new List<object>() { 1, repeatedLabelName, "firstName2" }
};
//Exercise
Action exercise = () => sut.ConvertDynamic(columns, matrix);
//Verify
exercise.ShouldThrow<ConverterRepeatedColumnException>()
.Where(x => x.Message.Contains(repeatedLabelName));
}
示例4: Convert_SimpleDynamicObject_ShouldSucced
public void Convert_SimpleDynamicObject_ShouldSucced(Converter sut)
{
//Setup
var columns = new List<string>() {
"id",
"name",
"value"
};
var matrix = new List<List<object>>()
{
new List<object>() { 1, "firstName", "firstName" },
new List<object>() { 1, "lastName", "lastName" },
new List<object>() { 2, "hasPets", true }
};
//Exercise
var actual = sut.ConvertDynamic(columns, matrix);
//Verify
actual.Should().NotBeEmpty()
.And.HaveCount(2)
.And.DeepContain(new Dictionary<string, object>() { { "id", 1 }, { "firstName", "firstName" }, { "lastName", "lastName" } })
.And.DeepContain(new Dictionary<string, object>() { { "id", 2 }, { "hasPets", true } });
}