本文整理汇总了C#中PrivateType类的典型用法代码示例。如果您正苦于以下问题:C# PrivateType类的具体用法?C# PrivateType怎么用?C# PrivateType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrivateType类属于命名空间,在下文中一共展示了PrivateType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstanceTest
public void InstanceTest()
{
try
{
InvisibleForm actual;
actual = InvisibleForm.Instance;
Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
// Reset and try again
PrivateType invisibleForm = new PrivateType(typeof(InvisibleForm));
invisibleForm.SetStaticFieldOrProperty("instanceForm", null);
actual = InvisibleForm.Instance;
Assert.IsNotNull(actual, "InvisibleForm.Instance returned null");
Assert.AreSame(actual, invisibleForm.GetStaticFieldOrProperty("instanceForm"), "Second call to the property should return the same opbject instance.");
Form f = actual as Form;
Assert.IsFalse(f.Visible, "InvisibleForm should not be visible");
}
catch (Exception ex)
{
// Use try catch to test a workaround on CI build (AppVeyor)
Console.WriteLine(ex.Message);
}
}
示例2: MyTestCleanup
public void MyTestCleanup()
{
PrivateType privateWindowType = new PrivateType(typeof(VSWindows));
privateWindowType.SetStaticFieldOrProperty("instance", null);
this.serviceProvider = null;
}
示例3: KeyGenerationTest
public void KeyGenerationTest()
{
PrivateType pt = new PrivateType(typeof(AsymmetricBlobCryptoProvider));
byte[] key = (byte[])pt.InvokeStatic("GenerateRandomKey");
byte[] encryptedKey;
byte[] decryptedKey;
var rsa = new RSACryptoServiceProvider();
rsa.ImportCspBlob(testCspBlob);
using (ICspProxy cspProxy = new DisposingCspProxy(rsa, rsa.KeySize))
{
encryptedKey = cspProxy.Encrypt(key);
decryptedKey = cspProxy.Decrypt(encryptedKey);
}
// The two keys shouldn't be the same...
Assert.IsFalse(key.SequenceEqual(encryptedKey));
// And we expect it to grow to the same size as the RSA Key
Assert.IsTrue(encryptedKey.Length == 4096 / 8);
// Sanity check, it should be 256 bit / 32 bytes and not contain any zeros.
Assert.IsTrue(decryptedKey.Length == 256/8, "Key length is incorrect");
Assert.IsTrue(decryptedKey[0] != 0, "Key starts with an empty byte");
// And of course, the round tripped key should match original
Assert.IsTrue(key.SequenceEqual(decryptedKey));
}
开发者ID:DataWingSoftware,项目名称:azure-encryption-extensions,代码行数:30,代码来源:AsymmetricBlobCryptoProviderTests.cs
示例4: Init
public void Init()
{
PrivateType p = new PrivateType(typeof(Dev2DataLanguageParser));
var cache = p.GetStaticField("_expressionCache") as ConcurrentDictionary<string, IList<IIntellisenseResult>>;
Assert.IsNotNull(cache);
cache.Clear();
var cache2 = p.GetStaticField("_payloadCache") as ConcurrentDictionary<Tuple<string, string>, IList<IIntellisenseResult>>;
Assert.IsNotNull(cache2);
cache2.Clear();
Monitor.Enter(DataListSingletonTest.DataListSingletonTestGuard);
var testEnvironmentModel = ResourceModelTest.CreateMockEnvironment();
_resourceModel = new ResourceModel(testEnvironmentModel.Object)
{
ResourceName = "test",
ResourceType = ResourceType.Service,
DataList = @"
<DataList>
<Scalar/>
<Country/>
<State />
<City>
<Name/>
<GeoLocation />
</City>
</DataList>
"
};
IDataListViewModel setupDatalist = new DataListViewModel();
DataListSingleton.SetDataList(setupDatalist);
DataListSingleton.ActiveDataList.InitializeDataListViewModel(_resourceModel);
}
示例5: Initialize
public void Initialize()
{
PrivateType pt = new PrivateType(typeof(SQLiteRepositoryClient));
pt.SetStaticField("dataSource", filename);
wait = new AutoResetEvent(false);
}
示例6: GetPublicStaticPropertyValue
public void GetPublicStaticPropertyValue()
{
dynamic subjectPO = new PrivateType<Subject>();
bool actual = subjectPO.publicStaticProperty;
Assert.IsFalse(actual);
}
示例7: TestGetApiURL
public void TestGetApiURL()
{
PrivateType grinder = new PrivateType(typeof(MeatGrinder));
PrivateObject obj = new PrivateObject(grinder);
var retval = obj.Invoke("GetApiURL");
Assert.AreEqual(1, 1);
}
示例8: GetPublicStaticFieldValue
public void GetPublicStaticFieldValue()
{
dynamic subjectPO = new PrivateType<Subject>();
int actual = subjectPO.publicStaticField;
Assert.AreEqual(Subject.FieldInitialValue, actual);
}
示例9: TestCountBulls
public void TestCountBulls()
{
bool[] isBull = new bool[4];
PrivateType pr = new PrivateType(typeof(Game));
pr.SetStaticFieldOrProperty("secretNumberAsString", "1234");
int res = Game.CountBulls("1235", 0, isBull);
Assert.AreEqual(3, res);
}
示例10: ReplaceNulls
public void ReplaceNulls()
{
PrivateType internalAssertEx = new PrivateType(typeof(AssertEx));
object oNull = null;
Assert.AreEqual("(null)", internalAssertEx.InvokeStatic("ReplaceNulls", oNull), "AssertEx.ReplaceNulls didn't return the correct value.");
Assert.AreEqual("teststring", internalAssertEx.InvokeStatic("ReplaceNulls", "teststring"), "AssertEx.ReplaceNulls didn't return the correct value.");
Assert.AreEqual("test\\0string", internalAssertEx.InvokeStatic("ReplaceNulls", "test\0string"), "AssertEx.ReplaceNulls didn't return the correct value.");
}
示例11: TestBaseClass
protected TestBaseClass(object instanceToTest, Type typeToTest, int? presentationMethodID)
{
if (instanceToTest != null)
InstanceToTest = new PrivateObject(instanceToTest);
if (typeToTest != null)
TypeToTest = new PrivateType(typeToTest);
}
示例12: InvokePrivateMethodThatReturnsBooleanWithParameter
public void InvokePrivateMethodThatReturnsBooleanWithParameter()
{
dynamic subjectPO = new PrivateType<Subject>();
bool result = subjectPO.privateStaticMethodThatReturnsBooleanWithParameter(true);
Assert.IsTrue(result);
}
示例13: SetTestDateTime
/// <summary>
/// Injects current UTC time as fixed constant as replacement of DateTime.UtcNow for testing purposes
/// </summary>
internal static void SetTestDateTime()
{
var moment = new PrivateType(typeof(Moment));
var current = DateTime.UtcNow;
// reduce precision to seconds, because Ticks may be extracted by SQL server
DateTime precise = new DateTime(current.Year, current.Month, current.Day, current.Hour, current.Minute, current.Second);
var customMoment = new InjectionDateTime { UtcNow = precise };
moment.SetStaticField("service", customMoment);
}
示例14: TestIfCorrectNumbersOfMinesAreCreated
public void TestIfCorrectNumbersOfMinesAreCreated()
{
PrivateType privateType = new PrivateType(typeof(GameBoardGenerator));
var fieldSize = 1;
int startRandomRange = ((15 * fieldSize * fieldSize) / 100) + 1;
int endRandomRange = ((30 * fieldSize * fieldSize) / 100) + 1;
int randomCheck = (int)privateType.InvokeStatic("RandomGenerator", startRandomRange, endRandomRange);
Assert.IsTrue(randomCheck >= 1);
}
示例15: TestGetDestFilePath_NoExtensions
public void TestGetDestFilePath_NoExtensions()
{
const string expected = @"C:\Garmin\Activities\1990-01-01-00-00-00_duplicated";
const string srcPath = @"C:\Garmin\Activities\1990-01-01-00-00-00";
var pt = new PrivateType(typeof(Program));
var actual = (string)pt.InvokeStatic("GetDestFilePath", new object[] { srcPath });
Assert.AreEqual(expected, actual);
}