quantum-space-buddies/QSBTests/UtilityTests.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2021-02-12 13:29:01 +00:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
2021-12-27 02:17:04 +00:00
using OWML.Utils;
2021-02-12 13:29:01 +00:00
using QSB.Utility;
2021-12-27 02:17:04 +00:00
using System;
2021-02-12 13:29:01 +00:00
namespace QSBTests
{
[TestClass]
public class UtilityTests
{
[TestMethod]
2021-02-13 09:07:39 +00:00
public void IsInUnitTest()
2021-02-12 13:29:01 +00:00
=> Assert.IsTrue(UnitTestDetector.IsInUnitTest, "UnitTestDetector is not working.");
2021-12-27 02:17:04 +00:00
private class A
{
public virtual string Method() => nameof(A);
public virtual string MethodArgs(int num) => nameof(A);
public virtual void VoidMethod() { }
public virtual void GenericMethod<T>(T t) { }
}
private class B : A
{
public override string Method() => nameof(B);
public override string MethodArgs(int num) => nameof(B);
public override void VoidMethod() { }
public override void GenericMethod<T>(T t) { }
}
[TestMethod]
public void TestInvokeBase()
{
var a = new A();
Assert.AreEqual(nameof(A), a.Method());
A b = new B();
Assert.AreEqual(nameof(B), b.Method());
Assert.AreEqual(nameof(B), b.Invoke<string>(nameof(b.Method)));
Assert.AreEqual(nameof(A), b.InvokeBase<string>(nameof(b.Method)));
Assert.AreEqual(nameof(A), b.InvokeBase<string>(nameof(b.MethodArgs), 1));
b.InvokeBase(nameof(b.VoidMethod));
Assert.ThrowsException<MissingMethodException>(() =>
b.InvokeBase(nameof(b.GenericMethod), (object)null));
}
2021-02-12 13:29:01 +00:00
}
}