public void ShouldRefreshCacheToForceReloadOfBdtAndBieLibrary()
        {
            // Setup
            var bdtLibraryMock       = new Mock <IBdtLibrary>();
            var bieLibraryMock       = new Mock <IBieLibrary>();
            var expectedBieLibraries = new[] { bieLibraryMock.Object };
            var expectedBdtLibraries = new[] { bdtLibraryMock.Object };
            var allLibraries         = new List <object>();

            allLibraries.AddRange(expectedBieLibraries);
            allLibraries.AddRange(expectedBdtLibraries);
            var cctsRepositoryMock = new Mock <ICctsRepository>();

            cctsRepositoryMock.Setup(r => r.GetAllLibraries()).Returns(allLibraries);

            // Events
            CcCache            ccCache      = CcCache.GetInstance(cctsRepositoryMock.Object);
            List <IBieLibrary> bieLibraries = ccCache.GetBieLibraries();
            List <IBdtLibrary> bdtLibraries = ccCache.GetBdtLibraries();

            ccCache.GetBieLibraries();
            ccCache.GetBdtLibraries();

            ccCache.Refresh();

            ccCache.GetBieLibraries();
            ccCache.GetBdtLibraries();
            ccCache.GetBieLibraries();
            ccCache.GetBdtLibraries();

            // Assertion and Verification
            Assert.That(bdtLibraries, Is.EquivalentTo(expectedBdtLibraries));
            Assert.That(bieLibraries, Is.EquivalentTo(expectedBieLibraries));
            cctsRepositoryMock.Verify(r => r.GetAllLibraries(), Times.Exactly(2));
        }
        public void ShouldGetAndCacheBieLibraries()
        {
            // Setup
            var bieLibraryMock       = new Mock <IBieLibrary>();
            var cctsRepositoryMock   = new Mock <ICctsRepository>();
            var expectedBieLibraries = new[] { bieLibraryMock.Object };

            cctsRepositoryMock.Setup(r => r.GetAllLibraries()).Returns(expectedBieLibraries);

            // Events
            CcCache            ccCache      = CcCache.GetInstance(cctsRepositoryMock.Object);
            List <IBieLibrary> bieLibraries = ccCache.GetBieLibraries();

            ccCache.GetBieLibraries();

            // Assertion and Verification
            Assert.That(bieLibraries, Is.EquivalentTo(expectedBieLibraries));
            cctsRepositoryMock.Verify(r => r.GetAllLibraries(), Times.Exactly(1));
        }
        public void createSubSet()
        {
            var abiesToRemove  = new List <String>();
            var bbiesToRemove  = new Dictionary <String, List <String> >();
            var asbiesToRemove = new Dictionary <String, List <String> >();

            followAsmasAndRemoveUnused(rootElement.OriginalMa);
            foreach (IBieLibrary bieLibrary in ccCache.GetBieLibraries())
            {
                var abies = new List <IAbie>(bieLibrary.Abies);
                foreach (IAbie abie in abies)
                {
                    List <CheckableTreeViewItem> result = findCheckableTreeViewItems(abie.Name, mCandidateAbieItems);
                    if (result.Count == 0)
                    {
                        abiesToRemove.Add(abie.Name);
                        bieLibrary.RemoveAbie(abie);
                    }
                    else
                    {
                        if (testIfAllCheckableTreeViewItemsAreUnchecked(result))
                        {
                            abiesToRemove.Add(abie.Name);
                            bieLibrary.RemoveAbie(abie);
                        }
                        else
                        {
                            CandidateAbie candidateAbie = findAbie(abie.Name, rootElement.CandidateAbies);
                            //update asbies
                            if (candidateAbie.PotentialAsbies != null)
                            //if the potentialAsbies are null the user hasn't even looked at them.. nothing to do!
                            {
                                if (candidateAbie.PotentialAsbies.Count == 0)
                                //for now this is almost always 0.. so we will examine children also!
                                {
                                    foreach (CheckableTreeViewItem checkableTreeViewItem in result)
                                    {
                                        if (checkableTreeViewItem.Checked)
                                        {
                                            //remove unchecked Bbies, only if the item is not unchecked!
                                            var actualBbies = new List <IBbie>(abie.Bbies);
                                            var tempBbies   = new List <String>();
                                            if (candidateAbie.PotentialBbies != null)
                                            {
                                                foreach (IBbie bbie in actualBbies)
                                                {
                                                    foreach (PotentialBbie potentialBbie in candidateAbie.PotentialBbies)
                                                    {
                                                        if (bbie.Name.Equals(potentialBbie.Name))
                                                        {
                                                            if (!potentialBbie.Checked)
                                                            {
                                                                tempBbies.Add(bbie.Name + bbie.Bdt.Name);
                                                                abie.RemoveBbie(bbie);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            bbiesToRemove.Add(abie.Name, tempBbies);
                                        }
                                        //examine children to find obsolete asbies
                                        foreach (CheckableTreeViewItem child in checkableTreeViewItem.Children)
                                        {
                                            if (!child.Checked)
                                            {
                                                var tmpAsbies = new List <String>();
                                                foreach (IAsbie asbie in candidateAbie.OriginalAbie.Asbies)
                                                {
                                                    if (asbie.AssociatedAbie.Name.Equals(child.Text))
                                                    {
                                                        tmpAsbies.Add(asbie.Name);
                                                        candidateAbie.OriginalAbie.RemoveAsbie(asbie);
                                                    }
                                                }
                                                asbiesToRemove.Add(abie.Name, tmpAsbies);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    IEnumerable <IAsbie> originalAsbies = candidateAbie.OriginalAbie.Asbies;
                                    var tmpAsbies = new List <String>();
                                    foreach (IAsbie asbie in originalAsbies)
                                    {
                                        foreach (PotentialAsbie potentialAsbie in candidateAbie.PotentialAsbies)
                                        {
                                            if (potentialAsbie.Name.Equals(asbie.Name))
                                            {
                                                if (!potentialAsbie.Checked)
                                                {
                                                    tmpAsbies.Add(asbie.Name);
                                                    candidateAbie.OriginalAbie.RemoveAsbie(asbie);
                                                }
                                            }
                                        }
                                    }
                                    asbiesToRemove.Add(abie.Name, tmpAsbies);
                                }
                            }
                        }
                    }
                }
            }
            if (!namespacePrefix.Equals(String.Empty) && !targetNamespace.Equals(String.Empty))
            {
                writeSchematronRules(abiesToRemove, bbiesToRemove, asbiesToRemove);
            }
        }