Exemplo n.º 1
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"
        }
        /// <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;

            ResolveComReference 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.AreEqual(2, rcr.allProjectRefs.Count, "Should be two references");

            tlbRefInfo = (ComReferenceInfo)rcr.allProjectRefs[1];
            var embedInteropTypes = tlbRefInfo.taskItem.GetMetadata(ItemMetadataNames.embedInteropTypes);
            Assert.AreEqual("false", embedInteropTypes, "The tlb wrapper for the activex control should have EmbedInteropTypes=false not " + embedInteropTypes);
            Assert.IsTrue(ComReference.AreTypeLibAttrEqual(tlbRefInfo.attr, axRefInfo.attr), "reference information should be the same");
            Assert.AreEqual
                (
                    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"
                );
        }