public void TaskThrowsException() { TestAA.Act(() => Task.FromException(new ApplicationException())).Assert <ApplicationException>(); TestAA.Act(task: async() => await Task.FromException(new ApplicationException())).Assert <ApplicationException>(); TestAA.Act(() => new ValueTask(Task.FromException(new ApplicationException()))).Assert <ApplicationException>(); }
public void LambdaAssert() { TestAA.Act(() => int.Parse("123")).Assert( @return: ret => Assert.AreEqual(123, ret) , exception: ex => Assert.IsNull(ex) ); }
public void TaskSynchronously() { TestAA.Act(() => Task.FromResult(123)).Assert(123); TestAA.Act(task: async() => await Task.FromResult(123)).Assert(123); TestAA.Act(() => new ValueTask <int>(123)).Assert(123); }
public void Act() { Action TestCase(int testNumber, Action act, Type exceptionType, Type expectedExceptionType = null) => () => { var msg = "No." + testNumber; // Act TestActual testActual = default; Exception exception = null; try { testActual = TestAA.Act(act); } catch (Exception ex) { exception = ex; } // Assert if (exception == null) { Assert.AreEqual(typeof(TestActual), testActual.GetType(), msg); Assert.AreEqual(exceptionType, testActual.Exception?.GetType(), msg); } Assert.AreEqual(expectedExceptionType, exception?.GetType(), msg); }; foreach (var action in new[] {
public void RawTask() { var task = Task.FromResult(123); TestAA.Act <Task <int> >(() => task).Assert(task); TestAA.Act <ValueTask <int> >(() => new ValueTask <int>(123)).Assert(new ValueTask <int>(123)); }
public void OutParameter() { int result = default; TestAA.Act(() => int.TryParse("123", out result)).Assert(true); // Additional Assert Assert.AreEqual(123, result); }
public void ImmediateEnumerableEvaluation() { TestAA.Act(() => CreateEnumerable()).Assert <ApplicationException>(); IEnumerable <int> CreateEnumerable() { yield return(123); throw new ApplicationException(); } }
public static void Test() { IDerived x = new Derived { V0 = 0, V1 = 1 }; Action TestCase(int testNo, object y, Type?expectedException = null) => () => { TestAA .Act(() => x.AssertIs(y)) .Assert(expectedException, message: $"No.{testNo}"); }; new[] { TestCase(0, y: new { V1 = 1 }, expectedException: typeof(PrimitiveAssertFailedException)), // y が IDerived のデータメンバーを全て実装していないので失敗すべき。 TestCase(1, y: new { V0 = 0, V1 = 1 }), }.Invoke(); }
public void IsNumeric() { Action TestCase(int testNo, Type type, bool expected) => () => { TestAA .Act(() => Numeric.IsNumeric(type)) .Assert(expected, message: $"No.{testNo}"); }; new[] { TestCase(0, typeof(sbyte), expected: true), TestCase(1, typeof(byte), expected: true), TestCase(2, typeof(short), expected: true), TestCase(3, typeof(ushort), expected: true), TestCase(4, typeof(int), expected: true), TestCase(5, typeof(uint), expected: true), TestCase(6, typeof(long), expected: true), TestCase(7, typeof(ulong), expected: true), TestCase(8, typeof(float), expected: true), TestCase(9, typeof(double), expected: true), TestCase(10, typeof(decimal), expected: true), TestCase(50, typeof(sbyte?), expected: true), TestCase(51, typeof(byte?), expected: true), TestCase(52, typeof(short?), expected: true), TestCase(53, typeof(ushort?), expected: true), TestCase(54, typeof(int?), expected: true), TestCase(55, typeof(uint?), expected: true), TestCase(56, typeof(long?), expected: true), TestCase(57, typeof(ulong?), expected: true), TestCase(58, typeof(float?), expected: true), TestCase(59, typeof(double?), expected: true), TestCase(60, typeof(decimal?), expected: true), TestCase(100, typeof(BigInteger), expected: false), TestCase(101, typeof(object), expected: false), TestCase(102, typeof(ValueType), expected: false), TestCase(103, typeof(Tuple <int>), expected: false), TestCase(104, typeof(ValueTuple <int>), expected: false), TestCase(105, typeof(Enum), expected: false), TestCase(106, typeof(IntPtr), expected: false), TestCase(107, typeof(UIntPtr), expected: false), TestCase(108, typeof(Version), expected: false), }.Invoke(); }
public void Encode() { Action TestCase(TestNumber testNumber, byte[] bytes, bool toUpper, string expected) => () => { TestAA .Act(() => Base16.Encode(bytes, toUpper)) .Assert(expected, message: testNumber); }; var rndBytes = Rand.Bytes(); new[] { TestCase(1, Bytes(), toUpper: false, expected: ""), TestCase(2, Bytes(0x0f), toUpper: false, expected: "0f"), TestCase(3, Bytes(0x0f, 0xf0), toUpper: false, expected: "0ff0"), TestCase(4, Bytes(0x0f, 0xf0), toUpper: true, expected: "0FF0"), TestCase(10, Bytes(0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef), toUpper: false, expected: "0123456789abcdef"), TestCase(11, Bytes(0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef), toUpper: true, expected: "0123456789ABCDEF"), TestCase(50, rndBytes, toUpper: false, expected: BitConverter.ToString(rndBytes).Replace("-", "").ToLowerInvariant()), TestCase(51, rndBytes, toUpper: true, expected: BitConverter.ToString(rndBytes).Replace("-", "").ToUpperInvariant()), }.Run(); }
private static Action TestCase(int testNo, Type?target, object?x, object?y, Type?expectedException = null) => () => { TestAA .Act(() => x.AssertIs(target, y, $"No.{testNo}")) .Assert(expectedException, message: $"No.{testNo}"); };
public void ThrowsException() { TestAA.Act(() => int.Parse("abc")).Assert <FormatException>(); }
public void Basic() { TestAA.Act(() => int.Parse("123")).Assert(123); }
static Action TestCase <T>(int testNo, T x, object y, Type?expectedException = null) => () => { TestAA .Act(() => x.AssertIs(y, $"No.{testNo}")) .Assert(expectedException, message: $"No.{testNo}"); };
public void IsPrimitiveData() { Action TestCase(int testNo, Type type, bool expected) => () => { TestAA .Act(() => type.IsPrimitiveData()) .Assert(expected, message: $"No.{testNo}"); }; new[] { TestCase(0, typeof(bool), expected: true), TestCase(1, typeof(char), expected: true), TestCase(2, typeof(DateTime), expected: true), TestCase(3, typeof(DateTimeOffset), expected: true), TestCase(4, typeof(TimeSpan), expected: true), TestCase(5, typeof(Guid), expected: true), TestCase(6, typeof(StubEnum), expected: true), TestCase(7, typeof(sbyte), expected: true), TestCase(8, typeof(byte), expected: true), TestCase(9, typeof(short), expected: true), TestCase(10, typeof(ushort), expected: true), TestCase(11, typeof(int), expected: true), TestCase(12, typeof(uint), expected: true), TestCase(13, typeof(long), expected: true), TestCase(14, typeof(ulong), expected: true), TestCase(15, typeof(float), expected: true), TestCase(16, typeof(double), expected: true), TestCase(17, typeof(decimal), expected: true), TestCase(30, typeof(string), expected: true), TestCase(31, typeof(Uri), expected: true), TestCase(50, typeof(bool?), expected: true), TestCase(51, typeof(char?), expected: true), TestCase(52, typeof(DateTime?), expected: true), TestCase(53, typeof(DateTimeOffset?), expected: true), TestCase(54, typeof(TimeSpan?), expected: true), TestCase(55, typeof(Guid?), expected: true), TestCase(56, typeof(StubEnum?), expected: true), TestCase(57, typeof(sbyte?), expected: true), TestCase(58, typeof(byte?), expected: true), TestCase(59, typeof(short?), expected: true), TestCase(60, typeof(ushort?), expected: true), TestCase(61, typeof(int?), expected: true), TestCase(62, typeof(uint?), expected: true), TestCase(63, typeof(long?), expected: true), TestCase(64, typeof(ulong?), expected: true), TestCase(65, typeof(float?), expected: true), TestCase(66, typeof(double?), expected: true), TestCase(67, typeof(decimal?), expected: true), TestCase(100, typeof(BigInteger), expected: false), TestCase(101, typeof(object), expected: false), TestCase(102, typeof(ValueType), expected: false), TestCase(103, typeof(Tuple <int>), expected: false), TestCase(104, typeof(ValueTuple <int>), expected: false), TestCase(105, typeof(Array), expected: false), TestCase(106, typeof(List <int>), expected: false), TestCase(107, typeof(ArraySegment <int>), expected: false), TestCase(108, typeof(Enum), expected: false), TestCase(109, typeof(Exception), expected: false), TestCase(110, typeof(IntPtr), expected: false), TestCase(111, typeof(UIntPtr), expected: false), TestCase(112, typeof(Type), expected: true), TestCase(113, typeof(Version), expected: false), }.Invoke(); }