public void LazyPropertyIsInitializedOnlyOnce()
        {
            var service = new SampleService();

            service.DoWork(1);
            service.DoWork(1);
            service.DoWork(1);

            ServiceInstancesCreated.Should().Be(1);
            ExpensiveInstancesCreated.Should().Be(1);
        }
示例#2
0
        public void LazyPropertyIsDestroyedOnlyOnce()
        {
            TestBody(() =>
            {
                var service = new SampleService();

                service.DoWork(1);
                service.DoWork(1);
                service.DoWork(1);
            });

            ServiceInstancesDestroyed.Should().Be(1);
            ExpensiveInstancesDestroyed.Should().Be(1);
        }
        public void LazyPropertyIsInitializedOncePerInstance()
        {
            var service1 = new SampleService();
            var service2 = new SampleService();

            service1.DoWork(1);
            service1.DoWork(1);
            service1.DoWork(1);

            service2.DoWork(1);
            service2.DoWork(1);
            service2.DoWork(1);

            ServiceInstancesCreated.Should().Be(2);
            ExpensiveInstancesCreated.Should().Be(2);
        }