예제 #1
0
        public void CheckAddMissingTlbReference()
        {
            TYPELIBATTR      axAttr, tlbAttr, piaAttr, notInProjectAttr;
            ComReferenceInfo axRefInfo, tlbRefInfo, piaRefInfo;

            CreateTestReferences(out axRefInfo, out tlbRefInfo, out piaRefInfo,
                                 out axAttr, out tlbAttr, out piaAttr, out notInProjectAttr);

            var rcr = new ResolveComReference();

            rcr.BuildEngine = new MockEngine();

            // populate the ResolveComReference's list of project references
            rcr.allProjectRefs = new List <ComReferenceInfo>();
            rcr.allProjectRefs.Add(axRefInfo);
            rcr.allProjectRefs.Add(tlbRefInfo);
            rcr.allProjectRefs.Add(piaRefInfo);

            rcr.AddMissingTlbReferences();

            Assert.Equal(4, rcr.allProjectRefs.Count); // "There should be four references now"

            ComReferenceInfo newTlbInfo = (ComReferenceInfo)rcr.allProjectRefs[3];

            Assert.Equal(axRefInfo.primaryOfAxImpRef, newTlbInfo);                                                                       // "axRefInfo should hold back reference to tlbRefInfo"
            Assert.True(ComReference.AreTypeLibAttrEqual(newTlbInfo.attr, axRefInfo.attr));                                              // "The added reference should have the same attributes as the Ax reference"
            Assert.Equal(newTlbInfo.typeLibName, axRefInfo.typeLibName);                                                                 // "The added reference should have the same type lib name as the Ax reference"
            Assert.Equal(newTlbInfo.strippedTypeLibPath, axRefInfo.strippedTypeLibPath);                                                 // "The added reference should have the same type lib path as the Ax reference"

            Assert.Equal(newTlbInfo.taskItem.ItemSpec, axRefInfo.taskItem.ItemSpec);                                                     // "The added reference should have the same task item spec as the Ax reference"
            Assert.Equal(newTlbInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.wrapperTool), ComReferenceTypes.primaryortlbimp); // "The added reference should have the tlbimp/primary wrapper tool"

            rcr.AddMissingTlbReferences();
            Assert.Equal(4, rcr.allProjectRefs.Count); // "There should still be four references"
        }
예제 #2
0
        /// <summary>
        /// Helper method that will new up an AX and matching TLB reference, and verify that the AX reference
        /// sets its RCW appropriately.
        /// </summary>
        private void CheckAxReferenceRCWTlbExists(RcwStyle rcwStyle, bool includeVersionInInteropName)
        {
            Guid             axGuid = Guid.NewGuid();
            ComReferenceInfo tlbRefInfo;

            var rcr = new ResolveComReference();

            rcr.BuildEngine = new MockEngine();
            rcr.IncludeVersionInInteropName = includeVersionInInteropName;
            rcr.allProjectRefs = new List <ComReferenceInfo>();

            TaskItem         axTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.aximp);
            ComReferenceInfo axRefInfo  = CreateComReferenceInfo(axTaskItem, "RefLibName", "RefLibPath");

            rcr.allProjectRefs.Add(axRefInfo);

            switch (rcwStyle)
            {
            case RcwStyle.GenerateTlb: break;

            case RcwStyle.PreexistingTlb:
            {
                TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.tlbimp, "true");
                tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath");
                rcr.allProjectRefs.Add(tlbRefInfo);
                break;
            }

            case RcwStyle.PreexistingPia:
            {
                TaskItem tlbTaskItem = CreateComReferenceTaskItem("ref", axGuid.ToString(), "1", "2", "1033", ComReferenceTypes.primary, "true");
                tlbRefInfo = CreateComReferenceInfo(tlbTaskItem, "RefLibName", "RefLibPath");
                rcr.allProjectRefs.Add(tlbRefInfo);
                break;
            }
            }

            rcr.AddMissingTlbReferences();

            Assert.Equal(2, rcr.allProjectRefs.Count); // "Should be two references"

            tlbRefInfo = rcr.allProjectRefs[1];
            var embedInteropTypes = tlbRefInfo.taskItem.GetMetadata(ItemMetadataNames.embedInteropTypes);

            Assert.Equal("false", embedInteropTypes);                                       // "The tlb wrapper for the activex control should have EmbedInteropTypes=false not " + embedInteropTypes);
            Assert.True(ComReference.AreTypeLibAttrEqual(tlbRefInfo.attr, axRefInfo.attr)); // "reference information should be the same"
            Assert.Equal(TlbReference.GetWrapperFileName
                         (
                             axRefInfo.taskItem.GetMetadata(ComReferenceItemMetadataNames.tlbReferenceName),
                             includeVersionInInteropName,
                             axRefInfo.attr.wMajorVerNum,
                             axRefInfo.attr.wMinorVerNum
                         ),
                         TlbReference.GetWrapperFileName
                         (
                             tlbRefInfo.typeLibName,
                             includeVersionInInteropName,
                             tlbRefInfo.attr.wMajorVerNum,
                             tlbRefInfo.attr.wMinorVerNum
                         )); //                     "Expected Ax reference's RCW name to match the new TLB"
        }