本文整理汇总了C#中Xunit.JsonObject类的典型用法代码示例。如果您正苦于以下问题:C# JsonObject类的具体用法?C# JsonObject怎么用?C# JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonObject类属于Xunit命名空间,在下文中一共展示了JsonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetFieldsAddsKeyValuePairs
public void SetFieldsAddsKeyValuePairs()
{
dynamic person = new JsonObject();
person.FirstName = "Mikael";
person.LastName = "Waltersson";
person.Age = 30;
Assert.Equal(new[] { "FirstName", "LastName", "Age" }, person.GetDynamicMemberNames());
Assert.Equal(
new Dictionary<string, object>
{
{ "FirstName", "Mikael" },
{ "LastName", "Waltersson" },
{ "Age", 30 }
},
(IEnumerable<KeyValuePair<string, object>>)person);
Assert.Equal("Mikael", person.FirstName);
Assert.Equal("Waltersson", person.LastName);
Assert.Equal(30, person.Age);
}
示例2: NonExistingFieldsHasUndefinedValue
public void NonExistingFieldsHasUndefinedValue()
{
dynamic person = new JsonObject();
person.FirstName = "Mikael";
Assert.Equal(Undefined.Value, person.LastName);
}
示例3: JsonObject_ToString_OrderingMaintained
public void JsonObject_ToString_OrderingMaintained()
{
var obj = new JsonObject();
obj["a"] = 1;
obj["c"] = 3;
obj["b"] = 2;
Assert.Equal("{\"a\": 1, \"b\": 2, \"c\": 3}", obj.ToString());
}
示例4: convert_large_number_to_json
public void convert_large_number_to_json()
{
var obj = new JsonObject();
obj["value"] = new JsonValue(long.MaxValue);
var json = obj.ToString();
obj = JsonObject.Parse(json);
((JsonValue)obj["value"]).Value.ShouldEqual(long.MaxValue);
}
示例5: SettingUndefinedAsFieldValueRemovesField
public void SettingUndefinedAsFieldValueRemovesField()
{
dynamic person = new JsonObject();
person.FirstName = "Mikael";
person.LastName = "Waltersson";
person.FirstName = Undefined.Value;
Assert.Equal(new[] { "LastName" }, person.GetPropertyNames());
}
示例6: dynamic_case
public void dynamic_case()
{
dynamic jobject = new JsonObject();
jobject.name = "test";
jobject.value = 1;
jobject.list = new object[] { 5, "test" };
string json = jobject.ToString();
json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}");
}
示例7: general_case
public void general_case()
{
var jobject = new JsonObject();
jobject["name"] = new JsonValue("test");
jobject["value"] = new JsonValue(1);
jobject["list"] = new JsonArray { new JsonValue(5), new JsonValue("test") };
var json = jobject.ToString();
json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}");
}
示例8: anonymous_case
public void anonymous_case()
{
var obj = new
{
name = "test",
value = 1,
list = new object[] { 5, "test" }
};
var json = new JsonObject(obj).ToString();
json.ShouldEqual("{\"name\":\"test\",\"value\":1,\"list\":[5,\"test\"]}");
}
示例9: opIndexer_int
public void opIndexer_int()
{
var expected = new JsonObject();
var document = new JsonDocument
{
expected
};
var actual = document[0];
Assert.Equal(expected, actual);
}
示例10: opIndexer_int
public void opIndexer_int()
{
var expected = new JsonPair("name", "value");
var document = new JsonObject
{
expected
};
var actual = document[0];
Assert.Equal(expected, actual);
}
示例11: op_Add_JsonObject
public void op_Add_JsonObject()
{
var expected = new JsonObject();
var document = new JsonDocument
{
expected
};
var actual = document.First();
Assert.Equal(expected, actual);
}
示例12: op_GetEnumerator
public void op_GetEnumerator()
{
var expected = new JsonObject();
IEnumerable document = new JsonDocument
{
expected
};
foreach (var actual in document)
{
Assert.Equal(expected, actual);
}
}
示例13: opIndexer_string
public void opIndexer_string()
{
const string name = "name";
var expected = new JsonPair(name, "value");
var document = new JsonObject
{
expected
};
var actual = document[name];
Assert.Equal(expected, actual);
}
示例14: ShouldCastToDynamicAsRawJson
public void ShouldCastToDynamicAsRawJson()
{
var jsonObject = new JsonObject("{\"_id\":\"8A7FD19B\",\"_rev\":\"1-42\",\"type\":\"simpleEntity\",\"name\":\"John\"}");
dynamic dynamicObject = jsonObject;
Assert.Null((string)dynamicObject.Id);
Assert.Null((string)dynamicObject.Revision);
Assert.Null((string)dynamicObject.Type);
Assert.Equal("8A7FD19B", (string)dynamicObject._id);
Assert.Equal("1-42", (string)dynamicObject._rev);
Assert.Equal("simpleEntity", (string)dynamicObject.type);
Assert.Equal("John", (string)dynamicObject.name);
}
示例15: Ctor_IEnumerable
public void Ctor_IEnumerable()
{
// Workaround xunit/xunit#987: InvalidOperationException thrown if this is in MemberData
KeyValuePair<string, JsonValue>[] items = new KeyValuePair<string, JsonValue>[] { new KeyValuePair<string, JsonValue>("key", new JsonPrimitive(true)) };
JsonObject obj = new JsonObject((IEnumerable<KeyValuePair<string, JsonValue>>)items);
Assert.Equal(items.Length, obj.Count);
for (int i = 0; i < items.Length; i++)
{
Assert.Equal(items[i].Value.ToString(), obj[items[i].Key].ToString());
JsonValue value;
Assert.True(obj.TryGetValue(items[i].Key, out value));
Assert.Equal(items[i].Value.ToString(), value.ToString());
}
}