public void CreateValidatesWhetherTypeIsSupportedTest(Type type, bool supported)
        {
            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 ArrayTypeCreator();

            Action action = () => sut.Create(executeStrategy, type);

            if (supported)
            {
                action.Should().NotThrow();
            }
            else
            {
                action.Should().Throw <NotSupportedException>();
            }
        }
        public void PopulateAddsItemsToCollectionFromExecuteStrategy()
        {
            var expected = new Guid[15];

            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);
            executeStrategy.Create(typeof(Guid)).Returns(Guid.NewGuid());

            var sut = new ArrayTypeCreator
            {
                MaxCount = 15
            };

            var actual = sut.Populate(executeStrategy, expected);

            actual.Should().BeSameAs(expected);

            var set = (Guid[])actual;

            set.Should().HaveCount(sut.MaxCount);
            set.All(x => x != Guid.Empty).Should().BeTrue();
        }
        public void PriorityReturnsHigherThanDefaultTypeCreator()
        {
            var sut   = new ArrayTypeCreator();
            var other = new DefaultTypeCreator();

            sut.Priority.Should().BeGreaterThan(other.Priority);
        }
        public void CanPopulateReturnsWhetherTypeIsSupportedTest(Type type, bool supported)
        {
            var target = new ArrayTypeCreator();

            var actual = target.CanPopulate(type, null, null);

            actual.Should().Be(supported);
        }
        public void CanCreateThrowsExceptionWithNullTypeTest()
        {
            var target = new ArrayTypeCreator();

            Action action = () => target.CanCreate(null, null, null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void CanCreateReturnsWhetherTypeIsSupportedTest(Type type, bool supported)
        {
            var configuration = Substitute.For <IBuildConfiguration>();

            var sut = new ArrayTypeCreator();

            var actual = sut.CanCreate(configuration, null !, type);

            actual.Should().Be(supported);
        }
        public void PopulateThrowsExceptionWithNullStrategy()
        {
            var instance = new List <string>();

            var sut = new ArrayTypeCreator();

            Action action = () => sut.Populate(null !, instance);

            action.Should().Throw <ArgumentNullException>();
        }
        public void PopulateThrowsExceptionWithNullInstance()
        {
            var strategy = Substitute.For <IExecuteStrategy>();

            var sut = new ArrayTypeCreator();

            Action action = () => sut.Populate(strategy, null !);

            action.Should().Throw <ArgumentNullException>();
        }
        public void CanCreateThrowsExceptionWithNullType()
        {
            var configuration = Substitute.For <IBuildConfiguration>();

            var sut = new ArrayTypeCreator();

            Action action = () => sut.CanCreate(configuration, null !, (Type)null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 10
0
        public void PopulateInfersItemTypeByArrayTypeWhenFirstItemIsNull()
        {
            var actual          = new Person[15];
            var executeStrategy = Model.UsingDefaultConfiguration()
                                  .UsingExecuteStrategy <DefaultExecuteStrategy <List <Company> > >();

            var sut = new ArrayTypeCreator();

            var result = (Person[])sut.Populate(executeStrategy, actual);

            result.All(x => x != null !).Should().BeTrue();
        }
Ejemplo n.º 11
0
        public void CanPopulateReturnsWhetherTypeIsSupportedTest(Type type, bool supported)
        {
            _output.WriteLine("Testing " + type.FullName);

            var configuration = Substitute.For <IBuildConfiguration>();

            var sut = new ArrayTypeCreator();

            var actual = sut.CanPopulate(configuration, null !, type);

            actual.Should().Be(supported);
        }
        public void UpdateTypeCreatorThrowsExceptionWhenOnlyDerivedClassFound()
        {
            var sut         = new BuildConfiguration();
            var typeCreator = new ArrayTypeCreator();

            sut.TypeCreators.Add(typeCreator);

            Action action = () => sut.UpdateTypeCreator <DefaultTypeCreator>(x =>
            {
                // Do nothing
            });

            action.Should().Throw <InvalidOperationException>();
        }
Ejemplo n.º 13
0
        public void PopulateThrowsExceptionWithUnsupportedType()
        {
            var instance = new Lazy <bool>(() => true);

            var buildChain      = new BuildHistory();
            var executeStrategy = Substitute.For <IExecuteStrategy>();

            executeStrategy.BuildChain.Returns(buildChain);

            var sut = new ArrayTypeCreator();

            Action action = () => sut.Populate(executeStrategy, instance);

            action.Should().Throw <NotSupportedException>();
        }
        public void UpdateTypeCreatorUpdateMatchingTypeCreatorMatchingExplicitType()
        {
            var maxCount = Environment.TickCount;
            var sut      = new BuildConfiguration();
            var first    = new DefaultTypeCreator();
            var second   = new ArrayTypeCreator();

            sut.TypeCreators.Add(first);
            sut.TypeCreators.Add(second);

            var config = sut.UpdateTypeCreator <ArrayTypeCreator>(x => { x.MaxCount = maxCount; });

            config.Should().Be(sut);

            second.MaxCount.Should().Be(maxCount);
        }
Ejemplo n.º 15
0
        public void CreateReturnsInstanceTest(Type type)
        {
            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 ArrayTypeCreator();

            var actual = sut.Create(executeStrategy, type);

            actual.Should().NotBeNull();
        }
Ejemplo n.º 16
0
        public void PopulateReturnsEmptyArrayWhenSourceHasZeroLength()
        {
            var expected = new Guid[0];

            var buildChain      = new BuildHistory();
            var executeStrategy = Substitute.For <IExecuteStrategy>();

            executeStrategy.BuildChain.Returns(buildChain);
            executeStrategy.Create(typeof(Guid)).Returns(Guid.NewGuid());

            var sut = new ArrayTypeCreator
            {
                MaxCount = 15
            };

            var actual = sut.Populate(executeStrategy, expected);

            actual.Should().BeSameAs(expected);

            var set = (Guid[])actual;

            set.Should().BeEmpty();
        }
Ejemplo n.º 17
0
        public void PopulateAddsItemsToListFromExecuteStrategy()
        {
            var expected = new Guid[15];

            var buildChain      = new BuildHistory();
            var executeStrategy = Substitute.For <IExecuteStrategy>();

            executeStrategy.BuildChain.Returns(buildChain);
            executeStrategy.Create(typeof(Guid)).Returns(Guid.NewGuid());

            var sut = new ArrayTypeCreator
            {
                MaxCount = 15
            };

            var actual = sut.Populate(executeStrategy, expected);

            actual.Should().BeSameAs(expected);

            var set = (Guid[])actual;

            set.Should().HaveCount(sut.MaxCount);
            set.All(x => x != Guid.Empty).Should().BeTrue();
        }
Ejemplo n.º 18
0
        public void CreateReturnsBetweenMinAndMaxCountItems()
        {
            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 ArrayTypeCreator
            {
                MinCount = 5,
                MaxCount = 15
            };

            var actual = (Person[])sut.Create(executeStrategy, typeof(Person[])) !;

            actual.Length.Should().BeGreaterOrEqualTo(sut.MinCount);
            actual.Length.Should().BeLessOrEqualTo(sut.MaxCount);
        }
        public void CreateReturnsInstanceTest(Type type)
        {
            var target = new ArrayTypeCreator();

            var actual = target.Create(type, null, null);

            actual.Should().NotBeNull();
        }
        public void SettingMaxCountShouldNotChangeDefaultMaxCountTest()
        {
            var target = new ArrayTypeCreator
            {
                MaxCount = Environment.TickCount
            };

            ArrayTypeCreator.DefaultMaxCount.Should().NotBe(target.MaxCount);
        }
        public void SettingDefaultMaxCountOnlyAffectsNewInstancesTest()
        {
            var expected = ArrayTypeCreator.DefaultMaxCount;

            try
            {
                var first = new ArrayTypeCreator();

                ArrayTypeCreator.DefaultMaxCount = 11;

                var second = new ArrayTypeCreator();

                first.MaxCount.Should().Be(expected);
                second.MaxCount.Should().Be(11);
            }
            finally
            {
                ArrayTypeCreator.DefaultMaxCount = expected;
            }
        }
        public void ProrityReturnsHigherThanDefaultTypeCreatorTest()
        {
            var target = new ArrayTypeCreator();
            var other = new DefaultTypeCreator();

            target.Priority.Should().BeGreaterThan(other.Priority);
        }
        public void PopulateThrowsExceptionWithUnsupportedTypeTest()
        {
            var instance = new Lazy<bool>(() => true);

            var strategy = Substitute.For<IExecuteStrategy>();

            var target = new ArrayTypeCreator();

            Action action = () => target.Populate(instance, strategy);

            action.ShouldThrow<NotSupportedException>();
        }
        public void PopulateThrowsExceptionWithNullStrategyTest()
        {
            var instance = new List<string>();

            var target = new ArrayTypeCreator();

            Action action = () => target.Populate(instance, null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void PopulateThrowsExceptionWithNullInstanceTest()
        {
            var strategy = Substitute.For<IExecuteStrategy>();

            var target = new ArrayTypeCreator();

            Action action = () => target.Populate(null, strategy);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void PopulateReturnsEmptyArrayWhenSourceHasZeroLengthTest()
        {
            var expected = new Guid[0];

            var strategy = Substitute.For<IExecuteStrategy>();

            strategy.CreateWith(typeof(Guid)).Returns(Guid.NewGuid());

            var target = new ArrayTypeCreator
            {
                MaxCount = 15
            };

            var actual = target.Populate(expected, strategy);

            actual.Should().BeSameAs(expected);

            var set = (Guid[]) actual;

            set.Should().BeEmpty();
        }
        public void PopulateInferesItemTypeByArrayTypeWhenFirstItemIsNullTest()
        {
            var actual = new Person[15];
            var executeStrategy = Model.BuildStrategy.GetExecuteStrategy<List<int>>();

            var target = new ArrayTypeCreator();

            var result = (Person[]) target.Populate(actual, executeStrategy);

            result.All(x => x != null).Should().BeTrue();
        }
        public void PopulateAddsItemsToListFromExecuteStrategyTest()
        {
            var expected = new Guid[15];

            var strategy = Substitute.For<IExecuteStrategy>();

            strategy.CreateWith(typeof(Guid)).Returns(Guid.NewGuid());

            var target = new ArrayTypeCreator
            {
                MaxCount = 15
            };

            var actual = target.Populate(expected, strategy);

            actual.Should().BeSameAs(expected);

            var set = (Guid[]) actual;

            set.Should().HaveCount(target.MaxCount);
            set.All(x => x != Guid.Empty).Should().BeTrue();
        }
        public void CreateValidatesWhetherTypeIsSupportedTest(Type type, bool supported)
        {
            var target = new ArrayTypeCreator();

            Action action = () => target.Create(type, null, null);

            if (supported)
            {
                action.ShouldNotThrow();
            }
            else
            {
                action.ShouldThrow<NotSupportedException>();
            }
        }