Ejemplo n.º 1
0
        public void AddReferenceDatabase_BinaryWrongVersionLoading()
        {
            AddReferenceDatabase db = new AddReferenceDatabase(ArdbVersion.Current);

            db.AddUniqueMembers(PackageDatabaseTests.BuildDefaultSample());

            // Overwrite version with '9' and verify binary format won't load
            Verify.RoundTrip(db, new AddReferenceDatabase(), (w) => w.Write(9));
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
0
        public void AddReferenceDatabase_NewlineFlexibility()
        {
            PackageDatabase db = PackageDatabaseTests.BuildDefaultSample();

            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);

            ardb.AddUniqueMembers(db);
            string originalTextFormat = Write.ToString(ardb.WriteText);

            // Ensure non-Windows newlines don't trip up ReadText
            string modifiedNewlines    = originalTextFormat.Replace("\r\n", "\n");
            AddReferenceDatabase ardb2 = new AddReferenceDatabase(ArdbVersion.Current);

            Read.FromString(ardb2.ReadText, modifiedNewlines);

            // Verify everything in the ARDB round-tripped to validate read success
            string roundTripped = Write.ToString(ardb2.WriteText);

            Assert.AreEqual(originalTextFormat, roundTripped);
        }
Ejemplo n.º 5
0
        public void AddReferenceDatabase_DuplicateMerging()
        {
            int defaultArdbMemberCount, addedDefaultSampleDataMemberCount;
            AddReferenceDatabase ardb = new AddReferenceDatabase(ArdbVersion.Current);
            PackageDatabase      db   = PackageDatabaseTests.BuildDefaultSample();

            defaultArdbMemberCount = ardb.DeclaredMembers.Count;

            // Add the database once
            ardb.AddUniqueMembers(db);
            int memberCount = ardb.DeclaredMembers.Count;

            addedDefaultSampleDataMemberCount = (ardb.DeclaredMembers.Count - defaultArdbMemberCount);

            db = PackageDatabaseTests.BuildDefaultSample(Guid.NewGuid().ToString());

            // Change only the package name. We should see no change
            // in member count, since all package contents are duped.
            memberCount = ardb.DeclaredMembers.Count;
            ardb.AddUniqueMembers(db);
            Assert.AreEqual(memberCount, ardb.DeclaredMembers.Count);

            db = PackageDatabaseTests.BuildDefaultSample(Guid.NewGuid().ToString());

            // Add allowing duplicates should add the same number of
            // new members as fresh construction of the sample data
            // + 2 (to account for a duplicated type and for
            // an added assembly node).
            memberCount = ardb.DeclaredMembers.Count + addedDefaultSampleDataMemberCount;
            ardb.AddReferenceAssemblyTypes(db);
            Assert.AreEqual(memberCount + 2, ardb.DeclaredMembers.Count);

            // Write the ARDB tree [debuggability]
            string result = Write.ToString(ardb.WriteText);

            Trace.WriteLine(result);
        }
Ejemplo n.º 6
0
        private void VerifyQueryResults(AddReferenceDatabase ardb, ArdbVersion version)
        {
            // "Diagnostics."
            MemberQuery           query   = new MemberQuery(PackageDatabaseTests.NS_DIAGNOSTICS + ".", false, false);
            PartialArray <Symbol> results = new PartialArray <Symbol>(10);

            query.TryFindMembers(ardb, ref results);
            Assert.AreEqual(3, results.Count);
            Assert.AreEqual("Logger, Memory, TraceWatch", PackageDatabaseTests.ResultNamesToString(results));

            if (version == ArdbVersion.V1)
            {
                // V1 has no TFM data. This call also verifies that most current client
                // can query older format without raising an exception.
                Assert.AreEqual(String8.Empty, ardb.GetFrameworkTargets(results[0].Index));
                return;
            }

            for (int i = 0; i < results.Count; i++)
            {
                Symbol symbol = results[i];
                string fx     = ardb.GetFrameworkTargets(symbol.Index).ToString();

                if (symbol.Name.ToString() == "TraceWatch")
                {
                    Assert.AreEqual(PackageDatabaseTests.NET20, fx);
                }
                else if (symbol.Name.ToString() == "Memory")
                {
                    Assert.AreEqual(PackageDatabaseTests.NET35, fx);
                }
                else
                {
                    Assert.AreEqual(@"<tfms><tfm>net20</tfm><tfm>net35</tfm></tfms>", fx);
                }
            }
        }
Ejemplo n.º 7
0
        public void MergedMembersDatabase_Merging()
        {
            MergedMembersDatabase db = new MergedMembersDatabase();
            DatabaseAddResult     result;
            string lastAddResult;

            PackageDatabase source = PackageDatabaseTests.BuildDefaultSample();

            source.Identity.PackageName = "V1";
            result        = db.Add(source, ArdbVersion.Current);
            lastAddResult = Write.ToString(result.WriteMemberResults);
            Trace.WriteLine("First Sample Import:\r\n" + lastAddResult);
            Trace.WriteLine(Write.ToString(result.WriteDuplicateComponents));

            // Sample has at least one unique thing
            Assert.IsTrue(result.WasMemberAdded[0].Value);

            // Memory class is included
            Assert.IsTrue(result.WasMemberAdded[ItemTreeTests.FindByPath(source.DeclaredMembers, source.StringStore, DIAGNOSTICS_NAMESPACE_REF35 + "|Memory", PackageDatabaseTests.SEPARATOR_CHAR)].Value);

            // FromGigabytes member is ignored (not a type)
            Assert.IsFalse(result.WasMemberAdded[ItemTreeTests.FindByPath(source.DeclaredMembers, source.StringStore, DIAGNOSTICS_NAMESPACE_REF35 + "|Memory|FromGigabytes", PackageDatabaseTests.SEPARATOR_CHAR)].HasValue);

            // Add the source again (a complete duplicate)
            source.Identity.PackageName = "V2";
            result        = db.Add(source, ArdbVersion.Current);
            lastAddResult = Write.ToString(result.WriteMemberResults);
            Trace.WriteLine("Duplicate Sample Import:\r\n" + lastAddResult);
            Trace.WriteLine(Write.ToString(result.WriteDuplicateComponents));

            // Verify nothing is unique this time
            Assert.IsFalse(result.WasMemberAdded[0].Value);

            // Add a new public class to the sample (should be added)
            MutableSymbol diagnostics = source.MutableRoot.FindByFullName(DIAGNOSTICS_NAMESPACE_LIB20, PackageDatabaseTests.SEPARATOR_CHAR);

            diagnostics.AddChild(new MutableSymbol("TraceWatch", SymbolType.Class)
            {
                Modifiers = SymbolModifier.Public | SymbolModifier.Static
            });

            // Add a new method to Logger (no effect)
            MutableSymbol logger = source.MutableRoot.FindByFullName(DIAGNOSTICS_NAMESPACE_LIB20 + "|Logger", PackageDatabaseTests.SEPARATOR_CHAR);

            logger.AddChild(new MutableSymbol("LogTime", SymbolType.Method)
            {
                Modifiers = SymbolModifier.Public
            });

            // Add the source with additions, verify something is new
            source.Identity.PackageName = "V3";
            result        = db.Add(source, ArdbVersion.Current);
            lastAddResult = Write.ToString(result.WriteMemberResults);
            Trace.WriteLine("Sample with additions Import:\r\n" + lastAddResult);
            Trace.WriteLine(Write.ToString(result.WriteDuplicateComponents));
            Assert.IsTrue(result.WasMemberAdded[0].Value);

            // Verify Diagnostics contains changes
            Assert.IsTrue(result.WasMemberAdded[ItemTreeTests.FindByPath(source.DeclaredMembers, source.StringStore, DIAGNOSTICS_NAMESPACE_LIB20, PackageDatabaseTests.SEPARATOR_CHAR)].Value);

            // Verify Logger wasn't considered changed
            Assert.IsFalse(result.WasMemberAdded[ItemTreeTests.FindByPath(source.DeclaredMembers, source.StringStore, TYPE_LOGGER, PackageDatabaseTests.SEPARATOR_CHAR)].Value);

            // Add a new private class to the sample (should not be added)
            diagnostics.AddChild(new MutableSymbol("SmartTimer", SymbolType.Class)
            {
                Modifiers = SymbolModifier.Internal
            });

            // Add the source again, verify nothing is new
            source.Identity.PackageName = "V4";
            result        = db.Add(source, ArdbVersion.Current);
            lastAddResult = Write.ToString(result.WriteMemberResults);
            Trace.WriteLine("Sample with private class Import:\r\n" + lastAddResult);
            Trace.WriteLine(Write.ToString(result.WriteDuplicateComponents));
            Assert.IsFalse(result.WasMemberAdded[0].Value);

            Trace.WriteLine(Write.ToString((w) => db.WriteMergedTree(w)));
        }
Ejemplo n.º 8
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));
        }