本文整理汇总了C#中StringBuilder.AppendSerialization方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.AppendSerialization方法的具体用法?C# StringBuilder.AppendSerialization怎么用?C# StringBuilder.AppendSerialization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuilder
的用法示例。
在下文中一共展示了StringBuilder.AppendSerialization方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize_ResultFromAppendSerialization_ReturnsOriginalObject
public void Deserialize_ResultFromAppendSerialization_ReturnsOriginalObject()
{
List<String> source = GenerateRandomListOfString();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendSerialization(source);
String serializedString = stringBuilder.ToString();
List<String> result = serializedString.Deserialize<List<String>>();
Assert.IsNotNull(result);
Assert.AreEqual(String.Join(",", source), String.Join(",", result));
}
示例2: AppendSerialization_CustomFormatterForEnumerable_SerializeMethodOfFormatterCalledWithEnumerableToList
AppendSerialization_CustomFormatterForEnumerable_SerializeMethodOfFormatterCalledWithEnumerableToList()
{
String[] list = GenerateRandomListOfString().ToArray();
IEnumerable<String> enumerable = list;
Mock<IFormatter> mockFormatter = new Mock<IFormatter>();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendSerialization(enumerable, formatter: mockFormatter.Object);
String result = stringBuilder.ToString();
mockFormatter.Verify(f => f.Serialize(It.IsAny<Stream>(), It.IsAny<List<String>>()), Times.Once(),
"The IEnumerable should be converted to a list before being sent to the formatter.");
mockFormatter.Verify(f => f.Serialize(It.IsAny<Stream>(), list), Times.Once());
}
示例3: AppendSerialization_CustomFormatter_SerializeMethodOfFormatterCalledWithObj
public void AppendSerialization_CustomFormatter_SerializeMethodOfFormatterCalledWithObj()
{
object obj = Random.RandomString();
Mock<IFormatter> mockFormatter = new Mock<IFormatter>();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendSerialization(obj, formatter: mockFormatter.Object);
String result = stringBuilder.ToString();
mockFormatter.Verify(f => f.Serialize(It.IsAny<Stream>(), obj), Times.Once());
}
示例4: AppendSerialization_NullInput_ThrowsArgumentNullException
public void AppendSerialization_NullInput_ThrowsArgumentNullException()
{
StringBuilder stringBuilder = new StringBuilder();
// ReSharper disable AssignNullToNotNullAttribute
stringBuilder.AppendSerialization(null);
// ReSharper restore AssignNullToNotNullAttribute
String result = stringBuilder.ToString();
Assert.AreEqual("", result);
}
示例5: AppendSerialization_UnicodeStringsInputAsObject_StringBuilderContainsValidBase64
public void AppendSerialization_UnicodeStringsInputAsObject_StringBuilderContainsValidBase64()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendSerialization((Object) Random.RandomString());
String result = stringBuilder.ToString();
Assert.AreNotEqual("", result);
Assert.IsTrue(ValidBase64.IsMatch(result));
}
示例6: AppendSerialization_ListOfIntsInput_StringBuilderContainsValidBase64
public void AppendSerialization_ListOfIntsInput_StringBuilderContainsValidBase64()
{
StringBuilder stringBuilder = new StringBuilder();
List<int> listOfInts = Enumerable.Range(Random.Next(1, 1000), Random.Next(10, 1000)).ToList();
stringBuilder.AppendSerialization(listOfInts);
String result = stringBuilder.ToString();
Assert.AreNotEqual("", result);
Assert.IsTrue(ValidBase64.IsMatch(result));
}