当前位置: 首页>>代码示例>>C#>>正文


C# PrivateType.SetStaticFieldOrProperty方法代码示例

本文整理汇总了C#中PrivateType.SetStaticFieldOrProperty方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateType.SetStaticFieldOrProperty方法的具体用法?C# PrivateType.SetStaticFieldOrProperty怎么用?C# PrivateType.SetStaticFieldOrProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PrivateType的用法示例。


在下文中一共展示了PrivateType.SetStaticFieldOrProperty方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MyTestCleanup

        public void MyTestCleanup()
        {
            PrivateType privateWindowType = new PrivateType(typeof(VSWindows));
            privateWindowType.SetStaticFieldOrProperty("instance", null);

            this.serviceProvider = null;
        }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:7,代码来源:VSWindowsTest.cs

示例2: InstanceTest

        public void InstanceTest()
        {
            try
            {
                InvisibleForm actual;

                actual = InvisibleForm.Instance;
                Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");

                // Reset and try again
                PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm));
                invisibleForm.SetStaticFieldOrProperty("instanceForm", null);

                actual = InvisibleForm.Instance;
                Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");

                Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance.");

                Form f = actual as Form;
                Assert.IsFalse(f.Visible, "InvisibleForm should not be visible");
            }
            catch (Exception ex)
            {
                // Use try catch to test a workaround on CI build (AppVeyor)
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:Visual-Stylecop,项目名称:Visual-StyleCop,代码行数:27,代码来源:InvisibleFormTest.cs

示例3: TestCountBulls

 public void TestCountBulls()
 {
     bool[] isBull = new bool[4];
     PrivateType pr = new PrivateType(typeof(Game));
     pr.SetStaticFieldOrProperty("secretNumberAsString", "1234");
     int res = Game.CountBulls("1235", 0, isBull);
     Assert.AreEqual(3, res);
 }
开发者ID:hmaleev,项目名称:Quality-Code-Team-Zinc,代码行数:8,代码来源:GameTest.cs

示例4: TestCountHits

 public void TestCountHits()
 {
     bool[] isBull = new bool[4];
     bool[] isCow = new bool[10];
     PrivateType pr = new PrivateType(typeof(Game));
     pr.SetStaticFieldOrProperty("secretNumberAsString", "1234");
     int bulls = Game.CountBulls("1234", 0, isBull);
     int cows = Game.CountCows("1234", 0, isBull, isCow);
     Assert.AreEqual(4, bulls);
     Assert.AreEqual(0, cows);
 }
开发者ID:hmaleev,项目名称:Quality-Code-Team-Zinc,代码行数:11,代码来源:GameTest.cs

示例5: GameTestCurrentHits

 public void GameTestCurrentHits()
 {
     PrivateType pr = new PrivateType(typeof(Game));
     pr.SetStaticFieldOrProperty("secretNumberAsString", "1234");
     StringWriter sw = new StringWriter();
     Console.SetOut(sw);
     Game.RevealCurrentHits("1234");
     var result = sw.ToString();
     var expected = String.Format("Wrong number! Bulls: 4, Cows: 0!{0}{0}",
         Environment.NewLine);
     Assert.AreEqual(expected, result);
 }
开发者ID:hmaleev,项目名称:Quality-Code-Team-Zinc,代码行数:12,代码来源:GameTest.cs

示例6: MyTestCleanup

 public void MyTestCleanup()
 {
     try
     {
         PrivateType instanceForm = new PrivateType(typeof(InvisibleForm));
         instanceForm.SetStaticFieldOrProperty("instanceForm", null);
     }
     catch (Exception ex)
     {
         // Use try catch to test a workaround on CI build (AppVeyor)
         Console.WriteLine(ex.Message);
     }
 }
开发者ID:Visual-Stylecop,项目名称:Visual-StyleCop,代码行数:13,代码来源:InvisibleFormTest.cs

示例7: InstanceTest

        public void InstanceTest()
        {
            InvisibleForm actual;

            actual = InvisibleForm.Instance;
            Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");

            // Reset and try again
            PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm));
            invisibleForm.SetStaticFieldOrProperty("instanceForm", null);
            
            actual = InvisibleForm.Instance;
            Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
            
            Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance.");
            
            Form f = actual as Form;
            Assert.IsFalse(f.Visible, "InvisibleForm should not be visible");
        }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:19,代码来源:InvisibleFormTest.cs

示例8: MyTestInitialize

 public void MyTestInitialize()
 {
     PrivateType instanceForm = new PrivateType(typeof(InvisibleForm));
     instanceForm.SetStaticFieldOrProperty("instanceForm", null);
 }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:5,代码来源:InvisibleFormTest.cs

示例9: OnNavigateToDocNotInProjectTest

        public void OnNavigateToDocNotInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, "DummyFile.txt");
            var mockSecondDocument = new SequenceMock<Document>();
            mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), true);
            mockDocumentEnumerator.AddExpectationExpr(docs => docs.Current, mockSecondDocument.Instance);
            mockDocumentEnumerator.AddExpectationExpr(docs => docs.MoveNext(), false);

            mockSecondDocument.AddExpectationExpr(doc => doc.FullName, "DummyFile.txt");

            AnalysisHelper analysisHelper = this.SetCoreNoUI();
            bool eventFired = false;

            PrivateObject actual = new PrivateObject(this.package, new PrivateType(typeof(StyleCopVSPackage)));
            actual.SetFieldOrProperty("core", this.package.Core);

            // Register output generated event to test event fired
            this.package.Core.OutputGenerated += (sender, args) => { eventFired = true; };

            mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);

            mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
            mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);

            mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);

            // Use private type to set static private field
            PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
            privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

            // Execute
            PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
            taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);

            // Verify the required methods are called to show the violation
            mockTextSelection.Verify();
            mockVirtualPoint.Verify();
            mockDocument.Verify();

            Assert.IsTrue(eventFired, "Core did not fire output event");
        }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:51,代码来源:ViolationTaskTest.cs

示例10: OnNavigateToDocInProjectTest

        public void OnNavigateToDocInProjectTest()
        {
            var mockDocumentEnumerator = new SequenceMock<IEnumerator>();
            var mockDte = new Mock<DTE>();
            var mockDocuments = new Mock<Documents>();
            var mockDocument = new SequenceMock<Document>();
            var mockActiveDocument = new Mock<Document>();
            var mockTextSelection = new SequenceMock<TextSelection>();
            var mockVirtualPoint = new SequenceMock<VirtualPoint>();

            this.SetupProjectUtilities(mockDocumentEnumerator, mockDte, mockDocuments, mockDocument, mockActiveDocument, this.violation.File);

            mockDocument.AddExpectationExpr(doc => doc.Activate());
            mockDocument.AddExpectationExpr(doc => doc.DTE, (Func<DTE>)delegate { return (EnvDTE.DTE)mockDte.Instance; });

            mockActiveDocument.ImplementExpr(doc => doc.Selection, mockTextSelection.Instance);

            mockTextSelection.ImplementExpr(sel => sel.GotoLine(this.violation.LineNumber, true));
            mockTextSelection.ImplementExpr(sel => sel.ActivePoint, mockVirtualPoint.Instance);

            mockVirtualPoint.ImplementExpr(vp => vp.TryToShow(EnvDTE.vsPaneShowHow.vsPaneShowCentered, 0));

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);

            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(EnvDTE.DTE)), mockDte.Instance);
            this.mockServiceProvider.ImplementExpr(sp => sp.GetService(typeof(SVsSolutionBuildManager)), new MockSolutionBuildManager());

            // Use private type to set static private field
            PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));
            privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

            // Execute
            PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
            taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);

            // Verify the required methods are called to show the violation
            mockTextSelection.Verify();
            mockVirtualPoint.Verify();
            mockDocument.Verify();
        }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:40,代码来源:ViolationTaskTest.cs

示例11: OnNavigateNoDocumentTest

        public void OnNavigateNoDocumentTest()
        {
            bool eventFired = false;
            Mock<DTE> mockDte = new Mock<DTE>();

            // No UI for test
            AnalysisHelper analysisHelper = this.SetCoreNoUI();

            PrivateObject actual = new PrivateObject(this.package, new PrivateType(typeof(StyleCopVSPackage)));
            actual.SetFieldOrProperty("core", this.package.Core);

            // Register output generated event to test event fired
            this.package.Core.OutputGenerated += (sender, args) => { eventFired = true; };

            // Does nothing - included for code coverage and to catch it if it starts doing something unexpectedly
            Assert.IsNotNull(this.taskUnderTestShell, "this.taskUnderTestShell is null.");
            this.taskUnderTestShell.Document = null;

            // Use private type to set static private field
            PrivateType privateProjectUtilities = new PrivateType(typeof(ProjectUtilities));           
            privateProjectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);

            PrivateObject taskUnderTestPrivateObject = new PrivateObject(this.taskUnderTest, new PrivateType(typeof(ViolationTask)));
            taskUnderTestPrivateObject.Invoke("OnNavigate", EventArgs.Empty);

            Assert.IsTrue(eventFired, "Core did not fire output event");
        }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:27,代码来源:ViolationTaskTest.cs

示例12: TestInitialize

        public void TestInitialize()
        {
            this.mockServiceProvider = new Mock<IServiceProvider>();

            PrivateType projectUtilities = new PrivateType(typeof(ProjectUtilities));
            projectUtilities.SetStaticFieldOrProperty("serviceProvider", this.mockServiceProvider.Instance);
        }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:7,代码来源:PackageCommandSetTest.cs

示例13: TestCleanup

 public void TestCleanup()
 {
     PrivateType projectUtilities = new PrivateType(typeof(ProjectUtilities));
     projectUtilities.SetStaticFieldOrProperty("serviceProvider", null);
 }
开发者ID:kopelli,项目名称:Visual-StyleCop,代码行数:5,代码来源:PackageCommandSetTest.cs


注:本文中的PrivateType.SetStaticFieldOrProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。