public void CreateReturnsInstanceCreatedWithMatchingParameterConstructorTest() { var args = new object[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, true, Guid.NewGuid(), Environment.TickCount }; var target = new DefaultTypeCreator(); var actual = target.Create(typeof(Person), null, null, args); actual.Should().BeOfType<Person>(); var person = (Person) actual; person.FirstName.Should().Be((string) args[0]); person.LastName.Should().Be((string) args[1]); person.DOB.Should().Be((DateTime) args[2]); person.IsActive.Should().Be((bool) args[3]); person.Id.Should().Be((Guid) args[4]); person.Priority.Should().Be((int) args[5]); }
public void CreateReturnsInstanceCreatedWithCreatedParameters() { var constructorResolver = new DefaultConstructorResolver(CacheLevel.PerInstance); var constructorInfo = constructorResolver.Resolve(typeof(SimpleConstructor), null) !; var args = new object[] { new SlimModel() }; var executeStrategy = Substitute.For <IExecuteStrategy>(); var typeResolver = Substitute.For <ITypeResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); executeStrategy.CreateParameters(constructorInfo).Returns(args); configuration.ConstructorResolver.Returns(constructorResolver); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, Arg.Any <Type>()).Returns(x => x.Arg <Type>()); executeStrategy.Configuration.Returns(configuration); var sut = new DefaultTypeCreator(); var actual = sut.Create(executeStrategy, typeof(SimpleConstructor), null); actual.Should().NotBeNull(); }
public void CreateThrowsExceptionWithNullTypeTest() { var target = new DefaultTypeCreator(); Action action = () => target.Create(null, null, null); action.ShouldThrow<ArgumentNullException>(); }
public void CreateThrowsExceptionWhenNoTypeNotSupportedTest() { var target = new DefaultTypeCreator(); Action action = () => target.Create(typeof(Stream), null, null); action.ShouldThrow<NotSupportedException>(); }
public void CreateReturnsInstanceCreatedWithDefaultConstructorTest() { var target = new DefaultTypeCreator(); var actual = target.Create(typeof(Person), null, null); actual.Should().NotBeNull(); }
public void CreateThrowsExceptionWhenNoAppropriateConstructorFoundTest() { var args = new object[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid(), Environment.TickCount }; var target = new DefaultTypeCreator(); Action action = () => target.Create(typeof(Person), null, null, args); action.ShouldThrow<MissingMemberException>(); }
public void CreateThrowsExceptionWhenTypeNotSupported() { var targetType = typeof(Environment); var typeResolver = Substitute.For <ITypeResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); var executeStrategy = Substitute.For <IExecuteStrategy>(); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, targetType).Returns(targetType); executeStrategy.Configuration.Returns(configuration); var sut = new DefaultTypeCreator(); Action action = () => sut.Create(executeStrategy, targetType); action.Should().Throw <NotSupportedException>(); }
public void CreateThrowsExceptionWhenNoTypeNotSupported() { var buildChain = new BuildHistory(); var executeStrategy = Substitute.For <IExecuteStrategy>(); var typeResolver = Substitute.For <ITypeResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, Arg.Any <Type>()).Returns(x => x.Arg <Type>()); executeStrategy.BuildChain.Returns(buildChain); executeStrategy.Configuration.Returns(configuration); var sut = new DefaultTypeCreator(); Action action = () => sut.Create(executeStrategy, typeof(Stream)); action.Should().Throw <NotSupportedException>(); }
public void CreateThrowsExceptionWhenConstructorNotFound() { var constructorResolver = Substitute.For <IConstructorResolver>(); var executeStrategy = Substitute.For <IExecuteStrategy>(); var typeResolver = Substitute.For <ITypeResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); constructorResolver.Resolve(Arg.Any <Type>()).Returns((ConstructorInfo?)null); configuration.ConstructorResolver.Returns(constructorResolver); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, Arg.Any <Type>()).Returns(x => x.Arg <Type>()); executeStrategy.Configuration.Returns(configuration); var sut = new DefaultTypeCreator(); Action action = () => sut.Create(executeStrategy, typeof(Person), null); action.Should().Throw <NotSupportedException>(); }
public void CreateReturnsInstanceCreatedWithResolvedDefaultConstructorWhenArgumentsIsNull() { var constructorResolver = new DefaultConstructorResolver(CacheLevel.PerInstance); var executeStrategy = Substitute.For <IExecuteStrategy>(); var typeResolver = Substitute.For <ITypeResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); configuration.ConstructorResolver.Returns(constructorResolver); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, Arg.Any <Type>()).Returns(x => x.Arg <Type>()); executeStrategy.Configuration.Returns(configuration); var sut = new DefaultTypeCreator(); var actual = sut.Create(executeStrategy, typeof(Person), null); actual.Should().NotBeNull(); }
public void CreateThrowsExceptionWhenTypeConstructorsDoNotSupportProvidedArguments() { var executeStrategy = Substitute.For <IExecuteStrategy>(); var typeResolver = Substitute.For <ITypeResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, Arg.Any <Type>()).Returns(x => x.Arg <Type>()); executeStrategy.Configuration.Returns(configuration); var args = new object[] { Guid.NewGuid() }; var sut = new DefaultTypeCreator(); Action action = () => sut.Create(executeStrategy, typeof(Person), args); action.Should().Throw <NotSupportedException>(); }
public void CreateReturnsInstanceCreatedWithProvidedArguments() { var constructorInfo = typeof(Person).GetConstructors().First(); var executeStrategy = Substitute.For <IExecuteStrategy>(); var typeResolver = Substitute.For <ITypeResolver>(); var constructorResolver = Substitute.For <IConstructorResolver>(); var configuration = Substitute.For <IBuildConfiguration>(); configuration.TypeResolver.Returns(typeResolver); configuration.ConstructorResolver.Returns(constructorResolver); typeResolver.GetBuildType(configuration, Arg.Any <Type>()).Returns(x => x.Arg <Type>()); executeStrategy.Configuration.Returns(configuration); constructorResolver.Resolve(typeof(Person), Arg.Any <object?[]?>()).Returns(constructorInfo); var args = new object[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, true, Guid.NewGuid(), Environment.TickCount }; var sut = new DefaultTypeCreator(); var actual = sut.Create(executeStrategy, typeof(Person), args); actual.Should().BeOfType <Person>(); var person = (Person)actual !; person.FirstName.Should().Be((string)args[0]); person.LastName.Should().Be((string)args[1]); person.DOB.Should().Be((DateTime)args[2]); person.IsActive.Should().Be((bool)args[3]); person.Id.Should().Be((Guid)args[4]); person.Priority.Should().Be((int)args[5]); }
public void CreateThrowsExceptionWithNullTypeTest() { var buildChain = new LinkedList<object>(); var target = new DefaultTypeCreator(); Action action = () => target.Create(null, "Name", buildChain); action.ShouldThrow<ArgumentNullException>(); }