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"); }
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(); }
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(); }
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(); }
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); }
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(); }
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>(); }
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(); }
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> >(); }
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); }
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); }
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); }