Beispiel #1
0
        public void AMockFailsVerifyAllTest()
        {
            Scenario("AMockTest")
            .Given(AMock <ISpeaker>()
                   .WhereMethod(t => t.Says())
                   .Returns("DoDah")
                   .Instance)
            .WhenNothing()
            .Then(() => { /*Scenario passes but verify should fail*/ });

            MockException thrown = null;

            try
            {
                //force scenario completion and assertions
                AfterTest();
            }
            catch (Exception e)
            {
                thrown = e.InnerException as MockException;
            }

            AnException.With()
            .Type("Moq.MockVerificationException")
            .Message(AString.Containing("ISpeaker t => t.Says()"))
            .AssertMatch(thrown);
        }
        public void TypeMatchTest()
        {
            AssertPasses(new MyException(), AnException.With().Type <Exception>());
            AssertPasses(new MyException(), AnException.With().Type <MyException>());
            AssertPasses(new MyException(), AnException.With().Type(typeof(MyException).FullName));

            AssertFails(new MyException(), AnException.With().Type <InvalidOperationException>());
            AssertFails(new MyException(), AnException.With().Type(typeof(Exception).FullName));
        }
        public void MessageMatchTest()
        {
            AssertPasses(new MyException("MyMessage"), AnException.With().Message("MyMessage"));
            AssertPasses(new MyException("MyMessage"), AnException.With().Message(AString.StartingWith("My")));


            AssertFails(new MyException("MyMessage"), AnException.With().Message("OtherMessage"));
            AssertFails(new MyException("MyMessage"), AnException.With().Message(AString.StartingWith("Other")));
        }
 public void StackTraceMatchTest()
 {
     AssertPasses(NewThrownException(), AnException.With().StackTrace(AString.MatchingAntPattern("NewThrownException?()")));
     AssertFails(NewThrownException(), AnException.With().StackTrace(AString.MatchingAntPattern("SomeOtherMethod?()")));
 }
Beispiel #5
0
 public void For_That_Throws()
 {
     AssertPasses(() => Expect.For("myMsg").That(() => { throw new Exception("SomeError"); }).Throws(AnException.With().Message("SomeError")));
     AssertFails(() => Expect.For("myMsg").That(() => { throw new Exception("Wrong Error Msg"); }).Throws(AnException.With().Message("SomeError")));
 }