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


C# PrivateObject.Invoke方法代码示例

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


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

示例1: LabyrinthMoveUpTest

        public void LabyrinthMoveUpTest()
        {
            PlayerPosition startPosition = new PlayerPosition(3, 3);
            string[] rawData = new string[Labyrinth.LabyrinthSize]
            {
                "XXXXXXX",
                "X-X---X",
                "X---X-X",
                "X--*--X",
                "X-X----",
                "X-----X",
                "XXXXXXX"
            };
            Cell[,] board = LabyrinthDataFromStringArray(rawData);
            Labyrinth labyrinth = new Labyrinth(startPosition, board);
            var privateObject = new PrivateObject(labyrinth);
            privateObject.Invoke("ProcessMoveUp", 3, 3);
            string result =
                @"X X X X X X X 
X - X - - - X 
X - - * X - X 
X - - - - - X 
X - X - - - - 
X - - - - - X 
X X X X X X X 
";
            string expected = labyrinth.ToString();

            Assert.AreEqual(expected, result);                       
        }
开发者ID:Jarolim,项目名称:AllMyHomeworkForTelerikAcademy,代码行数:30,代码来源:Labyrinth.Tests.cs

示例2: ItShouldBePossibleToRegisterAMessageFromAChildThreadAutomatically

        public void ItShouldBePossibleToRegisterAMessageFromAChildThreadAutomatically()
        {
            var subThread = new MessageThread(true, NullLogger.Create(), "SUBTHREAD");
            subThread.SetMaxMessagePerCycle(1);
            var subThread2 = new MessageThread(false,NullLogger.Create(), "SUBTHREAD2");
            var threadManager = new ThreadManager(NullLogger.Create());
            var privateObject = new PrivateObject(threadManager);
            threadManager.RunThread();
            threadManager.AddThread(subThread);
            threadManager.AddThread(subThread2);
            Thread.Sleep(100);

            Assert.IsTrue(threadManager.Status == RunningStatus.Running);
            var result = privateObject.Invoke("IsTypeRegistered", subThread.ThreadName, typeof(TestMessage)) as Boolean?;
            Assert.IsNotNull(result);
            Assert.AreEqual(true, result);

            result = privateObject.Invoke("IsTypeRegistered", subThread2.ThreadName, typeof(TestMessage)) as Boolean?;
            Assert.IsNotNull(result);
            Assert.AreEqual(false, result);

            threadManager.SendMessageToThread(new TestMessage());
            Thread.Sleep(1000);
            Assert.IsTrue(subThread.MessagesCount==1);
            Assert.IsFalse(subThread2.MessagesCount == 1);
            Thread.Sleep(100);
            threadManager.Terminate();
            Thread.Sleep(500);
            Assert.IsTrue(threadManager.Status == RunningStatus.Halted);
        }
开发者ID:kendarorg,项目名称:ZakFramework,代码行数:30,代码来源:ThreadManagerWithMessagingTest.cs

示例3: SinglePointCrossoverCrossTest

 public void SinglePointCrossoverCrossTest() {
   var target = new PrivateObject(typeof(SinglePointCrossover));
   ItemArray<IntegerVector> parents;
   TestRandom random = new TestRandom();
   bool exceptionFired;
   // The following test checks if there is an exception when there are more than 2 parents
   random.Reset();
   parents = new ItemArray<IntegerVector>(new IntegerVector[] { new IntegerVector(5), new IntegerVector(6), new IntegerVector(4) });
   exceptionFired = false;
   try {
     IntegerVector actual;
     actual = (IntegerVector)target.Invoke("Cross", random, parents);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
   // The following test checks if there is an exception when there are less than 2 parents
   random.Reset();
   parents = new ItemArray<IntegerVector>(new IntegerVector[] { new IntegerVector(4) });
   exceptionFired = false;
   try {
     IntegerVector actual;
     actual = (IntegerVector)target.Invoke("Cross", random, parents);
   }
   catch (System.ArgumentException) {
     exceptionFired = true;
   }
   Assert.IsTrue(exceptionFired);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:30,代码来源:SinglePointCrossoverTest.cs

示例4: TestCellBackgroundIsChangedWhenCellHasMine

        public void TestCellBackgroundIsChangedWhenCellHasMine()
        {
            MainWindow window = new MainWindow();
            MinesweeperGrid minesweeperGrid =
                (MinesweeperGrid)MinesweeperGridFactory.CreateNewTable(MinesweeperDifficultyType.Easy);
            PrivateObject view = new PrivateObject(new WpfView(window.WinesweeperGrid));
            Grid buttons = (Grid)view.GetField("win");

            view.Invoke("DisplayGrid", minesweeperGrid);

            int counter = 0;
            for (int r = 0; r < minesweeperGrid.Rows; r++)
            {
                for (int c = 0; c < minesweeperGrid.Cols; c++)
                {
                    if (minesweeperGrid.HasCellBomb(r, c))
                    {
                        minesweeperGrid.RevealCell(r, c);
                        view.Invoke("DisplayGrid", minesweeperGrid);
                        r = minesweeperGrid.Rows;
                        break;
                    }

                    counter++;
                }
            }

            List<ImageBrush> images = (List<ImageBrush>)view.GetField("images");
            Button button = (Button)buttons.Children[counter];

            Assert.AreEqual(images[0], button.Background);
        }
开发者ID:Minesweeper-6-Team-Project-Telerik,项目名称:Minesweeper-6,代码行数:32,代码来源:WpfViewTest.cs

示例5: TestIfBombWithSizeFiveExplodesAsExpectedWhenOnTheTopLeft

        public void TestIfBombWithSizeFiveExplodesAsExpectedWhenOnTheTopLeft()
        {
            string testFieldSize = "6";

            Engine.FieldSizeUnitTestSetter = new StringReader(testFieldSize);
            Engine.StartMenu.IsStartGameChosen = true;
            Engine gameEngine = new Engine();
            Playfield testField = Playfield.Instance;
            testField.SetFieldSize(6);
            testField.InitializeEmptyField();
            testField[0, 0] = new BombCell(5);

            PrivateObject enginePrivateInstance = new PrivateObject(gameEngine);
            enginePrivateInstance.Invoke("HandleExplosion", testField[0, 0]);
            Playfield engineField = (Playfield)enginePrivateInstance.GetFieldOrProperty("playField");
            BombCell bomb = new BombCell(5);
            bomb.X = 0;
            bomb.Y = 0;
            engineField[0, 0] = bomb;

            enginePrivateInstance.Invoke("ChangeCurrentCell", 1, 1);
            enginePrivateInstance.Invoke("HandleExplosion", engineField[0, 0]);

            Assert.AreEqual(engineField[0, 1].CellType == CellType.BlownCell, true, "Expected that the cell on coordinates 4,5 is CellType.BlownCell. Received {0} ", engineField[4, 4].CellType);
        }
开发者ID:huuuskyyy,项目名称:Teamworks,代码行数:25,代码来源:EngineTests.cs

示例6: AddRandomObjectTest

        public void AddRandomObjectTest()
        {
            PrivateObject manager = new PrivateObject(new GameObjectsManager(new Spaceship(), new Random()));
            manager.Invoke("AddRandomObject");
            manager.Invoke("Update", new GameTime());
            List<LiftObject> liftObjects = (List<LiftObject>)manager.GetField("liftObjects");

            Assert.AreEqual(1, liftObjects.Count);
        }
开发者ID:csce3513,项目名称:Team12,代码行数:9,代码来源:GameObjectsManagerTest.cs

示例7: CountNeighborStates3x3GridMixOfLiveAndDead

 public void CountNeighborStates3x3GridMixOfLiveAndDead()
 {
     PrivateObject ATestGrid = new PrivateObject(new GameOfLife(3, 3));
     Cell[,] ATestCellGrid = (Cell[,])ATestGrid.GetField("cells");
     ATestCellGrid[0, 0].State = true;
     ATestCellGrid[1, 1].State = true;
     ATestCellGrid[2, 2].State = true;
     int[] TestNeighborStates0x0 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[0, 0] });
     int[] TestNeighborStates0x2 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[0, 2] });
     int[] TestNeighborStates2x0 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[2, 0] });
     int[] TestNeighborStates2x2 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[2, 2] });
     int[] TestNeighborStates1x0 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[1, 0] });
     int[] TestNeighborStates1x2 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[1, 2] });
     int[] TestNeighborStates0x1 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[0, 1] });
     int[] TestNeighborStates2x1 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[2, 1] });
     int[] TestNeighborStates1x1 = (int[])ATestGrid.Invoke("CountNeighborStates", new object[] { ATestCellGrid[1, 1] });
     CollectionAssert.AreEqual(new int[] { 1, 2 }, TestNeighborStates0x0);
     CollectionAssert.AreEqual(new int[] { 1, 2 }, TestNeighborStates0x2);
     CollectionAssert.AreEqual(new int[] { 1, 2 }, TestNeighborStates2x0);
     CollectionAssert.AreEqual(new int[] { 1, 2 }, TestNeighborStates2x2);
     CollectionAssert.AreEqual(new int[] { 2, 3 }, TestNeighborStates1x0);
     CollectionAssert.AreEqual(new int[] { 2, 3 }, TestNeighborStates1x2);
     CollectionAssert.AreEqual(new int[] { 2, 3 }, TestNeighborStates0x1);
     CollectionAssert.AreEqual(new int[] { 2, 3 }, TestNeighborStates2x1);
     CollectionAssert.AreEqual(new int[] { 2, 6 }, TestNeighborStates1x1);
 }
开发者ID:sqfish,项目名称:ConwaysGameOfLife,代码行数:26,代码来源:GridTests.cs

示例8: RemoveObjectTest

        public void RemoveObjectTest()
        {
            PrivateObject manager = new PrivateObject(new GameObjectsManager(new Spaceship(), new Random()));
            manager.Invoke("AddObject", new LiftObjectTestClass(Vector2.Zero, 0, null));
            manager.Invoke("Update", new GameTime());
            List<LiftObject> liftObjects = (List<LiftObject>)manager.GetField("liftObjects");

            manager.Invoke("RemoveObject", liftObjects.Last());
            manager.Invoke("Update", new GameTime());
            liftObjects = (List<LiftObject>)manager.GetField("liftObjects");
            Assert.AreEqual(0, liftObjects.Count);
        }
开发者ID:csce3513,项目名称:Team12,代码行数:12,代码来源:GameObjectsManagerTest.cs

示例9: MoveRandomlyTest

        public void MoveRandomlyTest()
        {
            // Test that it moves when on ground
            PrivateObject cow = new PrivateObject(new Cow(new Vector2(100, 300), 0, null, new Random()));
            cow.Invoke("MoveRandomly", new GameTime());
            TimeSpan duration = (TimeSpan) cow.GetField("actionDuration");
            Assert.IsTrue(duration.Ticks > 0);

            // Test that it doesn't move when off ground
            cow.SetProperty("Position", new Vector2(100, 299));
            cow.Invoke("MoveRandomly", new GameTime());
            duration = (TimeSpan)cow.GetField("actionDuration");
            Assert.AreEqual(0, duration.Ticks);
        }
开发者ID:csce3513,项目名称:Team12,代码行数:14,代码来源:CowTest.cs

示例10: TestLocate2

        public void TestLocate2()
        {
            string sourceFolder = @"I:\[BDMV][アニメ] ココロコネクト";
            string torrentPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestTorrents", "[U2].13680.torrent");

            IList<FileSystemFileInfo> fileInfos = GetFileSystemInfos(sourceFolder);
            var torrent = Torrent.Load(torrentPath);

            var locater = new PrivateObject(typeof(TorrentFileLocater), torrent, fileInfos);
            locater.Invoke("FindTorrentFileLinks");
            var result = (bool)locater.Invoke("CheckPiece", 10);

            Assert.IsTrue(result);
        }
开发者ID:harrywong,项目名称:torrenthardlinkhelper,代码行数:14,代码来源:LocateTest.cs

示例11: CleanUpURLTest

        public void CleanUpURLTest()
        {
            ChromeDriver driver = new ChromeDriver(-1);
            PrivateObject privateObject = new PrivateObject(driver);

            string result = (string)privateObject.Invoke("CleanUpURL", new object[] { "http://website.com&list=RDJEgVI-IKpqk&index=30" });
            Assert.AreEqual("http://website.com", result);

            result = (string)privateObject.Invoke("CleanUpURL", new object[] { "http://website.com&index=0&list=RDJEgVI-IKpqk&other=new" });
            Assert.AreEqual("http://website.com&other=new", result);

            result = (string)privateObject.Invoke("CleanUpURL", new object[] { "http://website.com" });
            Assert.AreEqual("http://website.com", result);

            driver.Stop();
        }
开发者ID:etray,项目名称:NCorder,代码行数:16,代码来源:ChromeDriverTest.cs

示例12: NotRequireAuth_NotAuthenticated

// ReSharper disable InconsistentNaming
        public void NotRequireAuth_NotAuthenticated()
// ReSharper restore InconsistentNaming
        {
            var controller = GetControllerMock<AuthenticatedController>();

            //set up stubs
            var request = MockRepository.GenerateStub<HttpRequestBase>();
            var context = MockRepository.GenerateStub<HttpContextBase>();
            //override methods
            request.Stub(a => a.IsAuthenticated).Return(false);
            context.Stub(a => a.Request).Return(request);



            //set controller context. 
            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            //invoke OnACtionExecuting
            var pocontroller = new PrivateObject(controller);
            var filter = new ActionExecutingContext();
            pocontroller.Invoke("OnActionExecuting", filter);
            var result = filter.Result;

            //assert
            Assert.IsNotInstanceOfType(result, typeof(RedirectToRouteResult));

            

        }
开发者ID:andyevans2000,项目名称:Illuminate,代码行数:30,代码来源:AuthenticationTests.cs

示例13: RequireAuthNotAuthenticated

        public void RequireAuthNotAuthenticated()
        {
            var controller = GetControllerMock<AuthenticatedController>();
            const string rawurl = "http://testrawurl"; 
            ////set up stubs
            //HttpRequestBase request = MockRepository.GenerateStub<HttpRequestBase>();
            //HttpContextBase context = MockRepository.GenerateStub<HttpContextBase>();
            ////override methods
            //request.Stub(a => a.IsAuthenticated).Return(false);
            //context.Stub(a => a.Request).Return(request); 



            //set controller context. 
            var context = GetContext(false);
            context.Request.Stub(r => r.RawUrl).Return(rawurl); 

            controller.ControllerContext = new ControllerContext(context, new RouteData(), controller);

            //invoke OnACtionExecuting
            var pocontroller = new PrivateObject(controller); 
            var filter = new ActionExecutingContext();
            
            pocontroller.Invoke("OnActionExecuting", filter);
            var result = filter.Result; 

            //assert
            Assert.IsInstanceOfType(result, typeof(RedirectResult));

            var rr = (RedirectResult) result;
            Assert.AreEqual(rr.Url, "/Login?originalurl=" + rawurl); //"/Login?originalurl=" + Request.RawUrl
            
        }
开发者ID:andyevans2000,项目名称:Illuminate,代码行数:33,代码来源:AuthenticationTests.cs

示例14: DealFuncASCIIFlag_Test

 public void DealFuncASCIIFlag_Test()
 {
     var po = new PrivateObject(new BaseResp(null));
     byte[] arg = new byte[] {27,15,32,51,50,67,40,57,48,70,41,44,32};
     var r = (string)po.Invoke("DealFuncASCIIFlag", new object[] { arg });
     Assert.AreEqual(r, " 32C(90F), ");
 }
开发者ID:upan,项目名称:ETermSimulator,代码行数:7,代码来源:BaseRespTest.cs

示例15: DealFuncGBKFlag_GBKInfrequentlyUsedCharacter

 public void DealFuncGBKFlag_GBKInfrequentlyUsedCharacter()//朱镕基 “镕” is not a frequently used character
 {
     var po = new PrivateObject(new BaseResp(null));
     byte[] arg = new byte[] { 27,14,86, 108, 120, 77, 100, 69, 59, 121 };
     var r = (string)po.Invoke("DealFuncGBKFlag", new object[] { arg });
     Assert.AreEqual(r, "朱镕基");
 }
开发者ID:upan,项目名称:ETermSimulator,代码行数:7,代码来源:BaseRespTest.cs


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