本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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));
}
示例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
}
示例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), ");
}
示例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, "朱镕基");
}