Exemple #1
0
        public void AddReferenceDatabase_PackagePrereleaseVersion()
        {
            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);
            // Build and add the sample PackageDatabase
            PackageDatabase source = PackageDatabaseTests.BuildPreleaseSample();

            ardb.AddUniqueMembers(source);
            ardb.ConvertToImmutable();

            MemberQuery           query   = new MemberQuery(PackageDatabaseTests.TYPE_LOGGER, false, false);
            PartialArray <Symbol> results = new PartialArray <Symbol>(10);

            query.TryFindMembers(ardb, ref results);
            Assert.AreEqual(1, results.Count);
            Assert.AreEqual(PackageDatabaseTests.PRERELEASE_VERSION, ardb.GetPackageVersion(results[0].Index).ToString());
        }
Exemple #2
0
        public void AddReferenceDatabase_PackageReleaseVersion()
        {
            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);
            // Build and add the sample PackageDatabase
            PackageDatabase source = PackageDatabaseTests.BuildDefaultSample();

            ardb.AddUniqueMembers(source);
            ardb.ConvertToImmutable();

            MemberQuery           query   = new MemberQuery(PackageDatabaseTests.TYPE_LOGGER, false, false);
            PartialArray <Symbol> results = new PartialArray <Symbol>(10);

            query.TryFindMembers(ardb, ref results);
            Assert.AreEqual(1, results.Count);

            // We shouldn't persist non-prerelease version details in the ARDB
            Assert.AreEqual(String.Empty, ardb.GetPackageVersion(results[0].Index).ToString());
        }
Exemple #3
0
        private void AddReferenceDatabaseBasicHelper(ArdbVersion version)
        {
            AddReferenceDatabase ardb = new AddReferenceDatabase(version);
            DatabaseAddResult    result;

            // Build and add the sample PackageDatabase
            PackageDatabase source = PackageDatabaseTests.BuildDefaultSample("V1");

            result = CallAddUniqueMembers(ardb, source);

            // Verify at least something was added
            int ardbCountFirstAdd = ardb.Count;

            Assert.IsTrue(result.WasMemberAdded[0].Value);

            // Add the sample again; verify nothing was added
            source = PackageDatabaseTests.BuildDefaultSample("V2");
            result = CallAddUniqueMembers(ardb, source);
            Assert.IsFalse(result.WasMemberAdded[0].Value);
            Assert.AreEqual(ardbCountFirstAdd, ardb.Count);

            // Add a namespace with a private class; verify nothing added
            source = PackageDatabaseTests.BuildDefaultSample("V3");
            MutableSymbol diagnostics = source.MutableRoot.FindByFullName(BuildDiagnosticsNamespaceFor(source.Identity.PackageName), PackageDatabaseTests.SEPARATOR_CHAR);
            MutableSymbol internalNs  = diagnostics.AddChild(new MutableSymbol("Internal", SymbolType.Namespace));

            internalNs.AddChild(new MutableSymbol("Tracer", SymbolType.Class)
            {
                Modifiers = SymbolModifier.Internal
            });
            result = CallAddUniqueMembers(ardb, source);
            Assert.IsFalse(result.WasMemberAdded[0].Value);
            Assert.AreEqual(ardbCountFirstAdd, ardb.Count);

            // Add a new public class (existing namespace); verify it is added
            source      = PackageDatabaseTests.BuildDefaultSample("V4");
            diagnostics = source.MutableRoot.FindByFullName(BuildDiagnosticsNamespaceFor(source.Identity.PackageName), PackageDatabaseTests.SEPARATOR_CHAR);
            diagnostics.AddChild(new MutableSymbol("TraceWatch", SymbolType.Class)
            {
                Modifiers = SymbolModifier.Public | SymbolModifier.Static
            });
            result = CallAddUniqueMembers(ardb, source);
            Assert.IsTrue(result.WasMemberAdded[0].Value);
            Assert.IsTrue(result.WasMemberAdded[result.WasMemberAdded.Length - 1].Value);
            Assert.AreNotEqual(ardbCountFirstAdd, ardb.Count);

            // Verify a query [expect Diagnostics. to match Logger, Memory, and TraceWatch
            ardb.ConvertToImmutable();
            VerifyQueryResults(ardb, version);

            // Double-convert ARDB. Verify queries still work correctly.
            ardb.ConvertToImmutable();
            VerifyQueryResults(ardb, version);

            // Round trip to string; verify query still right, count matches
            string sampleArdbFilePath = "Sample.ardb.txt";

            Write.ToFile(ardb.WriteText, sampleArdbFilePath);
            AddReferenceDatabase reloaded = new AddReferenceDatabase(version);

            Read.FromFile(reloaded.ReadText, sampleArdbFilePath);

            VerifyQueryResults(reloaded, version);
            Assert.AreEqual(ardb.Count, reloaded.Count);

            string sampleRewriteArdbFilePath = "Sample.Rewrite.ardb.txt";

            Write.ToFile(reloaded.WriteText, sampleRewriteArdbFilePath);
            Assert.AreEqual(File.ReadAllText(sampleArdbFilePath), File.ReadAllText(sampleRewriteArdbFilePath));
        }