public void AddSetDependency_UnitTest()
        {
            String       key  = default(String);
            ICatalogNode node = default(ICatalogNode);

            ExecuteMethod(
                () => { return((ICatalogDependencyGroup)GetInstance()); },
                instance =>
            {
                key  = default(String);    //No Constructor
                node = CatalogNodeImpl_UnitTests.GetInstance();
                AddSetDependency_PreCondition(instance, ref key, ref node);
            },
                instance => { instance.AddSetDependency(key, node); },
                instance => { AddSetDependency_PostValidate(instance, key, node); });
        }
Beispiel #2
0
 partial void ParentPath_SetCondition(ref ICatalogNode instance, ref String setValue);
Beispiel #3
0
 partial void ParentNode_SetCondition(ref ICatalogNode instance, ref ICatalogNode setValue);
        public void CatalogsTreeBuilder_BuildTree_DirectoryFacadeWithOnlyCatalogs_CorrectlyBuildTree()
        {
            // Arrange

            List <Catalog> catalogs = new List <Catalog>
            {
                new Catalog {
                    Id = 1, Name = "Catalog1", ParentCatalogId = 0, OrderInParentCatalog = 1
                },
                new Catalog {
                    Id = 2, Name = "Catalog2", ParentCatalogId = 0, OrderInParentCatalog = 2
                },
                new Catalog {
                    Id = 3, Name = "SubCatalog1", ParentCatalogId = 1, OrderInParentCatalog = 1
                },
                new Catalog {
                    Id = 4, Name = "SubCatalog2", ParentCatalogId = 1, OrderInParentCatalog = 2
                },
                new Catalog {
                    Id = 5, Name = "SubSubCatalog1", ParentCatalogId = 3, OrderInParentCatalog = 1
                }
            };
            Mock <IDirectorySystemFacade> mockDirectorySystemFacade = new Mock <IDirectorySystemFacade>(MockBehavior.Strict);

            foreach (Catalog catalog in catalogs)
            {
                List <Catalog> currSubcatalogs = new List <Catalog>();
                foreach (Catalog subcatalog in catalogs.FindAll(x => x.ParentCatalogId == catalog.Id))
                {
                    currSubcatalogs.Add(subcatalog);
                }
                mockDirectorySystemFacade.Setup(m => m.GetSubcatalogs(It.Is <int>(id => id == catalog.Id))).Returns <int>(x => currSubcatalogs);
            }
            mockDirectorySystemFacade.Setup(m => m.GetSubcatalogs(It.Is <int>(id => id == 0)))
            .Returns <int>(x => catalogs.FindAll(catalog => catalog.ParentCatalogId == 0));

            // Act

            CatalogNode expectedTree = new CatalogNode
            {
                ChildrenNodes = new List <ICatalogNode>
                {
                    new CatalogNode
                    {
                        Id            = 1, Name = "Catalog1", Order = 1,
                        ChildrenNodes = new List <ICatalogNode>
                        {
                            new CatalogNode
                            {
                                Id            = 3, Name = "SubCatalog1", Order = 1,
                                ChildrenNodes = new List <ICatalogNode>
                                {
                                    new CatalogNode
                                    {
                                        Id            = 5, Name = "SubSubCatalog1", Order = 1,
                                        ChildrenNodes = new List <ICatalogNode>()
                                    }
                                },
                            },
                            new CatalogNode
                            {
                                Id            = 4, Name = "SubCatalog2", Order = 2,
                                ChildrenNodes = new List <ICatalogNode>()
                            }
                        },
                    },
                    new CatalogNode
                    {
                        Id            = 2, Name = "Catalog2", Order = 2,
                        ChildrenNodes = new List <ICatalogNode>()
                    }
                }
            };
            CatalogsTreeBuilder <CatalogNode> catalogsTreeBuilder = new CatalogsTreeBuilder <CatalogNode>(mockDirectorySystemFacade.Object);
            CatalogNode tree = catalogsTreeBuilder.BuildTree();

            // Assert

            List <ICatalogNode> expectedNodesOnCurrDepthLevel = expectedTree.ChildrenNodes;
            List <ICatalogNode> actualNodesOnCurrDepthLevel   = tree.ChildrenNodes;

            while (expectedNodesOnCurrDepthLevel.Count > 0 && actualNodesOnCurrDepthLevel.Count > 0)
            {
                List <ICatalogNode> expectedNodesOnNextDepthLevel = new List <ICatalogNode>();
                List <ICatalogNode> actualNodesOnNextDepthLevel   = new List <ICatalogNode>();
                Assert.Equal(expectedNodesOnCurrDepthLevel.Count, actualNodesOnCurrDepthLevel.Count);
                for (int i = 0; i < expectedNodesOnCurrDepthLevel.Count; i++)
                {
                    ICatalogNode expectedCatalogNode = expectedNodesOnCurrDepthLevel[i];
                    ICatalogNode actualCatalogNode   = actualNodesOnCurrDepthLevel[i];
                    expectedNodesOnNextDepthLevel.AddRange(expectedCatalogNode.ChildrenNodes);
                    actualNodesOnNextDepthLevel.AddRange(actualCatalogNode.ChildrenNodes);

                    Assert.Equal(expectedCatalogNode.Id, actualCatalogNode.Id);
                    Assert.Equal(expectedCatalogNode.Name, actualCatalogNode.Name);
                    Assert.Equal(expectedCatalogNode.Order, actualCatalogNode.Order);
                }
                expectedNodesOnCurrDepthLevel = expectedNodesOnNextDepthLevel;
                actualNodesOnCurrDepthLevel   = actualNodesOnNextDepthLevel;
            }
            mockDirectorySystemFacade.VerifyAll();
        }
 partial void SetSingletonDependency_PostValidate(ICatalogDependencyGroup instance, String key, ICatalogNode node);
Beispiel #6
0
 partial void Resource_SetCondition(ref ICatalogNode instance, ref ICatalogResource setValue);
Beispiel #7
0
 partial void QueryParents_PostValidate(ICatalogNode instance, IEnumerable <Guid> resourceTypeFilters, Boolean recurseToRoot, ICatalogQueryOptions queryOptions);
Beispiel #8
0
 partial void QueryDependents_PostValidate(ICatalogNode instance, ICatalogQueryOptions queryOptions);
Beispiel #9
0
 partial void CreateChild_PostValidate(ICatalogNode instance, Guid resourceTypeIdentifier, String resourceDisplayName);
Beispiel #10
0
 partial void CatalogTree_SetCondition(ref ICatalogNode instance, ref ICatalogTree setValue);
Beispiel #11
0
 partial void CatalogNode_SetCondition(ref ITfsConnection instance, ref ICatalogNode setValue);
 /// <summary>
 ///     Removes the set dependency.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="node">The node.</param>
 /// <exception cref="DynCon.OSI.Core.Helpers.ToBeImplementedException"></exception>
 void ICatalogDependencyGroup.RemoveSetDependency(String key, ICatalogNode node)
 {
     throw new ToBeImplementedException();
 }
 /// <summary>
 ///     Sets the singleton dependency.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="node">The node.</param>
 /// <exception cref="DynCon.OSI.Core.Helpers.ToBeImplementedException"></exception>
 void ICatalogDependencyGroup.SetSingletonDependency(String key, ICatalogNode node)
 {
     throw new ToBeImplementedException();
 }
Beispiel #14
0
 partial void AddSetDependency_PreCondition(ICatalogDependencyGroup instance, ref String key, ref ICatalogNode node)
 {
     key = "TestKey";
 }
Beispiel #15
0
 partial void QueryChildren_PostValidate(ICatalogNode instance, IEnumerable <Guid> resourceTypeFilters, IEnumerable <KeyValuePair <String, String> > propertyFilters, Boolean recurse, ICatalogQueryOptions queryOptions);
Beispiel #16
0
 partial void QueryChildren_PreCondition(ICatalogNode instance, ref IEnumerable <Guid> resourceTypeFilters, ref IEnumerable <KeyValuePair <String, String> > propertyFilters, ref Boolean recurse, ref ICatalogQueryOptions queryOptions);
Beispiel #17
0
 partial void CreateChild_PreCondition(ICatalogNode instance, ref Guid resourceTypeIdentifier, ref String resourceDisplayName);
Beispiel #18
0
 partial void QueryDependents_PreCondition(ICatalogNode instance, ref ICatalogQueryOptions queryOptions);
Beispiel #19
0
 partial void Dependencies_SetCondition(ref ICatalogNode instance, ref ICatalogDependencyGroup setValue);
Beispiel #20
0
 partial void QueryParents_PreCondition(ICatalogNode instance, ref IEnumerable <Guid> resourceTypeFilters, ref Boolean recurseToRoot, ref ICatalogQueryOptions queryOptions);
Beispiel #21
0
 partial void ExpandDependencies_PostValidate(ICatalogNode instance);
Beispiel #22
0
 partial void ExpandDependencies_PreCondition(ICatalogNode instance);
Beispiel #23
0
 partial void IsDefault_SetCondition(ref ICatalogNode instance, ref Boolean setValue);
 partial void SetSingletonDependency_PreCondition(ICatalogDependencyGroup instance, ref String key, ref ICatalogNode node);
        public void CatalogsTreeBuilder_BuildTree_DirectoryFacadeWithCatalogsAndTextBlocks_CorrectlyBuildedTree()
        {
            // Arrange

            List <Catalog> allCatalogs = new List <Catalog>
            {
                new Catalog {
                    Id = 1, Name = "Catalog1", ParentCatalogId = 0, OrderInParentCatalog = 1
                },
                new Catalog {
                    Id = 2, Name = "Catalog2", ParentCatalogId = 0, OrderInParentCatalog = 2
                },
                new Catalog {
                    Id = 3, Name = "SubCatalog1", ParentCatalogId = 1, OrderInParentCatalog = 1
                },
                new Catalog {
                    Id = 4, Name = "SubCatalog2", ParentCatalogId = 1, OrderInParentCatalog = 2
                },
                new Catalog {
                    Id = 5, Name = "SubSubCatalog1", ParentCatalogId = 3, OrderInParentCatalog = 1
                }
            };
            List <TextBlock> allTextBlocks = new List <TextBlock>
            {
                new TextBlock {
                    Id = 1, Name = "TextBlock1", Text = "Text1", ParentCatalogId = 0, OrderInParentCatalog = 3
                },
                new TextBlock {
                    Id = 2, Name = "TextBlock2", Text = "Text2", ParentCatalogId = 1, OrderInParentCatalog = 3
                },
                new TextBlock {
                    Id = 3, Name = "TextBlock3", Text = "Text3", ParentCatalogId = 3, OrderInParentCatalog = 2
                },
                new TextBlock {
                    Id = 4, Name = "TextBlock4", Text = "Text4", ParentCatalogId = 4, OrderInParentCatalog = 1
                }
            };
            Mock <IDirectorySystemFacade> mockDirectorySystemFacade = new Mock <IDirectorySystemFacade>(MockBehavior.Strict);

            foreach (Catalog catalog in allCatalogs)
            {
                List <Catalog>   currSubcatalogs = new List <Catalog>();
                List <TextBlock> currTextBlocks  = new List <TextBlock>();
                foreach (Catalog subcatalog in allCatalogs.FindAll(x => x.ParentCatalogId == catalog.Id))
                {
                    currSubcatalogs.Add(subcatalog);
                }
                foreach (TextBlock textBlock in allTextBlocks.FindAll(x => x.ParentCatalogId == catalog.Id))
                {
                    currTextBlocks.Add(textBlock);
                }
                mockDirectorySystemFacade.Setup(m => m.GetSubcatalogs(It.Is <int>(id => id == catalog.Id))).Returns <int>(x => currSubcatalogs);
                mockDirectorySystemFacade.Setup(m => m.GetCatalogAttachments(It.Is <int>(id => id == catalog.Id))).Returns <int>(x => currTextBlocks);
            }
            mockDirectorySystemFacade.Setup(m => m.GetSubcatalogs(It.Is <int>(id => id == 0)))
            .Returns <int>(x => allCatalogs.FindAll(catalog => catalog.ParentCatalogId == 0));

            mockDirectorySystemFacade.Setup(m => m.GetCatalogAttachments(It.Is <int>(id => id == 0)))
            .Returns <int>(x => allTextBlocks.FindAll(textBlock => textBlock.ParentCatalogId == 0));

            // Act

            CatalogNode expectedTree = new CatalogNode
            {
                ChildrenNodes = new List <ICatalogNode>
                {
                    new CatalogNode
                    {
                        Id = 1, Name = "Catalog1", Order = 1,
                        CatalogAttachments = new List <TextBlock>
                        {
                            new TextBlock {
                                Id = 2, Name = "TextBlock2", Text = "Text2", ParentCatalogId = 1, OrderInParentCatalog = 3
                            }
                        },
                        ChildrenNodes = new List <ICatalogNode>
                        {
                            new CatalogNode
                            {
                                Id = 3, Name = "SubCatalog1", Order = 1,
                                CatalogAttachments = new List <TextBlock>
                                {
                                    new TextBlock {
                                        Id = 3, Name = "TextBlock3", Text = "Text3", ParentCatalogId = 3, OrderInParentCatalog = 2
                                    }
                                },
                                ChildrenNodes = new List <ICatalogNode>
                                {
                                    new CatalogNode
                                    {
                                        Id            = 5, Name = "SubSubCatalog1", Order = 1,
                                        ChildrenNodes = new List <ICatalogNode>()
                                    }
                                }
                            },
                            new CatalogNode
                            {
                                Id                 = 4, Name = "SubCatalog2", Order = 2,
                                ChildrenNodes      = new List <ICatalogNode>(),
                                CatalogAttachments = new List <TextBlock>
                                {
                                    new TextBlock {
                                        Id = 4, Name = "TextBlock4", Text = "Text4", ParentCatalogId = 4, OrderInParentCatalog = 1
                                    }
                                }
                            }
                        },
                    },
                    new CatalogNode
                    {
                        Id            = 2, Name = "Catalog2", Order = 2,
                        ChildrenNodes = new List <ICatalogNode>()
                    }
                },
                CatalogAttachments = new List <TextBlock>
                {
                    new TextBlock {
                        Id = 1, Name = "TextBlock1", Text = "Text1", ParentCatalogId = 0, OrderInParentCatalog = 3
                    }
                }
            };
            CatalogsTreeBuilder <CatalogNode> catalogsTreeBuilder = new CatalogsTreeBuilder <CatalogNode>(mockDirectorySystemFacade.Object);
            CatalogNode tree = catalogsTreeBuilder.BuildTree(isAddTextBlocks: true);

            // Assert

            List <ICatalogNode> expectedNodesOnCurrDepthLevel = expectedTree.ChildrenNodes;
            List <ICatalogNode> actualNodesOnCurrDepthLevel   = tree.ChildrenNodes;

            while (expectedNodesOnCurrDepthLevel.Count > 0 && actualNodesOnCurrDepthLevel.Count > 0)
            {
                List <ICatalogNode> expectedNodesOnNextDepthLevel = new List <ICatalogNode>();
                List <ICatalogNode> actualNodesOnNextDepthLevel   = new List <ICatalogNode>();
                Assert.Equal(expectedNodesOnCurrDepthLevel.Count, actualNodesOnCurrDepthLevel.Count);
                for (int i = 0; i < expectedNodesOnCurrDepthLevel.Count; i++)
                {
                    // Проверка равенства каталогов
                    ICatalogNode expectedCatalogNode = expectedNodesOnCurrDepthLevel[i];
                    ICatalogNode actualCatalogNode   = actualNodesOnCurrDepthLevel[i];
                    expectedNodesOnNextDepthLevel.AddRange(expectedCatalogNode.ChildrenNodes);
                    actualNodesOnNextDepthLevel.AddRange(actualCatalogNode.ChildrenNodes);
                    Assert.Equal(expectedCatalogNode.Id, actualCatalogNode.Id);
                    Assert.Equal(expectedCatalogNode.Name, actualCatalogNode.Name);
                    Assert.Equal(expectedCatalogNode.Order, actualCatalogNode.Order);

                    // Проверка равенства текстовых блоков
                    List <TextBlock> expectedTextBlocks = expectedCatalogNode.CatalogAttachments;
                    List <TextBlock> actualTextBlocks   = actualCatalogNode.CatalogAttachments;
                    Assert.Equal(expectedTextBlocks.Count, actualTextBlocks.Count);
                    for (int j = 0; j < expectedTextBlocks.Count; j++)
                    {
                        TextBlock currentExpectedTextBlock = expectedTextBlocks[j];
                        TextBlock currentActualTextBlock   = actualTextBlocks[j];
                        Assert.Equal(currentExpectedTextBlock.Id, currentActualTextBlock.Id);
                        Assert.Equal(currentExpectedTextBlock.Name, currentActualTextBlock.Name);
                        Assert.Equal(currentExpectedTextBlock.OrderInParentCatalog, currentActualTextBlock.OrderInParentCatalog);
                        Assert.Equal(currentExpectedTextBlock.ParentCatalogId, currentActualTextBlock.ParentCatalogId);
                        Assert.Equal(currentExpectedTextBlock.Text, currentActualTextBlock.Text);
                    }
                }
                expectedNodesOnCurrDepthLevel = expectedNodesOnNextDepthLevel;
                actualNodesOnCurrDepthLevel   = actualNodesOnNextDepthLevel;
            }
            mockDirectorySystemFacade.VerifyAll();
        }