public ApplicationInstance GetCurrent()
        {
            ApplicationInstance instance = _cache.GetCurrent();

            if (instance == null)
            {
                instance = _retriever.GetApplicationInstance();
                _cache.Set(ApplicationInstance.CacheKey, instance);
            }

            return(instance);
        }
Пример #2
0
        public void Retrieves_application_instance_when_not_found_in_cache()
        {
            ApplicationInstance instance = new ApplicationInstance();

            MockRepository                       mocks     = new MockRepository();
            IApplicationInstanceCache            cache     = mocks.CreateMock <IApplicationInstanceCache>();
            ICurrentApplicationInstanceRetriever retriever = mocks.CreateMock <ICurrentApplicationInstanceRetriever>();

            using (mocks.Record())
            {
                Expect.Call(cache.GetCurrent()).Return(null);
                Expect.Call(retriever.GetApplicationInstance()).Return(instance);
                cache.Set(ApplicationInstance.CacheKey, instance);
            }

            using (mocks.Playback())
            {
                IApplicationInstanceContext instanceContext = new ApplicationInstanceContext(cache, retriever);
                Assert.That(instanceContext.GetCurrent(), Is.SameAs(instance));
            }

            mocks.VerifyAll();
        }