public void Add_adds_merges_all_indexes()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 0));
            index.Add("tut3", new IndexAttribute("pong", 2) { IsClustered = true });
            index.Add("tut2", new IndexAttribute("pong", 1));

            Assert.Equal("pong", index.Index.Name);
            Assert.Equal(new[] { "tut1", "tut2", "tut3" }, index.Columns);
            Assert.True(index.Index.IsClustered);
            Assert.True(index.Index.IsClusteredConfigured);
            Assert.False(index.Index.IsUniqueConfigured);
        }
예제 #2
0
        public void Add_adds_merges_all_indexes()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 0));

            index.Add("tut3", new IndexAttribute("pong", 2)
            {
                IsClustered = true
            });
            index.Add("tut2", new IndexAttribute("pong", 1));

            Assert.Equal("pong", index.Index.Name);
            Assert.Equal(new[] { "tut1", "tut2", "tut3" }, index.Columns);
            Assert.True(index.Index.IsClustered);
            Assert.True(index.Index.IsClusteredConfigured);
            Assert.False(index.Index.IsUniqueConfigured);
        }
예제 #3
0
        public void CreateDropIndexOperation_creates_operation_and_its_inverse()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 0)
            {
                IsClustered = true, IsUnique = true
            });

            index.Add("tut2", new IndexAttribute("pong", 1));

            var operation = index.CreateDropIndexOperation();

            Assert.Equal("raS", operation.Table);
            Assert.Equal("pong", operation.Name);
            Assert.Equal(new List <string> {
                "tut1", "tut2"
            }, operation.Columns);

            var inverse = (CreateIndexOperation)operation.Inverse;

            Assert.Equal("raS", inverse.Table);
            Assert.Equal("pong", inverse.Name);
            Assert.Equal(new List <string> {
                "tut1", "tut2"
            }, inverse.Columns);
            Assert.True(inverse.IsUnique);
            Assert.True(inverse.IsClustered);
        }
        public void Add_throws_on_column_order_clashes()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 77));

            Assert.Equal(
                Strings.OrderConflictWhenConsolidating("pong", "raS", 77,  "tut1", "tut2"),
                Assert.Throws<InvalidOperationException>(() => index.Add("tut2", new IndexAttribute("pong", 77))).Message);
        }
예제 #5
0
        public void Add_throws_on_column_order_clashes()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 77));

            Assert.Equal(
                Strings.OrderConflictWhenConsolidating("pong", "raS", 77, "tut1", "tut2"),
                Assert.Throws <InvalidOperationException>(() => index.Add("tut2", new IndexAttribute("pong", 77))).Message);
        }
        public void Add_throws_when_index_of_given_name_conflicts_with_existing_index_for_that_name()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 0) { IsClustered = false });

            Assert.Equal(
                Strings.ConflictWhenConsolidating("pong", "raS", Strings.ConflictingIndexAttributeProperty("IsClustered", "False", "True")),
                Assert.Throws<InvalidOperationException>(
                    () => index.Add("tut3", new IndexAttribute("pong", 2) { IsClustered = true })).Message);
        }
예제 #7
0
        public void Add_throws_when_index_of_given_name_conflicts_with_existing_index_for_that_name()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 0)
            {
                IsClustered = false
            });

            Assert.Equal(
                Strings.ConflictWhenConsolidating("pong", "raS", Strings.ConflictingIndexAttributeProperty("IsClustered", "False", "True")),
                Assert.Throws <InvalidOperationException>(
                    () => index.Add("tut3", new IndexAttribute("pong", 2)
            {
                IsClustered = true
            })).Message);
        }
예제 #8
0
        public static IEnumerable <ConsolidatedIndex> BuildIndexes(
            string tableName,
            IEnumerable <Tuple <string, EdmProperty> > columns)
        {
            List <ConsolidatedIndex> source = new List <ConsolidatedIndex>();

            foreach (Tuple <string, EdmProperty> column in columns)
            {
                foreach (IndexAttribute indexAttribute in column.Item2.Annotations.Where <MetadataProperty>((Func <MetadataProperty, bool>)(a => a.Name == "http://schemas.microsoft.com/ado/2013/11/edm/customannotation:Index")).Select <MetadataProperty, object>((Func <MetadataProperty, object>)(a => a.Value)).OfType <IndexAnnotation>().SelectMany <IndexAnnotation, IndexAttribute>((Func <IndexAnnotation, IEnumerable <IndexAttribute> >)(a => a.Indexes)))
                {
                    IndexAttribute    index             = indexAttribute;
                    ConsolidatedIndex consolidatedIndex = index.Name == null ? (ConsolidatedIndex)null : source.FirstOrDefault <ConsolidatedIndex>((Func <ConsolidatedIndex, bool>)(i => i.Index.Name == index.Name));
                    if (consolidatedIndex == null)
                    {
                        source.Add(new ConsolidatedIndex(tableName, column.Item1, index));
                    }
                    else
                    {
                        consolidatedIndex.Add(column.Item1, index);
                    }
                }
            }
            return((IEnumerable <ConsolidatedIndex>)source);
        }
        public void CreateCreateIndexOperation_creates_operation_and_its_inverse()
        {
            var index = new ConsolidatedIndex("raS", "tut1", new IndexAttribute("pong", 0) { IsClustered = true });
            index.Add("tut2", new IndexAttribute("pong", 1));

            var operation = index.CreateCreateIndexOperation();

            Assert.Equal("raS", operation.Table);
            Assert.Equal("pong", operation.Name);
            Assert.Equal(new List<string> { "tut1", "tut2" }, operation.Columns);
            Assert.False(operation.IsUnique);
            Assert.True(operation.IsClustered);

            var inverse = (DropIndexOperation)operation.Inverse;

            Assert.Equal("raS", inverse.Table);
            Assert.Equal("pong", inverse.Name);
            Assert.Equal(new List<string> { "tut1", "tut2" }, inverse.Columns);
        }