コード例 #1
0
        public void CreateThrowExceptionWhenTypeNotEnumerable()
        {
            var executeStrategy = Substitute.For <IExecuteStrategy>();
            var configuration   = Substitute.For <IBuildConfiguration>();

            executeStrategy.Configuration.Returns(configuration);

            var sut = new EnumerableTypeCreator();

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

            action.Should().Throw <BuildException>();
        }
コード例 #2
0
        public void PopulateAddsItemsToInstancesTest(Type type)
        {
            var configuration = Model.UsingDefaultConfiguration();

            var sut = new EnumerableTypeCreator();

            var executeStrategy = new DefaultExecuteStrategy();

            executeStrategy.Initialize(configuration);

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

            sut.Populate(executeStrategy, actual);

            var converted = (IEnumerable)actual;

            converted.Should().NotBeEmpty();
        }
コード例 #3
0
        public void CreateReturnsInstanceOfMostAppropriateTypeTest(Type requestedType, Type expectedType)
        {
            var buildChain = new BuildHistory();

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

            executeStrategy.BuildChain.Returns(buildChain);
            executeStrategy.Configuration.Returns(configuration);

            var sut = new EnumerableTypeCreator();

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

            actual.Should().NotBeNull();
            actual.Should().BeOfType(expectedType);
            actual.Should().BeAssignableTo(requestedType);
            actual.As <IEnumerable>().Should().BeEmpty();
        }
コード例 #4
0
        public void PopulateAddsItemsToInstancesTest(Type type)
        {
            var configuration = Model.BuildStrategy;
            var buildLog = configuration.GetBuildLog();

            var target = new EnumerableTypeCreator();
            var executeStrategy = new DefaultExecuteStrategy();

            executeStrategy.Initialize(configuration, buildLog);

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

            target.Populate(actual, executeStrategy);

            var converted = (IEnumerable) actual;

            converted.Should().NotBeEmpty();
        }
コード例 #5
0
        public void CreateValidatesWhetherTypeIsSupportedTest(Type type, bool supported)
        {
            var target = new EnumerableTypeCreator();

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

            if (supported)
            {
                action.ShouldNotThrow();
            }
            else
            {
                action.ShouldThrow<NotSupportedException>();
            }
        }
コード例 #6
0
        public void CreateThrowsExceptionWithNullTypeTest()
        {
            var target = new EnumerableTypeCreator();

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

            action.ShouldThrow<ArgumentNullException>();
        }
コード例 #7
0
        public void CreateReturnsNewListOfSpecfiedTypeTest(Type targetType)
        {
            var target = new EnumerableTypeCreator();

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

            actual.Should().BeOfType<List<int>>();
            actual.As<List<int>>().Should().BeEmpty();
        }
コード例 #8
0
        public void CreateReturnsInstanceTest(Type type)
        {
            var target = new EnumerableTypeCreator();

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

            actual.Should().NotBeNull();
        }