本文整理汇总了C#中PrivateObject.GetFieldOrProperty方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateObject.GetFieldOrProperty方法的具体用法?C# PrivateObject.GetFieldOrProperty怎么用?C# PrivateObject.GetFieldOrProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PrivateObject
的用法示例。
在下文中一共展示了PrivateObject.GetFieldOrProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructorTest
public void ConstructorTest()
{
bool isFull = true;
AnalysisThread target = CreateAnalysisThread(isFull);
Assert.IsNotNull(target, "Constructor is broken");
PrivateObject privateAnalysis = new PrivateObject(target, new PrivateType(typeof(AnalysisThread)));
Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("projects"), "Constructor did not set the projects.");
Assert.IsTrue((bool)privateAnalysis.GetFieldOrProperty("full"), "Constructor did not set the full flag.");
Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("core"), "Constructor did not set the core.");
}
示例2: ImapIdlerConstructorTest
public void ImapIdlerConstructorTest()
{
var factory = new Mock<ImapClientFactory>(_configuration.Object);
var idler = new ImapIdler(factory.Object);
var imapIdlerPvtObject = new PrivateObject(idler);
Assert.AreEqual(factory.Object, imapIdlerPvtObject.GetFieldOrProperty("Factory"));
Assert.AreNotEqual(null, imapIdlerPvtObject.GetFieldOrProperty("Timeout"));
Assert.AreNotEqual(null, imapIdlerPvtObject.GetFieldOrProperty("IntegrityCheckTimer"));
}
示例3: test
static void test()
{
Class1.Item a = new Class1.Item();
Type t = typeof(Class1);
Type tinner = t.GetNestedType("Item", BindingFlags.NonPublic);
PrivateObject o = new PrivateObject(tinner);
o.SetFieldOrProperty("ID", "12345");
PrivateObject class1 = new PrivateObject(typeof(Class1));
dynamic list = (List<dynamic>)class1.GetFieldOrProperty("itemList");
list.Add(o.Target);
Console.WriteLine(class1.GetFieldOrProperty("GetFromListID"));
}
示例4: TestMethod2
public void TestMethod2()
{
var t1 = DateTime.Now;
var t2 = DateTime.Now.AddDays(-1);
var emptyBook = new BookOrganizer.Book();
var model = new AddBookViewModel(emptyBook);
Book resBookManual = new Book()
{
Annotation = "Аннотация",
Comment = "Комментарий",
FinishTime = t1,
StartTime = t2,
Title = "Название",
Pages = 100,
Mark = 10,
Year = 2016
};
model.Annotation = "Аннотация";
model.Comment = "Комментарий";
model.FinishTime = t1;
model.StartTime = t2;
model.Title = "Название";
model.Pages = 100;
model.Mark = 10;
model.Year = 2016;
var privateModel = new PrivateObject(model);
var t = (privateModel.GetFieldOrProperty("book")) as Book;
Assert.AreEqual(resBookManual, t);
model.Author = "Пушкин А.С.";
model.Genre = "Классика";
resBookManual.Author = new Author() { Name = "Пушкин А.С." };
resBookManual.Genre = new Genre() { Name = "Классика" };
model.BookOut += (a) => { Assert.AreNotEqual(a, resBookManual); Assert.AreNotEqual(((Book)a).Author.Id, resBookManual.Author.Id); Assert.AreNotEqual(((Book)a).Genre.Id, resBookManual.Genre.Id); };
model.SubmitCommand.Execute(null);
var bookAutoCreatedButWithManualAuthorAndGenre = (privateModel.GetFieldOrProperty("book")) as Book;
bookAutoCreatedButWithManualAuthorAndGenre.Author = new Author() { Name = "Пушкин А.С.", Id = 0 };
bookAutoCreatedButWithManualAuthorAndGenre.Genre = new Genre() { Name = "Классика", Id = 0 };
privateModel.SetFieldOrProperty("book", bookAutoCreatedButWithManualAuthorAndGenre);
t = privateModel.GetFieldOrProperty("book") as Book;
Assert.AreEqual(resBookManual, t);
}
示例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: TestMethod1
public void TestMethod1()
{
var book = new BookOrganizer.Book() { Title = "что-то", Author = new BookOrganizer.Author() { Name = "Пушкин" } };
var b = new AddBookViewModel(book);
PrivateObject obj = new PrivateObject(b);
Assert.AreEqual(book, obj.GetFieldOrProperty("book") as BookOrganizer.Book);
}
示例7: TestDeckCount
public void TestDeckCount()
{
var testDeck = new PrivateObject(typeof(Deck));
// Testing < and > instead of == for more robust feedback in case of failure.
var cardsInTestDeck = new List<Card>((Stack<Card>)testDeck.GetFieldOrProperty("_cards"));
Assert.IsFalse(cardsInTestDeck.Count < 52, "Deck Length Error", "There are less than 52 cards in the deck!");
Assert.IsFalse(cardsInTestDeck.Count > 52, "Deck Length Error", "There are more than 52 cards in the deck!");
}
示例8: EnsureDeckHasRightNumberOfSuites
public void EnsureDeckHasRightNumberOfSuites()
{
var testDeck = new PrivateObject(typeof(Deck));
var cardsInTestDeck = new List<Card>((Stack<Card>)testDeck.GetFieldOrProperty("_cards"));
var result = cardsInTestDeck.GroupBy(card => card.Suit);
Assert.IsFalse(result.Count() < 4, "Suits Error", "The deck contains less than four suits.");
Assert.IsFalse(result.Count() > 4, "Suits Error", "The deck contains more than four suits.");
}
示例9: EnsureDeckHasRightNumberOfValues
public void EnsureDeckHasRightNumberOfValues()
{
var testDeck = new PrivateObject(typeof(Deck));
var cardsInTestDeck = new List<Card>((Stack<Card>)testDeck.GetFieldOrProperty("_cards"));
var result = cardsInTestDeck.GroupBy(card => card.Value);
Assert.IsFalse(result.Count() < 13, "Value Error", "The deck contains less than thirteen values.");
Assert.IsFalse(result.Count() > 13, "Value Error", "The deck contains more than thirteen values.");
}
示例10: ConstructorTest
public void ConstructorTest()
{
// Execute metod under test first time
TaskProvider target = new TaskProvider(this.serviceProvider);
Assert.IsNotNull(target, "Unable to instantiate TaskProvider.");
PrivateObject taskProvider = new PrivateObject(target, new PrivateType(typeof(TaskProvider)));
Assert.IsNotNull(taskProvider.GetFieldOrProperty("serviceProvider"), "TaskProvider.provider returned null");
}
示例11: GetInstanceTest
public void GetInstanceTest()
{
VSWindows instance = VSWindows.GetInstance(this.serviceProvider);
PrivateObject actual = new PrivateObject(instance, new PrivateType(typeof(VSWindows)));
Assert.IsNotNull(instance, "VSWindows.GetInstance() returned null.");
Assert.IsNotNull(this.serviceProvider, "serviceProvider is null.");
Assert.AreEqual(this.serviceProvider, (MockServiceProvider)actual.GetFieldOrProperty("serviceProvider"), "Service provider was not set correctly");
}
示例12: ConstructorTest
public void ConstructorTest()
{
try
{
bool isFull = true;
AnalysisThread target = CreateAnalysisThread(isFull);
Assert.IsNotNull(target, "Constructor is broken");
PrivateObject privateAnalysis = new PrivateObject(target, new PrivateType(typeof(AnalysisThread)));
Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("projects"), "Constructor did not set the projects.");
Assert.IsTrue((bool)privateAnalysis.GetFieldOrProperty("full"), "Constructor did not set the full flag.");
Assert.IsNotNull(privateAnalysis.GetFieldOrProperty("core"), "Constructor did not set the core.");
}
catch (Exception ex)
{
// Use try catch to test a workaround on CI build (AppVeyor)
Console.WriteLine(ex.Message);
}
}
示例13: TestPrivateMember
public void TestPrivateMember()
{
//arrange
string name = "Abhishek";
int age = 30;
Salary osalary = new Salary(name, age);
//act
PrivateObject pObj = new PrivateObject(osalary);
//assert
Assert.AreEqual<int>(age, Convert.ToInt32(pObj.GetField("age")));
Assert.AreEqual<string>(name, pObj.GetFieldOrProperty("name") as string);
}
示例14: FreshenMailBoxTest
public void FreshenMailBoxTest()
{
//setup private object
var pvt = new PrivateObject(_imapMailBox);
pvt.SetFieldOrProperty("_imapWorker", _worker.Object);
//* start the freshen *//
var result = (Task<bool>)pvt.Invoke("FreshenMailBox");
_worker.Verify(x => x.FreshenMailBox(It.IsAny<string>()));
Assert.IsTrue(result.Result);
Assert.IsFalse((bool) pvt.GetFieldOrProperty("Freshening"));
}
示例15: DTEPropertyTest
public void DTEPropertyTest()
{
try
{
VSWindows instance = VSWindows.GetInstance(this.serviceProvider);
PrivateObject actual = new PrivateObject(instance, new PrivateType(typeof(VSWindows)));
Assert.IsNotNull((MockDTE)actual.GetFieldOrProperty("DTE"), "DTE property was null");
}
catch (Exception ex)
{
// Use try catch to test a workaround on CI build (AppVeyor)
Console.WriteLine(ex.Message);
}
}