Ejemplo n.º 1
0
        public void WritingLogEntryIndentsAllLinesOfMessage()
        {
            var creatorType = typeof(DefaultTypeCreator);

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Exception exception;

            try
            {
                throw new TimeoutException();
            }
            catch (TimeoutException ex)
            {
                // Get the exception with a valid stack trace
                exception = ex;
            }

            sut.CreatingType(typeof(Person), creatorType, null !);
            sut.BuildFailure(exception);
            sut.CreatedType(typeof(Person), null !);

            var lines = sut.Output.Split(
                new[]
            {
                Environment.NewLine
            },
                StringSplitOptions.RemoveEmptyEntries);
            var indentedLines = lines.Skip(1).Take(lines.Length - 2);

            indentedLines.All(x => x.StartsWith("    ", StringComparison.OrdinalIgnoreCase)).Should().BeTrue();
        }
        public void CircularReferenceDetectedThrowsExceptionWithNullTypeTest()
        {
            var target = new DefaultBuildLog();

            Action action = () => target.CircularReferenceDetected(null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void CreatedTypeAppendsLogEntryTest()
        {
            var target = new DefaultBuildLog();

            target.CreatedType(typeof(string), null);

            target.Output.Should().NotBeNullOrWhiteSpace();
        }
        public void CreatedTypeThrowsExceptionWithNullTypeTest()
        {
            var target = new DefaultBuildLog();

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

            action.ShouldThrow<ArgumentNullException>();
        }
Ejemplo n.º 5
0
        public void CreatedTypeDoesNotWriteLogWhenDisabled()
        {
            var sut = new DefaultBuildLog();

            sut.CreatedType(typeof(string), null !);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 6
0
        public void MappedTypeDoesNotWriteLogWhenDisabled()
        {
            var sut = new DefaultBuildLog();

            sut.MappedType(typeof(Stream), typeof(MemoryStream));

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 7
0
        public void CircularReferenceDetectedDoesNotWriteLogWhenDisabled()
        {
            var sut = new DefaultBuildLog();

            sut.CircularReferenceDetected(typeof(string));

            sut.Output.Should().BeEmpty();
        }
        public void CircularReferenceDetectedAppendsLogEntryTest()
        {
            var target = new DefaultBuildLog();

            target.CircularReferenceDetected(typeof(string));

            target.Output.Should().NotBeNullOrWhiteSpace();
        }
        public void BuildFailureAppendsLogEntryTest()
        {
            var ex = new BuildException(Guid.NewGuid().ToString());

            var target = new DefaultBuildLog();

            target.BuildFailure(ex);

            target.Output.Should().Contain(ex.ToString());
        }
Ejemplo n.º 10
0
        public void CreatingTypeDoesNotWriteLogWhenDisabled()
        {
            var creatorType = typeof(DefaultTypeCreator);

            var sut = new DefaultBuildLog();

            sut.CreatingType(typeof(string), creatorType, null !);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 11
0
        public void CircularReferenceDetectedThrowsExceptionWithNullType()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.CircularReferenceDetected(null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 12
0
        public void BuildFailureThrowsExceptionWithNullType()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.BuildFailure(null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 13
0
        public void CircularReferenceDetectedAppendsLogEntry()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.CircularReferenceDetected(typeof(string));

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 14
0
        public void CreatedTypeAppendsLogEntry()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.CreatedType(typeof(string), null !);

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 15
0
        public void MappedTypeAppendsLogEntry()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.MappedType(typeof(Stream), typeof(MemoryStream));

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 16
0
        public void BuildFailureDoesNotWriteLogWhenDisabled()
        {
            var ex = new BuildException(Guid.NewGuid().ToString());

            var sut = new DefaultBuildLog();

            sut.BuildFailure(ex);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 17
0
        public void MappedTypeThrowsExceptionWithNullSourceType()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.MappedType(null !, typeof(MemoryStream));

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 18
0
        public void MappedTypeThrowsExceptionWithNullTargetType()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.MappedType(typeof(Stream), null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 19
0
        public void PopulatingInstanceDoesNotWriteLogWhenDisabled()
        {
            var instance = new Person();

            var sut = new DefaultBuildLog();

            sut.PopulatingInstance(instance);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 20
0
        public void PopulatingInstanceThrowsExceptionWithNullInstance()
        {
            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.PopulatingInstance(null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 21
0
        public void PostBuildActionDoesNotWriteLogWhenDisabled()
        {
            var postBuildType = typeof(DummyPostBuildAction);

            var sut = new DefaultBuildLog();

            sut.PostBuildAction(typeof(string), postBuildType, null !);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 22
0
        public void CreatingValueDoesNotWriteLogWhenDisabled()
        {
            var generatorType = typeof(StateValueGenerator);
            var type          = typeof(string);

            var sut = new DefaultBuildLog();

            sut.CreatingValue(type, generatorType, null !);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 23
0
        public void CreatingParameterDoesNotWriteLogWhenDisabled()
        {
            var parameterInfo = typeof(Person).GetConstructors()
                                .First(x => x.GetParameters().FirstOrDefault()?.Name == "firstName").GetParameters().First();

            var sut = new DefaultBuildLog();

            sut.CreatingParameter(parameterInfo, null !);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 24
0
        public void IgnoringPropertyDoesNotWriteLogWhenDisabled()
        {
            var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !;
            var context      = new Person();

            var sut = new DefaultBuildLog();

            sut.IgnoringProperty(propertyInfo, context);

            sut.Output.Should().BeEmpty();
        }
Ejemplo n.º 25
0
        public void CreatingParameterThrowsExceptionWithNullParameter()
        {
            var context = Guid.NewGuid().ToString();

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.CreatingParameter(null !, context);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 26
0
        public void BuildFailureAppendsLogEntry()
        {
            var ex = new BuildException(Guid.NewGuid().ToString());

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.BuildFailure(ex);

            sut.Output.Should().Contain(ex.ToString());
        }
Ejemplo n.º 27
0
        public void CreatingValueThrowsExceptionWithNullType()
        {
            var generatorType = typeof(StateValueGenerator);

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.CreatingValue(null !, generatorType, null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 28
0
        public void PostBuildActionThrowsExceptionWithNullType()
        {
            var creatorType = typeof(DefaultTypeCreator);

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.PostBuildAction(null !, creatorType, null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 29
0
        public void PostBuildActionAppendsLogEntry()
        {
            var postBuildType = typeof(DummyPostBuildAction);

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.PostBuildAction(typeof(string), postBuildType, null !);

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 30
0
        public void PopulatingInstanceAppendsLogEntry()
        {
            var instance = new Person();

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.PopulatingInstance(instance);

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 31
0
        public void IgnoringPropertyThrowsExceptionWithNullProperty()
        {
            var context = new Person();

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.IgnoringProperty(null !, context);

            action.Should().Throw <ArgumentNullException>();
        }
        public void ClearRemovesExistingBuildLogDataTest()
        {
            var target = new DefaultBuildLog();

            target.CreatingValue(typeof(string), null);

            target.Output.Should().NotBeNullOrWhiteSpace();

            target.Clear();

            target.Output.Should().BeNullOrWhiteSpace();
        }
Ejemplo n.º 33
0
        public void IgnoringPropertyThrowsExceptionWithNullContext()
        {
            var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !;

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.IgnoringProperty(propertyInfo, null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 34
0
        public void PostBuildActionThrowsExceptionWithNullPostBuildType()
        {
            var type = typeof(string);

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            Action action = () => sut.PostBuildAction(type, null !, null !);

            action.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 35
0
        public void CreatingValueAppendsLogEntry()
        {
            var generatorType = typeof(StateValueGenerator);
            var type          = typeof(string);

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.CreatingValue(type, generatorType, null !);

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
Ejemplo n.º 36
0
        public void IgnoringPropertyAppendsLogEntry()
        {
            var propertyInfo = typeof(Person).GetProperty(nameof(Person.FirstName)) !;
            var context      = new Person();

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.IgnoringProperty(propertyInfo, context);

            sut.Output.Should().NotBeNullOrWhiteSpace();
        }
        public void PopulatingInstanceThrowsExceptionWithNullInstanceTest()
        {
            var target = new DefaultBuildLog();

            Action action = () => target.PopulatingInstance(null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void PopulatingInstanceAppendsLogEntryTest()
        {
            var instance = new Person();

            var target = new DefaultBuildLog();

            target.PopulatingInstance(instance);

            target.Output.Should().NotBeNullOrWhiteSpace();
        }
        public void CreateParameterAppendsLogEntryTest()
        {
            var target = new DefaultBuildLog();

            target.CreateParameter(typeof(Person), typeof(string), "FirstName", null);

            target.Output.Should().NotBeNullOrWhiteSpace();
        }
        public void CreatePropertyValidatesPropertysTest(Type propertyType, string propertyName, bool includeContext)
        {
            Person context = null;

            if (includeContext)
            {
                context = new Person();
            }

            var target = new DefaultBuildLog();

            Action action = () => target.CreateProperty(propertyType, propertyName, context);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void PopulateInstanceIndentsChildMessagesTest()
        {
            var instance = new Person();

            var target = new DefaultBuildLog();

            target.PopulatingInstance(instance);
            target.CreatingValue(typeof(string), null);
            target.PopulatedInstance(instance);

            var actual = target.Output;

            actual.Should().Contain("    ");
        }
        public void CreateTypeIndentsChildMessagesTest()
        {
            var target = new DefaultBuildLog();

            target.CreatingType(typeof(Person), null);
            target.CreatingValue(typeof(string), null);
            target.CreatedType(typeof(Person), null);

            var actual = target.Output;

            actual.Should().Contain("    ");
        }
        public void CreateWithThrowsExceptionWhenDerivedImplementationSuppliesNullTypeTest()
        {
            var buildLog = new DefaultBuildLog();

            var buildStrategy = Substitute.For<IBuildStrategy>();

            buildStrategy.GetBuildLog().Returns(buildLog);

            var target = new NullTypeBuildExecuteStrategy();

            target.Initialize(buildStrategy, buildStrategy.GetBuildLog());

            Action action = () => target.CreateWith(typeof(int));

            action.ShouldThrow<ArgumentNullException>();
        }
        public void CreateParameterValidatesParametersTest(Type instanceType, Type parameterType, string parameterName)
        {
            var target = new DefaultBuildLog();

            Action action = () => target.CreateParameter(instanceType, parameterType, parameterName, null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void CreatePropertyAppendsLogEntryTest()
        {
            var context = new Person();

            var target = new DefaultBuildLog();

            target.CreateProperty(typeof(string), "FirstName", context);

            target.Output.Should().NotBeNullOrWhiteSpace();
        }
        public void CreateWithDoesNotBuildPropertiesWhenTypeCreatorDisablesAutoPopulateTest()
        {
            var model = new SlimModel();
            var typeCreators = new List<ITypeCreator>();
            var buildLog = new DefaultBuildLog();

            var typeCreator = Substitute.For<ITypeCreator>();
            var buildStrategy = Substitute.For<IBuildStrategy>();

            typeCreators.Add(typeCreator);

            buildStrategy.GetBuildLog().Returns(buildLog);
            buildStrategy.TypeCreators.Returns(typeCreators.AsReadOnly());

            var target = new DefaultExecuteStrategy();

            target.Initialize(buildStrategy, buildStrategy.GetBuildLog());

            typeCreator.CanCreate(typeof(SlimModel), null, Arg.Any<LinkedList<object>>()).Returns(true);
            typeCreator.Create(typeof(SlimModel), null, Arg.Any<LinkedList<object>>()).Returns(model);
            typeCreator.Priority.Returns(1);
            typeCreator.AutoPopulate.Returns(false);
            typeCreator.Populate(model, target).Returns(model);

            var actual = (SlimModel)target.CreateWith(typeof(SlimModel));

            actual.Should().BeSameAs(model);
            actual.Value.Should().BeEmpty();
        }
        public void WritingLogEntryIndentsAllLinesOfMessageTest()
        {
            var target = new DefaultBuildLog();

            Exception exception;

            try
            {
                throw new TimeoutException();
            }
            catch (Exception ex)
            {
                // Get the exception with a valid stack trace
                exception = ex;
            }

            target.CreatingType(typeof(Person), null);
            target.BuildFailure(exception);
            target.CreatedType(typeof(Person), null);

            var lines = target.Output.Split(
                new[]
                {
                    Environment.NewLine
                },
                StringSplitOptions.RemoveEmptyEntries);
            var indentedLines = lines.Skip(1).Take(lines.Length - 2);

            indentedLines.All(x => x.StartsWith("    ")).Should().BeTrue();
        }