Exemplo n.º 1
0
        public void Should_be_able_to_resolve_same_type_twice_when_successful()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakes("dummy value"),
                this.fakeObjectCreator);

            object dummy;

            session.TryResolveDummyValue(typeof(string), out dummy);

            // Act
            var result = session.TryResolveDummyValue(typeof(string), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().Be("dummy value");
        }
Exemplo n.º 2
0
        public void Should_return_false_for_restricted_types(Type restrictedType)
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = session.TryResolveDummyValue(restrictedType, out dummy);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 3
0
        public void Should_return_false_when_default_constructor_throws()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

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

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 4
0
        public void Should_not_be_able_to_create_class_with_circular_dependencies()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = session.TryResolveDummyValue(typeof(TypeWithCircularDependency), out dummy);

            // Assert
            result.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void Should_return_default_value_when_type_is_value_type()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

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

            // Assert
            result.Should().BeTrue();
            dummy.Should().Be(0);
        }
Exemplo n.º 6
0
        public void Should_return_false_when_type_cannot_be_created()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

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

            // Assert
            result.Should().BeFalse();
            dummy.Should().BeNull();
        }
Exemplo n.º 7
0
        public void Should_be_able_to_create_class_with_default_constructor()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

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

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeOfType <ClassWithDefaultConstructor>();
        }
Exemplo n.º 8
0
        public void Should_favor_the_widest_constructor_when_activating()
        {
            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakes("dummy value"),
                this.fakeObjectCreator);

            // Act
            object dummy;

            session.TryResolveDummyValue(typeof(TypeWithMultipleConstructorsOfDifferentWidth), out dummy);
            var typedDummy = (TypeWithMultipleConstructorsOfDifferentWidth)dummy;

            // Assert
            typedDummy.WidestConstructorWasCalled.Should().BeTrue();
        }
Exemplo n.º 9
0
        public void Should_be_able_to_create_class_with_resolvable_constructor_arguments()
        {
            // Arrange
            this.StubFakeObjectCreatorWithValue(A.Fake <IFoo>());
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakes("dummy string"),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = session.TryResolveDummyValue(typeof(TypeWithResolvableConstructorArguments <string, IFoo>), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeOfType <TypeWithResolvableConstructorArguments <string, IFoo> >();
        }
Exemplo n.º 10
0
        public void Should_return_dummy_from_container_when_available(object dummyInContainer)
        {
            Guard.AgainstNull(dummyInContainer, "dummyInContainer");

            // Arrange
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakes(dummyInContainer),
                this.fakeObjectCreator);

            // Act
            object dummy;
            var    result = session.TryResolveDummyValue(dummyInContainer.GetType(), out dummy);

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeSameAs(dummyInContainer);
        }
Exemplo n.º 11
0
        public void Should_return_fake_when_it_can_be_created()
        {
            // Arrange
            var fake = A.Fake <IFoo>();

            this.StubFakeObjectCreatorWithValue(fake);
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

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

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeSameAs(fake);
        }
Exemplo n.º 12
0
        public void Should_be_able_to_create_lazy_wrapper()
        {
            // Arrange
            var fake = A.Fake <IFoo>();

            this.StubFakeObjectCreatorWithValue(fake);
            var session = new DummyValueCreationSession(
                this.CreateDummyFactoryThatMakesNoDummy(),
                this.fakeObjectCreator);

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

            // Assert
            result.Should().BeTrue();
            dummy.Should().BeOfType <Lazy <IFoo> >();
            ((Lazy <IFoo>)dummy).Value.Should().BeSameAs(fake);
        }