コード例 #1
0
        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[] {
コード例 #2
0
ファイル: OrMatcherTests.cs プロジェクト: Carbonfrost/f-spec
        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"
            })));
        }
コード例 #3
0
        public void Ctor()
        {
            // Act
            var ret = new TestActual();

            // Assert
            Assert.IsNull(ret.Exception);
        }
コード例 #4
0
        public void Ctor_Exception()
        {
            var ex = new DummyException();

            // Act
            var ret = new TestActual <DummyObject>(exception: ex);

            // Assert
            Assert.AreEqual(default, ret.Return);
コード例 #5
0
        public void Ctor()
        {
            // Act
            var ret = new TestActual <DummyObject>();

            // Assert
            Assert.IsNull(ret.Return);
            Assert.IsNull(ret.Exception);
        }
コード例 #6
0
ファイル: NotMatcherTests.cs プロジェクト: Carbonfrost/f-spec
        public void Matches_should_detect_error()
        {
            var subj = new NotMatcher <int>(
                Matchers.Equal(20)
                );
            var val = subj.Matches(TestActual.Value(20));

            Assert.False(val);
        }
コード例 #7
0
ファイル: NotMatcherTests.cs プロジェクト: Carbonfrost/f-spec
        public void Matches_should_apply_nominal()
        {
            var subj = new NotMatcher <int>(
                Matchers.Equal(20)
                );
            var val = subj.Matches(TestActual.Value(10));

            Assert.True(val);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        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();
            }
        }
コード例 #14
0
ファイル: OrMatcherTests.cs プロジェクト: Carbonfrost/f-spec
        public void Matches_should_detect_nominal()
        {
            var subj = new OrMatcher <string>(Matchers.BeEmpty(), Matchers.HaveCount(0));

            Assert.True(subj.Matches(TestActual.Value("")));
        }