コード例 #1
0
        public void Test_Issue4()
        {
            var strings = new [] { "hello", "there" };
            var hron    = HRONSerializer.ObjectAsString(strings);

            List <string> resultsStrings;

            HRONObjectParseError[] errors;

            var result = HRONSerializer.TryParseObject(
                100,
                hron.ReadLines(),
                out resultsStrings,
                out errors
                );

            TestFor.Equality(true, result, "TryParseObject should succeed");
            if (TestFor.Equality(strings.Length, resultsStrings.Count, "The length of expected and result sets should be the same"))
            {
                for (var iter = 0; iter < strings.Length; ++iter)
                {
                    TestFor.Equality(strings[iter], resultsStrings[iter], "The result set should have the same value as the expected set: {0}".FormatWith(iter));
                }
            }
        }
コード例 #2
0
        public void Test_ObjectAsString()
        {
            var dic = new Dictionary <string, object>
            {
                { "A", "AA" },
                { "B", "BB" },
                { "C",
                  new Dictionary <string, object>
                  {
                      { "AAA", "AAAA" },
                      { "BBB", "BBBB" },
                  } },
            };

            var value = HRONSerializer.ObjectAsString(dic);

            const string testCase = @"=A
	AA
=B
	BB
@C
	=AAA
		AAAA
	=BBB
		BBBB"        ;

            TestFor.Equality(testCase, value, "Serialized dictionary should have the expected value");
        }
コード例 #3
0
        public static TableVersion GetTargetVersion(
            this SqlConnection conn,
            string tableName,
            out string targetStatePath
            )
        {
            if (!SyncStateDirectory.Exists)
            {
                SyncStateDirectory.Create();
            }

            targetStatePath = Path.Combine(
                SyncStateDirectory.FullName,
                Uri.EscapeDataString(
                    string.Concat(
                        conn.DataSource,
                        "_",
                        conn.Database,
                        "_",
                        tableName,
                        ".hron"
                        )
                    )
                );


            TableVersion targetVersion;

            HRONObjectParseError[] errors;
            if (
                File.Exists(targetStatePath) &&
                HRONSerializer.TryParseObject(
                    0,
                    File.ReadAllText(targetStatePath, Encoding.UTF8).ReadLines(),
                    out targetVersion,
                    out errors
                    ))
            {
                return(targetVersion);
            }

            var tableVersion = new TableVersion
            {
                CurrentVersion  = -1,
                MinValidVersion = -1
            };

            File.WriteAllText(
                targetStatePath,
                HRONSerializer.ObjectAsString(
                    tableVersion
                    ),
                Encoding.UTF8
                );
            return(tableVersion);
        }
コード例 #4
0
ファイル: SyncJob.cs プロジェクト: ztxyzu/SqlBulkSync
 public void Save(string jobPath)
 {
     File.WriteAllText(
         jobPath,
         HRONSerializer.ObjectAsString(
             this
             ),
         Encoding.UTF8
         );
 }
コード例 #5
0
 public static void PersistsSourceTargetVersionState(this TableSchema tableSchema)
 {
     File.WriteAllText(
         tableSchema.TargetStatePath,
         HRONSerializer.ObjectAsString(
             tableSchema.SourceVersion
             ),
         Encoding.UTF8
         );
 }
コード例 #6
0
        public void Test_NameValueCollection()
        {
            var nvc = new NameValueCollection
            {
                { "Key1", "Value1" },
                { "Key1", "Value2" },
                { "Key1", "Value3" }
            };

            var value = HRONSerializer.ObjectAsString(nvc);

            // This test case is just to test that NameValueCollection doesn't crash the serializer
        }
コード例 #7
0
        public void Test_TryParseObject()
        {
            var    lines = s_test2_hron.ReadLines().ToArray();
            Config config;

            HRONObjectParseError[] errors;
            var result = HRONSerializer.TryParseObject(int.MaxValue, lines, out config, out errors);

            if (TestFor.Equality(true, result, "HRON should be parsed successfully"))
            {
                var value = HRONSerializer.ObjectAsString(config);

                TestFor.Equality(
                    s_test2_hron,
                    value,
                    "HRON after deserialize/serialize to object should be identical to test case"
                    );
            }
        }