本文整理汇总了C#中PrivateObject.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# PrivateObject.GetProperty方法的具体用法?C# PrivateObject.GetProperty怎么用?C# PrivateObject.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PrivateObject
的用法示例。
在下文中一共展示了PrivateObject.GetProperty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVirtualPath_NoTranslationExistsForThreadCulture_ReturnsNeutralLocalizationRoute
public void GetVirtualPath_NoTranslationExistsForThreadCulture_ReturnsNeutralLocalizationRoute()
{
using (ShimsContext.Create())
{
// Arrange
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es");
LocalizationCollectionRoute localizationCollectionRoute =
new LocalizationCollectionRoute(new HttpRoute("Home",
new HttpRouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new HttpRouteValueDictionary(),
new HttpRouteValueDictionary(), null));
PrivateObject privateObject = new PrivateObject(localizationCollectionRoute);
IDictionary<string, LocalizationRoute> routes =
(IDictionary<string, LocalizationRoute>)privateObject.GetProperty("LocalizedRoutesContainer");
ShimLocalizationRoute localizationRouteNeutral =
new ShimLocalizationRoute(new LocalizationRoute("Welcome",
new HttpRouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new HttpRouteValueDictionary(),
new HttpRouteValueDictionary(), null, string.Empty));
(new ShimHttpRoute(localizationRouteNeutral)).GetVirtualPathHttpRequestMessageIDictionaryOfStringObject =
(requestContext, values) => new HttpVirtualPathData(localizationRouteNeutral.Instance, "Welcome");
routes[string.Empty] = localizationRouteNeutral;
ShimLocalizationRoute localizationRouteEnglish =
new ShimLocalizationRoute(new LocalizationRoute("Welcome",
new HttpRouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new HttpRouteValueDictionary(),
new HttpRouteValueDictionary(), null, "en"));
(new ShimHttpRoute(localizationRouteEnglish)).GetVirtualPathHttpRequestMessageIDictionaryOfStringObject =
(requestContext, values) => new HttpVirtualPathData(localizationRouteEnglish.Instance, "Welcome");
routes["en"] = localizationRouteEnglish;
ShimLocalizationRoute localizationRouteGerman =
new ShimLocalizationRoute(new LocalizationRoute("Willkommen",
new HttpRouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new HttpRouteValueDictionary(),
new HttpRouteValueDictionary(), null, "de"));
routes["de"] = localizationRouteGerman;
(new ShimHttpRoute(localizationRouteGerman)).GetVirtualPathHttpRequestMessageIDictionaryOfStringObject =
(requestContext, values) => new HttpVirtualPathData(localizationRouteGerman.Instance, "Willkommen");
// Act
IHttpVirtualPathData virtualPathData = localizationCollectionRoute.GetVirtualPath(null,
new HttpRouteValueDictionary());
// Assert
Assert.AreEqual(virtualPathData.Route, localizationRouteNeutral.Instance);
}
}
示例2: DoRun
// Utility function that sets up and executes the run, then asserts the results
private PrivateObject DoRun(BinaryProblem problem, int maximumEvaluations, int seed, double bestQuality, int foundOn) {
var solver = new HeuristicLab.Algorithms.ParameterlessPopulationPyramid.ParameterlessPopulationPyramid();
solver.Problem = problem;
solver.MaximumEvaluations = maximumEvaluations;
solver.Seed = seed;
solver.SetSeedRandomly = false;
PrivateObject hidden = new PrivateObject(solver);
try {
hidden.Invoke("Run", new CancellationToken());
} catch (OperationCanceledException) {
// Ignore
}
Assert.AreEqual(maximumEvaluations, hidden.GetProperty("ResultsEvaluations"), "Total Evaluations");
double foundQuality = (double)hidden.GetProperty("ResultsBestQuality");
Assert.IsTrue(foundQuality.IsAlmost(bestQuality), string.Format("Expected <{0}> Actual <{1}>", bestQuality, foundQuality));
Assert.AreEqual(foundOn, hidden.GetProperty("ResultsBestFoundOnEvaluation"), "Found On");
return hidden;
}
示例3: DispatcherTimerTest
public void DispatcherTimerTest()
{
CountdownTimer timer = new CountdownTimer(new TimeSpan(0, 0, 0, 5), new TimeSpan(0, 0, 0, 1));
PrivateObject privateObject = new PrivateObject(timer);
Timer testTimer = new Timer(5001);
testTimer.Elapsed += (sender, args) =>
{
Assert.IsFalse((bool)privateObject.GetProperty("IsEnabled"));
Assert.AreEqual(new TimeSpan(), (TimeSpan)privateObject.GetField("_startTime"));
};
Assert.AreEqual(new TimeSpan(0, 0, 0, 5), (TimeSpan)privateObject.GetField("_startTime"));
Assert.IsFalse((bool)privateObject.GetProperty("IsEnabled"));
privateObject.Invoke("Start");
Assert.IsTrue((bool)privateObject.GetProperty("IsEnabled"));
testTimer.Start();
}
示例4: GetVirtualPath_OverriddenCultureByRouteDictionaryThatDoesNotExist_ReturnsNeutralLocalizationRoute
public void GetVirtualPath_OverriddenCultureByRouteDictionaryThatDoesNotExist_ReturnsNeutralLocalizationRoute()
{
using (ShimsContext.Create())
{
// Arrange
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
LocalizationCollectionRoute localizationCollectionRoute =
new LocalizationCollectionRoute(new Route("Home",
new RouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new RouteValueDictionary(),
new RouteValueDictionary(), null));
PrivateObject privateObject = new PrivateObject(localizationCollectionRoute);
IDictionary<string, LocalizationRoute> routes =
(IDictionary<string, LocalizationRoute>)privateObject.GetProperty("LocalizedRoutesContainer");
ShimLocalizationRoute localizationRouteNeutral =
new ShimLocalizationRoute(new LocalizationRoute("Welcome",
new RouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new RouteValueDictionary(),
new RouteValueDictionary(), null, string.Empty));
(new ShimRoute(localizationRouteNeutral)).GetVirtualPathRequestContextRouteValueDictionary =
(requestContext, values) => new VirtualPathData(localizationRouteNeutral, "Welcome");
routes[string.Empty] = localizationRouteNeutral;
ShimLocalizationRoute localizationRouteEnglish =
new ShimLocalizationRoute(new LocalizationRoute("Welcome",
new RouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new RouteValueDictionary(),
new RouteValueDictionary(), null, "en"));
(new ShimRoute(localizationRouteEnglish)).GetVirtualPathRequestContextRouteValueDictionary =
(requestContext, values) => new VirtualPathData(localizationRouteEnglish, "Welcome");
routes["en"] = localizationRouteEnglish;
ShimLocalizationRoute localizationRouteGerman =
new ShimLocalizationRoute(new LocalizationRoute("Willkommen",
new RouteValueDictionary() { { "controller", "Home" }, { "action", "Index" } }, new RouteValueDictionary(),
new RouteValueDictionary(), null, "de"));
routes["de"] = localizationRouteGerman;
(new ShimRoute(localizationRouteGerman)).GetVirtualPathRequestContextRouteValueDictionary =
(requestContext, values) => new VirtualPathData(localizationRouteGerman, "Willkommen");
// Act
VirtualPathData virtualPathData = localizationCollectionRoute.GetVirtualPath(null,
new RouteValueDictionary() { { "Culture", "es" } });
// Assert
Assert.AreEqual(virtualPathData.Route, localizationRouteNeutral.Instance);
}
}
示例5: GetReadOnlyAndCompulsory
private void GetReadOnlyAndCompulsory(string contentTypeName, out bool readOnly, out bool compulsory)
{
ContentType contentType = ContentTypeManager.Current.GetContentTypeByName(contentTypeName);
PrivateObject obj = new PrivateObject(contentType);
object o = obj.GetProperty("FieldSettings");
PrivateObject setting = new PrivateObject(((IList)o)[0]);
readOnly = (bool)setting.GetProperty("ReadOnly", new object[0]);
compulsory = (bool)setting.GetProperty("Compulsory", new object[0]);
}
示例6: ChoiceTestOnEnum
private void ChoiceTestOnEnum(string ctd, EnumTestNode.TestEnum loadValue, EnumTestNode.TestEnum selectValue, out ListItemCollection loadedList, out EnumTestNode.TestEnum result, out bool isValid)
{
ContentTypeInstaller.InstallContentType(ctd);
SNC.Content content = SNC.Content.CreateNew("EnumTestNode", _testRoot, "ChoiceTest");
var contentHandler = (EnumTestNode)content.ContentHandler;
contentHandler.TestProperty = loadValue;
//-- simulate ContentView
ChoiceField field = (ChoiceField)content.Fields["TestProperty"];
SenseNet.Portal.UI.Controls.CheckBoxGroup chk = new SenseNet.Portal.UI.Controls.CheckBoxGroup();
PrivateObject chkAcc = new PrivateObject(chk);
chkAcc.Invoke("set_Field", content.Fields["TestProperty"]);
chk.SetData(field.GetData());
ListItemCollection items = (ListItemCollection)chkAcc.GetProperty("InnerListItemCollection");
loadedList = new ListItemCollection();
foreach (ListItem item in items)
{
ListItem newItem = new ListItem(item.Text, item.Value, item.Enabled);
newItem.Selected = item.Selected;
loadedList.Add(newItem);
}
var extraOptionValue = (string)chkAcc.Invoke("get_ExtraOptionValue");
//-- select item
var selectedText = selectValue.ToString();
foreach (ListItem item in items)
item.Selected = item.Text == selectedText;
field.SetData(chk.GetData());
new PrivateObject(field).Invoke("Save", false);
result = (EnumTestNode.TestEnum)contentHandler.TestProperty;
isValid = field.IsValid;
}
示例7: ChoiceTestOnString
private void ChoiceTestOnString(string ctd, string loadValue, string setExtraValue, out ListItemCollection loadedList, out string result, out bool isValid)
{
ContentTypeInstaller.InstallContentType(ctd);
SNC.Content content = SNC.Content.CreateNew("ValidatedContent", _testRoot, "ChoiceTest");
content.ContentHandler["ChoiceTest"] = loadValue;
//-- simulate ContentView
ChoiceField field = (ChoiceField)content.Fields["ChoiceTest"];
SenseNet.Portal.UI.Controls.CheckBoxGroup chk = new SenseNet.Portal.UI.Controls.CheckBoxGroup();
PrivateObject chkAcc = new PrivateObject(chk);
chkAcc.Invoke("set_Field", content.Fields["ChoiceTest"]);
chk.SetData(field.GetData());
ListItemCollection items = (ListItemCollection)chkAcc.GetProperty("InnerListItemCollection");
loadedList = new ListItemCollection();
foreach (ListItem item in items)
{
ListItem newItem = new ListItem(item.Text, item.Value, item.Enabled);
newItem.Selected = item.Selected;
loadedList.Add(newItem);
}
var extraOptionValue = (string)chkAcc.Invoke("get_ExtraOptionValue");
ListItem extraItem = null;
//-- return inverted selection
foreach (ListItem item in items)
{
item.Selected = !item.Selected;
if (item.Value == extraOptionValue)
extraItem = item;
}
if (setExtraValue != null)
{
chkAcc.Invoke("SetExtraValue", setExtraValue);
if (extraItem != null)
extraItem.Selected = true;
}
field.SetData(chk.GetData());
new PrivateObject(field).Invoke("Save", false);
result = (string)content.ContentHandler["ChoiceTest"];
isValid = field.IsValid;
}
示例8: clearMacroEntryListTest
public void clearMacroEntryListTest()
{
Macro_Accessor target = new Macro_Accessor();
target.addMacroEntry(this, new MementoEventArgs("TestMacroEntry", "notExistingPluginName"));
target.addMacroEntry(this, new MementoEventArgs("memName", "Macro"));
PrivateObject macroAccessor = new PrivateObject(target);
MacroEntry rootEntry = macroAccessor.GetProperty("rootEntry", null) as MacroEntry;
Assert.IsNotNull(rootEntry, "Macro didnt process the add operation correctly.");
Assert.IsTrue(1 == rootEntry.macroEntries.Count, "Add macro operation didnt change the entries property.");
target.clearMacroEntryList();
Assert.IsTrue(0 == rootEntry.macroEntries.Count, "Clear operation didnt remove all items.");
}
示例9: SetupTest
public void SetupTest()
{
//arrange
var pvt = new PrivateObject(_imapMailBox);
//act
_imapMailBox.Setup().Wait();
//assert
var result = (bool)pvt.GetProperty("SetupInProgress");
Assert.IsFalse(result);
_worker.Verify(x => x.GetMailFolders());
}
示例10: Test_GIL_Lock
public void Test_GIL_Lock()
{
var py = new PrivateObject(Python.Instance());
var api = (PythonAPI)py.GetProperty("Api");
var gil = api.PyGILState_Ensure();
var sw = new Stopwatch();
sw.Start();
var t = new Thread(() => {
Thread.Sleep(2000);
api.PyGILState_Release(gil);
});
t.Start();
var anotherGil = api.PyGILState_Ensure();
Assert.GreaterOrEqual(sw.ElapsedMilliseconds, 2000);
api.PyGILState_Release(anotherGil);
}