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