Exemple #1
0
        public void CacheProxyPassesUncachedCallsToTheBaseType_WhenCheckingNULL()
        {
            var data = new DataStructure {
                Age = 21, Name = "Jimmy"
            };
            var returnValue = new DataStructure {
                Age = 22, Name = "Janey"
            };
            var returnValue2 = new DataStructure {
                Age = 11, Name = "Jimbo"
            };
            var repo = new ComplexRepositoryReturnsWhateverItWasSetupWith(returnValue);

            var           recorder    = Mimic.Record <IComplexRepository>(repo);
            DataStructure firstResult = recorder.GetRelated(data);

            string serialisedHistory = Mimic.SerialiseHistory(recorder);
            var    history           = Mimic.DeserialiseHistory(serialisedHistory);

            var replayer = Mimic.Cache <IComplexRepository>(
                new ComplexRepositoryReturnsWhateverItWasSetupWith(returnValue2), history);
            DataStructure result = replayer.GetRelated(null);

            Assert.AreEqual(returnValue2.Name, result.Name, "otherwise this is because it was cached");
            Assert.AreEqual(returnValue2.Age, result.Age, "otherwise this is because it was cached");
        }
Exemple #2
0
        public void DerivedReturnValue_WhenMatchesExpectation()
        {
            var ds = new DataStructure()
            {
                Age = 13, Name = "jimbob"
            };
            var repo = new ComplexRepositoryReturnsWhateverItWasSetupWith(
                new DerivedDataStructure()
            {
                Balance = 2
            });

            var recorder = Mimic.Record <IComplexRepository>(repo);

            recorder.GetRelated(ds);
            History history = Mimic.GetHistory(recorder);

            var testee = Mimic.GetBehaviourVerifier(history);
            var result = testee.ConfirmBehaviourHasNotChanged(
                new ComplexRepositoryReturnsWhateverItWasSetupWith(
                    new DerivedDataStructure()
            {
                Balance = 2
            }));

            Assert.IsTrue(result);
        }
Exemple #3
0
        public void NullParameter_WhenMatchesExpectation()
        {
            var repo     = new ComplexRepositoryReturnsWhateverItWasSetupWith(new DataStructure());
            var recorder = Mimic.Record <IComplexRepository>(repo);

            recorder.GetRelated(null);
            History history = Mimic.GetHistory(recorder);

            var testee = Mimic.GetBehaviourVerifier(history);
            var result = testee.ConfirmBehaviourHasNotChanged(new ComplexRepositoryReturnsWhateverItWasSetupWith(new DataStructure()));

            Assert.IsTrue(result);
        }
Exemple #4
0
        public void HistoryWithOneCallThatDoesNotMatchReturnValueVerifiesFail_WhenNullIsExpected()
        {
            var ds = new DataStructure()
            {
                Age = 13, Name = "jimbob"
            };
            var repo     = new ComplexRepositoryReturnsWhateverItWasSetupWith(null);
            var recorder = Mimic.Record <IComplexRepository>(repo);

            recorder.GetRelated(ds);
            History history = Mimic.GetHistory(recorder);

            var testee = Mimic.GetBehaviourVerifier(history);
            var result = testee.ConfirmBehaviourHasNotChanged(
                new ComplexRepositoryReturnsWhateverItWasSetupWith(new DataStructure()));

            Assert.IsFalse(result);
        }
Exemple #5
0
        public void WhenIModifyAReturnValueAfterLoggingIt_TheOriginalVerionShouldBeLogged()
        {
            var data = new DataStructure {
                Age = 21, Name = "Jimmy"
            };
            var           repo        = new ComplexRepositoryReturnsWhateverItWasSetupWith(data);
            var           recorder    = Mimic.Record <IComplexRepository>(repo);
            DataStructure firstResult = recorder.GetRelated(null);

            data.Age++;

            string serialisedHistory = Mimic.SerialiseHistory(recorder);
            var    history           = Mimic.DeserialiseHistory(serialisedHistory);

            var           replayer = Mimic.Stub <IComplexRepository>(history);
            DataStructure result   = replayer.GetRelated(null);

            Assert.AreEqual(21, result.Age);
        }
Exemple #6
0
        public void NullReturnedCallIsRecordedWithoutLossOfInformationWhenReplayed()
        {
            var data = new DataStructure {
                Age = 21, Name = "Jimmy"
            };
            var           repo        = new ComplexRepositoryReturnsWhateverItWasSetupWith(null);
            var           recorder    = Mimic.Record <IComplexRepository>(repo);
            DataStructure firstResult = recorder.GetRelated(data);

            string serialisedHistory = Mimic.SerialiseHistory(recorder);
            var    history           = Mimic.DeserialiseHistory(serialisedHistory);


            var replayer = Mimic.Cache <IComplexRepository>(
                new ComplexRepository2(), history);
            DataStructure result = replayer.GetRelated(data);

            Assert.AreEqual(firstResult, result, "otherwise this is because it was not cached");
        }
Exemple #7
0
        public void ReplaySavesCachedCombinedHistory()
        {
            var response = new DataStructure {
                Age = 21, Name = "Jimmy"
            };
            var repo     = new ComplexRepositoryReturnsWhateverItWasSetupWith(response);
            var recorder = Mimic.Record <IComplexRepository>(repo);

            var           pastHistory = Mimic.GetHistory(recorder);
            var           cacher      = Mimic.Cache <IComplexRepository>(repo, pastHistory);
            DataStructure firstResult = cacher.GetRelated(null);

            var cachedHistory = Mimic.GetCachedHistory(cacher);

            var           replayer = Mimic.Stub <IComplexRepository>(cachedHistory);
            DataStructure result   = replayer.GetRelated(null);

            Assert.AreEqual(firstResult.Name, result.Name, "otherwise this is because it was not cached");
            Assert.AreEqual(firstResult.Age, result.Age, "otherwise this is because it was not cached");
        }
Exemple #8
0
        public void CacheProxyReplaysCachedCalls_WhenParameterIsNULL()
        {
            var response = new DataStructure {
                Age = 21, Name = "Jimmy"
            };
            var           repo        = new ComplexRepositoryReturnsWhateverItWasSetupWith(response);
            var           recorder    = Mimic.Record <IComplexRepository>(repo);
            DataStructure firstResult = recorder.GetRelated(null);

            string serialisedHistory = Mimic.SerialiseHistory(recorder);
            var    history           = Mimic.DeserialiseHistory(serialisedHistory);


            var replayer = Mimic.Cache <IComplexRepository>(
                new ComplexRepository2(), history);
            DataStructure result = replayer.GetRelated(null);

            Assert.AreEqual(firstResult.Name, result.Name, "otherwise this is because it was not cached");
            Assert.AreEqual(firstResult.Age, result.Age, "otherwise this is because it was not cached");
        }
Exemple #9
0
        public void WhenIModifyAParameterAfterLoggingIt_TheOriginalVerionShouldBeLogged()
        {
            var data = new DataStructure {
                Age = 21, Name = "Jimmy"
            };
            var           repo        = new ComplexRepositoryReturnsWhateverItWasSetupWith(new DataStructure());
            var           recorder    = Mimic.Record <IComplexRepository>(repo);
            DataStructure firstResult = recorder.GetRelated(data);

            data.Age++;

            string serialisedHistory = Mimic.SerialiseHistory(recorder);
            var    history           = Mimic.DeserialiseHistory(serialisedHistory);

            var           replayer = Mimic.Stub <IComplexRepository>(history);
            DataStructure result   = replayer.GetRelated(new DataStructure {
                Age = 21, Name = "Jimmy"
            });

            Assert.Pass("no exceptions (there will be an exception if the logged call does not have age 21");
        }