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 Matches_should_detect_contra_nominal() { var subj = Matchers.Or(Matchers.BeEmpty(), Matchers.HaveCount(0)); Assert.False(subj.Matches(TestActual.Value(new List <string> { "A", "B" }))); }
public void Ctor() { // Act var ret = new TestActual(); // Assert Assert.IsNull(ret.Exception); }
public void Ctor_Exception() { var ex = new DummyException(); // Act var ret = new TestActual <DummyObject>(exception: ex); // Assert Assert.AreEqual(default, ret.Return);
public void Ctor() { // Act var ret = new TestActual <DummyObject>(); // Assert Assert.IsNull(ret.Return); Assert.IsNull(ret.Exception); }
public void Matches_should_detect_error() { var subj = new NotMatcher <int>( Matchers.Equal(20) ); var val = subj.Matches(TestActual.Value(20)); Assert.False(val); }
public void Matches_should_apply_nominal() { var subj = new NotMatcher <int>( Matchers.Equal(20) ); var val = subj.Matches(TestActual.Value(10)); Assert.True(val); }
public void Matches_should_detect_empty_nominal_func() { var subj = new SatisfyAnyMatcher <int[]>( Matchers.BeEmpty(), Matchers.HaveCount(10) ); var val = subj.Matches(TestActual.Value(new int[] { 2 })); Assert.False(val); }
public void Matches_should_apply_Any_nominal() { var subj = new SatisfyAnyMatcher <int[]>( Matchers.BeEmpty(), Matchers.HaveCount(10) ); var val = subj.Matches(TestActual.Value(new int[0])); Assert.True(val); }
public void Matches_should_fail_on_null_thunk() { var subj = new InstanceOfMatcher(typeof(string)); try { subj.Matches(TestActual.Value((string)null)); Assert.Fail("Expected to fail with AssertException -- can't match null"); } catch (AssertVerificationException) { Assert.Pass(); } }
public new void GetHashCode() { Action TestCase(int testNumber, DummyException exception) => () => { var testActual = new TestActual(exception); // GetHashCode() は環境によって戻り値が変わるので、例外が起こらない事だけ確認。 testActual.GetHashCode(); }; foreach (var action in new[] { TestCase(0, null), TestCase(1, new DummyException()), }) { action(); } }
public void Ctor_Args() { Action TestCase(int testNumber, Exception exception) => () => { var msg = "No." + testNumber; // Act var ret = new TestActual(exception); // Assert Assert.AreEqual(exception, ret.Exception, msg); }; foreach (var action in new[] { TestCase(0, null), TestCase(1, new DummyException()), }) { action(); } }
public void Ctor_TReturn() { Action TestCase(int testNumber, DummyObject @return) => () => { var msg = "No." + testNumber; // Act var ret = new TestActual <DummyObject>(@return: @return); // Assert Assert.AreEqual(@return, ret.Return, msg); Assert.IsNull(ret.Exception, msg); }; var obj = new DummyObject(); foreach (var action in new[] { TestCase(0, obj), TestCase(1, null), }) { action(); } }
public void Matches_should_detect_nominal() { var subj = new OrMatcher <string>(Matchers.BeEmpty(), Matchers.HaveCount(0)); Assert.True(subj.Matches(TestActual.Value(""))); }