public void Should_be_able_to_resolve_same_type_twice_when_successful()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes("dummy value"),
                this.fakeObjectCreator);

            resolver.TryResolveDummyValue(typeof(string), new LoopDetectingResolutionContext());

            // Act
            var result = resolver.TryResolveDummyValue(typeof(string), new LoopDetectingResolutionContext());

            // Assert
            result.WasSuccessful.Should().BeTrue();
            result.Result.Should().Be("dummy value");
        }
Пример #2
0
        public void Should_be_able_to_resolve_same_type_twice_when_successful()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes("dummy value"),
                this.fakeObjectCreator);

            object dummy;

            resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(string), out dummy);

            // Act
            var result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(string), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().Be("dummy value");
        }
Пример #3
0
        public void Should_not_be_able_to_create_class_with_circular_dependencies()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(TypeWithCircularDependency));

            // Assert
            result.WasSuccessful.Should().BeFalse();
        }
Пример #4
0
        public void Should_return_failed_creation_result_when_type_cannot_be_created()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(TypeThatCanNotBeInstantiated));

            // Assert
            result.WasSuccessful.Should().BeFalse();
        }
        public void Should_return_failed_result_for_restricted_types(Type restrictedType)
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(restrictedType, new LoopDetectingResolutionContext());

            // Assert
            result.WasSuccessful.Should().BeFalse();
        }
Пример #6
0
        public void Should_return_failed_result_when_default_constructor_throws()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(TypeWithDefaultConstructorThatThrows));

            // Assert
            result.WasSuccessful.Should().BeFalse();
        }
Пример #7
0
        public void Should_be_able_to_create_class_with_default_constructor()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(ClassWithDefaultConstructor));

            // Assert
            result.WasSuccessful.Should().BeTrue();
            result.Result.Should().BeOfType <ClassWithDefaultConstructor>();
        }
Пример #8
0
        public void Should_favor_the_widest_constructor_when_activating()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes("dummy value"),
                this.fakeObjectCreator);

            // Act
            var result     = resolver.TryResolveDummyValue(typeof(TypeWithMultipleConstructorsOfDifferentWidth));
            var typedDummy = (TypeWithMultipleConstructorsOfDifferentWidth)result.Result;

            // Assert
            typedDummy.WidestConstructorWasCalled.Should().BeTrue();
        }
Пример #9
0
        public void Should_return_false_for_restricted_types(Type restrictedType)
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), restrictedType, out dummy);

            // Assert
            result.Should().BeFalse();
        }
Пример #10
0
        public void Should_return_false_when_default_constructor_throws()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(TypeWithDefaultConstructorThatThrows), out dummy);

            // Assert
            result.Should().BeFalse();
        }
        public void Should_return_default_value_when_type_is_value_type()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(int), new LoopDetectingResolutionContext());

            // Assert
            result.WasSuccessful.Should().BeTrue();
            result.Result.Should().Be(0);
        }
Пример #12
0
        public void Should_return_default_value_when_type_is_value_type()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(int), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().Be(0);
        }
Пример #13
0
        public void Should_return_false_when_type_cannot_be_created()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(TypeThatCanNotBeInstantiated), out dummy);

            // Assert
            result.Should().BeFalse();
            dummy.Should().BeNull();
        }
Пример #14
0
        public void Should_be_able_to_create_class_with_resolvable_constructor_arguments()
        {
            // Arrange
            this.StubFakeObjectCreatorWithValue(A.Fake <IFoo>());
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes("dummy string"),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(TypeWithResolvableConstructorArguments <string, IFoo>));

            // Assert
            result.WasSuccessful.Should().BeTrue();
            result.Result.Should().BeOfType <TypeWithResolvableConstructorArguments <string, IFoo> >();
        }
Пример #15
0
        public void Should_be_able_to_create_class_with_default_constructor()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(ClassWithDefaultConstructor), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeOfType <ClassWithDefaultConstructor>();
        }
        public void Should_return_dummy_from_container_when_available(object dummyForContainer)
        {
            Guard.AgainstNull(dummyForContainer, nameof(dummyForContainer));

            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes(dummyForContainer),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(dummyForContainer.GetType(), new LoopDetectingResolutionContext());

            // Assert
            result.WasSuccessful.Should().BeTrue();
            result.Result.Should().BeSameAs(dummyForContainer);
        }
        public void Should_return_fake_when_it_can_be_created()
        {
            // Arrange
            var fake = A.Fake <IFoo>();

            this.StubFakeObjectCreatorWithValue(fake);
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(IFoo), new LoopDetectingResolutionContext());

            // Assert
            result.WasSuccessful.Should().BeTrue();
            result.Result.Should().BeSameAs(fake);
        }
Пример #18
0
        public void Should_return_dummy_from_container_when_available(object dummyForContainer)
        {
            Guard.AgainstNull(dummyForContainer, nameof(dummyForContainer));

            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes(dummyForContainer),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), dummyForContainer.GetType(), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeSameAs(dummyForContainer);
        }
Пример #19
0
        public void Should_return_fake_when_it_can_be_created()
        {
            // Arrange
            var fake = A.Fake <IFoo>();

            this.StubFakeObjectCreatorWithValue(fake);
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(IFoo), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeSameAs(fake);
        }
Пример #20
0
        public void Should_favor_the_widest_constructor_when_activating()
        {
            // Arrange
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakes("dummy value"),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(
                typeof(TypeWithMultipleConstructorsOfDifferentWidth),
                new LoopDetectingResolutionContext());

            // Assert
            var dummy = result.Result;

            dummy.Should().BeOfType <TypeWithMultipleConstructorsOfDifferentWidth>();
            ((TypeWithMultipleConstructorsOfDifferentWidth)dummy !).WidestConstructorWasCalled.Should().BeTrue();
        }
Пример #21
0
        public void Should_be_able_to_create_lazy_wrapper()
        {
            // Arrange
            var fake = A.Fake <IFoo>();

            this.StubFakeObjectCreatorWithValue(fake);
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = resolver.TryResolveDummyValue(new DummyCreationSession(), typeof(Lazy <IFoo>), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeOfType <Lazy <IFoo> >();
            ((Lazy <IFoo>)dummy).Value.Should().BeSameAs(fake);
        }
        public void Should_be_able_to_create_lazy_wrapper()
        {
            // Arrange
            var fake = A.Fake <IFoo>();

            this.StubFakeObjectCreatorWithValue(fake);
            var resolver = new DummyValueResolver(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            var result = resolver.TryResolveDummyValue(typeof(Lazy <IFoo>), new LoopDetectingResolutionContext());

            // Assert
            result.WasSuccessful.Should().BeTrue();
            var dummy = result.Result;

            dummy.Should().BeOfType <Lazy <IFoo> >();
            ((Lazy <IFoo>)dummy).Value.Should().BeSameAs(fake);
        }