Exemple #1
0
        public void SerializeToString_Writes_Empty_Collection_To_String(SeparatedValuesDelimiter delimiter)
        {
            var emptyEntities = Enumerable.Empty <SimpleEntityMock>();

            Assert.That(
                SeparatedValuesSerializer.SerializeToString(emptyEntities, delimiter),
                Is.EqualTo(String.Format("foo{0}bar", SeparatedValuesSerializer.DelimiterString(delimiter)))
                );
        }
Exemple #2
0
        public void SerializeToString_Writes_Simple_Collection_To_String(SeparatedValuesDelimiter delimiter)
        {
            string delimiterString = SeparatedValuesSerializer.DelimiterString(delimiter);

            Assert.That(
                SeparatedValuesSerializer.SerializeToString(simpleEntities, delimiter),
                Does.EndWith(String.Format(@"""{0}""{1}""{2}""", foo, delimiterString, bar))
                );
        }
Exemple #3
0
        public void SerializeToString_Can_Skip_Writing_Header_Row(SeparatedValuesDelimiter delimiter)
        {
            string delimiterString = SeparatedValuesSerializer.DelimiterString(delimiter);
            var    entities        = new[] { new { id = "my-id", name = "my-name", number = 42 } };

            Assert.That(
                SeparatedValuesSerializer.SerializeToString(entities, delimiter, false),
                Does.Not.Contain(String.Join(delimiterString, "id", "name", "number"))
                );
        }
Exemple #4
0
        public void SerializeToString_Writes_Header_Row_By_Default(SeparatedValuesDelimiter delimiter)
        {
            string delimiterString = SeparatedValuesSerializer.DelimiterString(delimiter);
            var    entities        = new[] { new { id = "my-id", name = "my-name", number = 42 } };

            Assert.That(
                SeparatedValuesSerializer.SerializeToString(entities, delimiter),
                Does.StartWith(String.Join(delimiterString, "id", "name", "number"))
                );
        }
Exemple #5
0
        public void SerializeToString_Writes_Complex_Collection_To_String(SeparatedValuesDelimiter delimiter)
        {
            string serializedSimpleEntities = String.Format("[{{\"foo\":\"{0}\",\"bar\":\"{1}\"}},{{\"foo\":\"{0}\",\"bar\":\"{1}\"}}]", foo, bar);
            string delimiterString          = SeparatedValuesSerializer.DelimiterString(delimiter);

            Assert.That(
                SeparatedValuesSerializer.SerializeToString(complexEntities, delimiter),
                Does.EndWith(String.Format(@"""complexEntity""{0}""{1}""", delimiterString, serializedSimpleEntities))
                );
        }
Exemple #6
0
        public void SerializeToString_Respects_DataContractAttribute(SeparatedValuesDelimiter delimiter)
        {
            var    dataContractEntities = new[] { new DataContractEntityMock(foo, bar, bup) };
            string delimiterString      = SeparatedValuesSerializer.DelimiterString(delimiter);

            string csvData = SeparatedValuesSerializer.SerializeToString(dataContractEntities, delimiter);

            Assert.That(
                csvData,
                Does.EndWith(String.Format("\"{0}\"{1}\"{2}\"", foo, delimiterString, bar))
                );

            Assert.That(
                csvData,
                Does.Not.Contain("bup")
                .And
                .Not.Contains(bup)
                );
        }
Exemple #7
0
 public void DelimiterString_For_Tab_Is_Tab()
 {
     Assert.AreEqual("\t", SeparatedValuesSerializer.DelimiterString(SeparatedValuesDelimiter.Tab));
 }
Exemple #8
0
 public void DelimiterString_For_Comma_Is_Comma()
 {
     Assert.AreEqual(",", SeparatedValuesSerializer.DelimiterString(SeparatedValuesDelimiter.Comma));
 }