Exemplo n.º 1
0
        public void CacheProxyRecordsException()
        {
            var exception = new CustomException();
            var repo      = new FakeRepositoryThrows(exception);

            var source = Mimic.Cache <IFakeRepository>(repo, new History());

            try
            {
                source.ParameterlessFn();
                Assert.Fail("Expect CustomException");
            }
            catch (CustomException)
            {
            }

            var log = Mimic.GetHistory(source);

            var testee = Mimic.Stub <IFakeRepository>(log);

            try
            {
                testee.ParameterlessFn();
                Assert.Fail();
            }
            catch (CustomException e)
            {
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 2
0
        public void ExampleFakeRepositoryThrowsBehaviour_OnParameterlessFunction()
        {
            var exception = new ApplicationException("message");
            var repo      = new FakeRepositoryThrows(exception);

            repo.ParameterlessFn();
        }
Exemplo n.º 3
0
        public void CanSerialiseExceptionInHistoryLog()
        {
            var exception = new CustomException();
            var repo      = new FakeRepositoryThrows(exception);

            var source = Mimic.Record <IFakeRepository>(repo);

            try
            {
                source.ParameterlessFn();
                Assert.Fail("Expect CustomException");
            }
            catch (CustomException)
            {
            }
            var logSerialised = Mimic.SerialiseHistory(source);

            var testee = Mimic.Stub <IFakeRepository>(Mimic.DeserialiseHistory(logSerialised));

            try
            {
                testee.ParameterlessFn();
                Assert.Fail();
            }
            catch (CustomException e)
            {
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 4
0
        public void CacheProxyReplaysException()
        {
            var exceptionMessage = "message";
            var exception        = new CustomException(exceptionMessage);
            var repo             = new FakeRepositoryThrows(exception);

            var source = Mimic.Record <IFakeRepository>(repo);

            try
            {
                source.ParameterlessFn();
                Assert.Fail("Expect CustomException");
            }
            catch (CustomException)
            {
            }

            var log = Mimic.GetHistory(source);

            var otherRepo = new FakeRepositoryDoubles();
            var testee    = Mimic.Cache <IFakeRepository>(otherRepo, log);

            try
            {
                testee.ParameterlessFn();
                Assert.Fail();
            }
            catch (CustomException e)
            {
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 5
0
        public void RecorderProxyBubblesException()
        {
            var exception = new CustomException();
            var repo      = new FakeRepositoryThrows(exception);

            var testee = Mimic.Record <IFakeRepository>(repo);

            testee.ParameterlessFn();
        }
Exemplo n.º 6
0
        public void WhenLoadingHistoryIntoReplayer_IfThrownExceptionHasNoDefaultConstructor_ThenThrow()
        {
            var exception = new ExceptionWithoutDefaultConstructor("required parameter");
            var repo      = new FakeRepositoryThrows(exception);

            var source = Mimic.Record <IFakeRepository>(repo);

            try
            {
                source.ParameterlessFn();
                Assert.Fail("Expect Exception");
            }
            catch (ExceptionWithoutDefaultConstructor)
            {
            }
            var log = Mimic.GetHistory(source);

            var replayer = Mimic.Stub <IFakeRepository>(log);
        }
Exemplo n.º 7
0
        public void BehaviourVerifier_VerifiesExceptionThrown_PassesWhenExpectedAndDoesOccur()
        {
            var repo     = new FakeRepositoryThrows(new CustomException());
            var recorder = Mimic.Record <IFakeRepository>(repo);

            try
            {
                recorder.Function(1);
                Assert.Fail();
            }
            catch (CustomException)
            {}

            History history = Mimic.GetHistory(recorder);

            var testee = Mimic.GetBehaviourVerifier(history);
            var result = testee.ConfirmBehaviourHasNotChanged(new FakeRepositoryThrows(new CustomException()));

            Assert.True(result);
        }