Exemple #1
0
        public void ResultOfMethodCallWithSameComplexTypeIsCached()
        {
            var testModule = new InlineModule(m => m.Bind <CacheMock>().ToSelf());

            using (var kernel = new StandardKernel(new LinFuModule(), new CacheModule(), testModule))
            {
                var obj = kernel.Get <CacheMock>();

                CacheMock.ResetCounts();

                string result;

                var simple1 = new SimpleObject();
                var simple2 = new SimpleObject();

                result = obj.Convert(simple1);
                Assert.That(result, Is.EqualTo(simple1.ToString()));
                Assert.That(CacheMock.ConvertCount, Is.EqualTo(1));

                result = obj.Convert(simple1);
                Assert.That(result, Is.EqualTo(simple1.ToString()));
                Assert.That(CacheMock.ConvertCount, Is.EqualTo(1));

                result = obj.Convert(simple2);
                Assert.That(result, Is.EqualTo(simple2.ToString()));
                Assert.That(CacheMock.ConvertCount, Is.EqualTo(2));
            }
        }
		public void ResultOfMethodCallWithSameComplexTypeIsCached()
		{
			var testModule = new InlineModule(m => m.Bind<CacheMock>().ToSelf());

			using (var kernel = new StandardKernel(new LinFuModule(), new CacheModule(), testModule))
			{
				var obj = kernel.Get<CacheMock>();

				CacheMock.ResetCounts();

				string result;

				var simple1 = new SimpleObject();
				var simple2 = new SimpleObject();

				result = obj.Convert(simple1);
				Assert.That(result, Is.EqualTo(simple1.ToString()));
				Assert.That(CacheMock.ConvertCount, Is.EqualTo(1));

				result = obj.Convert(simple1);
				Assert.That(result, Is.EqualTo(simple1.ToString()));
				Assert.That(CacheMock.ConvertCount, Is.EqualTo(1));

				result = obj.Convert(simple2);
				Assert.That(result, Is.EqualTo(simple2.ToString()));
				Assert.That(CacheMock.ConvertCount, Is.EqualTo(2));
			}
		}