public void TestIsTablePartitioned()
        {
            // Partitioning not enabled
            var conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName = "view1",
            };

            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionsToViewMap = null,
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionsToViewMap = new Dictionary <string, string>(),
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                    { "1", "view1" },
                    { "2", "view2" },
                    { "3", "view3" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                    { "1", "view1" },
                    { "2", "" },
                    { "3", "" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");



            // Partitioning enabled
            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = null,
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = new Dictionary <string, string>(),
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                    { "1", "view1" },
                    { "2", "view2" },
                    { "3", "view3" },
                }
            };
            Assert.IsTrue(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view2");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view3");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                    { "1", "view1" },
                    { "2", "" },
                    { "3", "" },
                }
            };
            Assert.IsTrue(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");

            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "view1",
                PartitionOnProperty = "X",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "viewIgnored" },
                    { "1", "" },
                    { "2", "" },
                    { "3", "" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == "view1");
            Assert.IsTrue(conf.GetViewForPartition("") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("1") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("2") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("3") == "view1");
        }
        public void TestGetViewForPartition()
        {
            // - no partitions defined
            var conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName = "DefaultView",
            };

            Assert.IsTrue(conf.GetViewForPartition(null) == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("X") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("x") == conf.ViewName);

            // - partitions defined but partition is disabled
            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "DefaultView",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "view0" },
                    { "X", "view1" },
                    { "Y", "view2" },
                    { "Z", "" },
                }
            };
            Assert.IsTrue(conf.GetViewForPartition(null) == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("X") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("x") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("Z") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("z") == conf.ViewName);

            // - partition enabled
            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "DefaultView",
                PartitionOnProperty = "SomeProperty",
                PartitionsToViewMap = null,
            };
            Assert.IsTrue(conf.GetViewForPartition(null) == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("X") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("x") == conf.ViewName);

            // - variant ...
            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "DefaultView",
                PartitionOnProperty = "SomeProperty",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "view0" },
                    { "X", "view1" },
                    { "Y", "view2" },
                    { "Z", "" },
                }
            };
            Assert.IsTrue(conf.GetViewForPartition(null) == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("A") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("a") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("X") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("x") == "view1");
            Assert.IsTrue(conf.GetViewForPartition("Y") == "view2");
            Assert.IsTrue(conf.GetViewForPartition("y") == "view2");
            Assert.IsTrue(conf.GetViewForPartition("Z") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("z") == conf.ViewName);

            // - variant ...
            conf = new ReplicatedTableConfiguredTableAccessor
            {
                ViewName            = "DefaultView",
                PartitionOnProperty = "SomeProperty",
                PartitionsToViewMap = new Dictionary <string, string>
                {
                    { "", "view0" },
                    { "X", "" },
                    { "Y", "" },
                    { "Z", "" },
                }
            };
            Assert.IsFalse(conf.IsTablePartitioned());
            Assert.IsTrue(conf.GetViewForPartition(null) == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("A") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("a") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("X") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("x") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("Y") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("y") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("Z") == conf.ViewName);
            Assert.IsTrue(conf.GetViewForPartition("z") == conf.ViewName);
        }