本文整理汇总了C#中PrivateObject.SetField方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateObject.SetField方法的具体用法?C# PrivateObject.SetField怎么用?C# PrivateObject.SetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PrivateObject
的用法示例。
在下文中一共展示了PrivateObject.SetField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethod_ClearEditNumber
public void TestMethod_ClearEditNumber()
{
CalcServicesApi api = new CalcServicesApi();
var obj = new PrivateObject(api);
obj.SetField("statement", "11+22-");
obj.SetField("editNumber", "120");
obj.Invoke("ClearEditNumber");
Assert.IsTrue(api.STATEMENT.Equals("11+22-"));
Assert.IsTrue(api.EDIT.Equals("0"));
}
示例2: ServerProxy_FallbackOnConnect
public void ServerProxy_FallbackOnConnect()
{
//------------Setup for test--------------------------
var serverProxy = new ServerProxy(new Uri("http://bob"));
var serverGuid = Guid.NewGuid();
PrivateObject p = new PrivateObject(serverProxy);
var wrapped = new Mock<IEnvironmentConnection>();
wrapped.Setup(a => a.DisplayName).Returns("moo");
wrapped.Setup(a => a.Connect(It.IsAny<Guid>())).Throws(new FallbackException());
wrapped.Setup(a => a.WebServerUri).Returns( new Uri("http://bob"));
p.SetField("_wrappedConnection", wrapped.Object);
try
{
serverProxy.Connect(serverGuid);
}
// ReSharper disable EmptyGeneralCatchClause
catch(Exception err)
{
Assert.IsNotNull(err);
}
var con = p.GetField("_wrappedConnection") as IEnvironmentConnection;
Assert.IsNotNull(con);
Assert.AreNotEqual(con,wrapped.Object);
Assert.AreEqual("moo",con.DisplayName);
}
示例3: TestValueOnePair
public void TestValueOnePair()
{
Yahtzee yahtzee = new Yahtzee();
PrivateObject priv = new PrivateObject(yahtzee);
int[] example = new int[5] { 1, 5, 5, 1, 1 };
priv.SetField("dies", example);
Assert.AreEqual(10, yahtzee.valueOnePair());
}
示例4: MoveTest
public void MoveTest()
{
Cow cow = new Cow(Vector2.Zero, 0, null, new Random());
PrivateObject cowObject = new PrivateObject(cow);
cowObject.SetField("moveRight", true);
cowObject.Invoke("Move");
Assert.IsTrue(((Vector2)cowObject.GetField("speed")).X > 0);
}
示例5: Application_Start
protected void Application_Start()
{
var setting = ConfigurationManager.AppSettings["TestApp.SendTelemetyIntemOnAppStart"];
if (false == string.IsNullOrWhiteSpace(setting) && true == bool.Parse(setting))
{
new TelemetryClient().TrackTrace("Application_Start");
}
GlobalConfiguration.Configure(WebApiConfig.Register);
var module = new PerformanceCollectorModule();
// we're running under IIS Express, so override the default behavior designed to prevent a deadlock
module.EnableIISExpressPerformanceCounters = true;
// set test-friendly timings
var privateObject = new PrivateObject(module);
privateObject.SetField("collectionPeriod", TimeSpan.FromMilliseconds(10));
privateObject.SetField(
"defaultCounters",
new List<string>() { @"\Memory\Available Bytes", @"Will not parse;\Does\NotExist" });
module.Counters.Add(
new PerformanceCounterCollectionRequest(@"Will not parse", "Custom counter - will not parse"));
module.Counters.Add(
new PerformanceCounterCollectionRequest(@"\Does\NotExist", "Custom counter - does not exist"));
module.Counters.Add(
new PerformanceCounterCollectionRequest(
@"\Process(??APP_WIN32_PROC??)\Handle Count",
"Custom counter one"));
module.Counters.Add(
new PerformanceCounterCollectionRequest(
@"\ASP.NET Applications(??APP_W3SVC_PROC??)\Anonymous Requests/Sec",
"Custom counter two"));
// necessary for .NET CLR Memory counters to start reporting process ID
GC.Collect();
module.Initialize(TelemetryConfiguration.Active);
TelemetryModules.Instance.Modules.Add(module);
}
示例6: GetFakeHttpApplication
public static HttpApplication GetFakeHttpApplication()
{
var httpContext = GetFakeHttpContext();
var httpApplicationWrapper = new PrivateObject(typeof(HttpApplication), null);
httpApplicationWrapper.SetField("_context", httpContext);
return (HttpApplication)httpApplicationWrapper.Target;
}
示例7: TestLoadInvalidFile
public void TestLoadInvalidFile()
{
// Arrange
Appointments testApps = new Appointments();
PrivateObject privApps = new PrivateObject(testApps);
privApps.SetField("fileName", "UnitTests/LoadInvalid.xml");
// Act
bool successfullLoad = testApps.Load();
// Assert
Assert.IsFalse(successfullLoad, "The appointment loaded an invalid file.");
}
示例8: SouthPointingState_Handle_NavigationMove_ExpectDecrementinYaxis
public void SouthPointingState_Handle_NavigationMove_ExpectDecrementinYaxis()
{
//Arrange
PrivateObject _marsRover = new PrivateObject(_roverInstance);
_marsRover.SetField("_currentNavigator", 'M');
RoverState target = CreateTarget();
//Act
target.Handle(_roverInstance);
//Assert
Assert.AreEqual<int>(1, _roverInstance.CurrentPosition.Xaxis);
}
示例9: TestLoadNoFile
public void TestLoadNoFile()
{
// Arrange
Appointments testApps = new Appointments();
PrivateObject privApp = new PrivateObject(testApps);
privApp.SetField("fileName", String.Empty);
// Act
bool successfullLoad = testApps.Load();
// Assert
Assert.IsFalse(successfullLoad, "The appointment didn't load from a file!");
}
示例10: SouthPointingState_Handle_NavigationRight_ExpectWest
public void SouthPointingState_Handle_NavigationRight_ExpectWest()
{
//Arrange
PrivateObject _marsRover = new PrivateObject(_roverInstance);
_marsRover.SetField("_currentNavigator", 'R');
RoverState target = CreateTarget();
//Act
target.Handle(_roverInstance);
//Assert
Assert.AreEqual<Enum_Direction>(Enum_Direction.Direction_W, _roverInstance.CurrentPosition.Direction);
}
示例11: ProcessSpaceInputTest
public void ProcessSpaceInputTest()
{
Spaceship spaceship = new Spaceship();
InputManager input = new InputManager();
PrivateObject privateInput = new PrivateObject(input);
privateInput.SetField("currentState", new KeyboardState(Keys.Space));
SpaceshipController controller = new SpaceshipController(spaceship, input);
controller.ProcessInput();
Assert.IsTrue(spaceship.BeamOn);
}
示例12: UpInputTest
public void UpInputTest()
{
Spaceship spaceship = new Spaceship();
InputManager input = new InputManager();
PrivateObject privateInput = new PrivateObject(input);
privateInput.SetField("currentState", new KeyboardState(Keys.W));
SpaceshipController controller = new SpaceshipController(spaceship, input);
spaceship.Y = 300;
controller.ProcessInput();
Assert.AreEqual(300 - spaceship.Speed, spaceship.Y);
}
示例13: TestSearchUsers
public void TestSearchUsers()
{
// Arrange
var query = "sTEn";
var allUsers = new List<Model.User>()
{
new Model.User() { FirstName = "Petra" },
new Model.User() { FirstName = "Carsten" },
new Model.User() { FirstName = "Philipp" }
};
var currentUsers = new ObservableCollection<Model.User>(allUsers);
var repository = CreateUserRepository();
var po = new PrivateObject(repository);
po.SetField("_allUsers", allUsers);
po.SetField("_currentUsers", currentUsers);
// Act
po.Invoke("SearchUsers", query);
var result = (ObservableCollection<Model.User>)po.GetField("_currentUsers");
// Assert
Assert.IsTrue(result.Count() == 1);
}
示例14: TestLoadValid
public void TestLoadValid()
{
// Arrange
Appointments testApps = new Appointments();
PrivateObject privApps = new PrivateObject(testApps);
privApps.SetField("fileName", "UnitTests/Load.xml");
DateTime dt = new DateTime(DateTime.Now.Year + 1, 1, 1, 0, 0, 0);
// Act
bool successfullLoad = testApps.Load();
// Assert
Assert.IsTrue(successfullLoad, "The file wasn't loaded!");
for (int i = 0; i < testApps.Count; ++i)
{
Assert.AreEqual("Description: Test Appointment " + i + "\nLocation: Test Location", testApps[i].DisplayableDescription, "The appointments description doesn't match!");
Assert.AreEqual(30, testApps[i].Length, "The appointments length is not the same!");
Assert.AreEqual(dt, testApps[i].Start, "The appointments starting time is not the same!");
}
}
示例15: ServerProxy_FallbackOnConnectWithError
public void ServerProxy_FallbackOnConnectWithError()
{
//------------Setup for test--------------------------
var serverProxy = new ServerProxy(new Uri("http://bob"));
var serverGuid = Guid.NewGuid();
PrivateObject p = new PrivateObject(serverProxy);
var wrapped = new Mock<IEnvironmentConnection>();
var fallback = new Mock<IEnvironmentConnection>();
wrapped.Setup(a => a.Connect(It.IsAny<Guid>())).Throws(new FallbackException());
p.SetField("_wrappedConnection",wrapped.Object);
try
{
serverProxy.Connect(serverGuid);
}
// ReSharper disable EmptyGeneralCatchClause
catch
// ReSharper restore EmptyGeneralCatchClause
{
}
var con = p.GetField("_wrappedConnection");
Assert.IsNotNull(con);
}