Example #1
0
        public void factory_based_on_func_is_invoked_each_time()
        {
            var count = 0;
            Func <HeavyClass> heavyClassFactory = () =>
            {
                count++;
                return(new HeavyClass());
            };
            var sut = new LightClassWithFunc(heavyClassFactory);

            sut.SomeMethod();
            sut.SomeMethod();
            sut.SomeMethod();

            count.Should().Be(3);
        }
Example #2
0
        public void should_defer_the_creation_using_a_func()
        {
            var created = false;
            Func <HeavyClass> heavyClassFactory = () =>
            {
                created = true;
                return(new HeavyClass());
            };

            var sut = new LightClassWithFunc(heavyClassFactory);

            created.Should().Be(false);

            sut.SomeMethod();

            created.Should().Be(true);
        }