Beispiel #1
0
        public void InvokeCountTooHighFails()
        {
            var mock = FluentMock <IMyTestInterface> .With()
                       .WhereMethod(x => x.Foo()).IsCalled(3).Times()
                       .Returns("hi");

            var instance = mock.Instance;

            instance.Foo();
            instance.Foo();
            instance.Foo();

            Exception error = null;

            try
            {
                instance.Foo();
            }
            catch (Exception e)
            {
                error = e;
            }
            Assert.NotNull(error, "expected failure on too many method calls");
            Assert.IsTrue(error.Message.Contains("unexpectedly performed 4 times"));
            Assert.IsTrue(error.Message.Contains("expected 3 times"));
        }
Beispiel #2
0
        public void InvokeCountTooLowFails()
        {
            var mock = FluentMock <IMyTestInterface> .With()
                       .WhereMethod(x => x.Foo).IsCalled(3).Times()
                       .Returns("hi");

            var instance = mock.Instance;

            var foo = instance.Foo;

            foo = instance.Foo;

            Exception error = null;

            try
            {
                mock.OnScenarioEnd();
            }
            catch (Exception e)
            {
                error = e;
            }
            Assert.NotNull(error, "expected failure on too few invokes");
            Assert.IsTrue(error.Message.Contains("unexpectedly performed 2 times"));
            Assert.IsTrue(error.Message.Contains("expected 3 times"));
        }
Beispiel #3
0
        public void InvokeCountOkPasses()
        {
            var mock = FluentMock <IMyTestInterface> .With().WhereMethod(x => x.Foo()).IsCalled(3).Times();

            var instance = mock.Instance;

            instance.Foo();
            instance.Foo();
            instance.Foo();

            mock.OnScenarioEnd();
        }