public void CanBeSerializedAndDeserializedTest()
        {
            var message = Guid.NewGuid().ToString();
            var targetType = typeof(Person);
            var referenceName = Guid.NewGuid().ToString();
            var context = new Company();
            var buildLog = Guid.NewGuid().ToString();
            var inner = new TimeoutException();
            var formatter = new BinaryFormatter();

            var target = new BuildException(message, targetType, referenceName, context, buildLog, inner);

            using (var ms = new MemoryStream())
            {
                formatter.Serialize(ms, target);
                ms.Seek(0, SeekOrigin.Begin);

                var outputException = formatter.Deserialize(ms) as BuildException;

                outputException.Message.Should().Be(message);
                outputException.TargetType.Should().Be(targetType);
                outputException.ReferenceName.Should().Be(referenceName);
                outputException.Context.Should().BeNull();
                outputException.BuildLog.Should().Be(buildLog);
                outputException.InnerException.Message.ShouldBeEquivalentTo(inner.Message);
            }
        }
Ejemplo n.º 2
0
 public ReadOnlyParent()
 {
     Company = new Company();
     RestrictedPeople = EmptySet();
     AssignablePeople = new List<Person>();
     People = new Collection<Person>();
 }
        public void CanCreateWithBuildInformationTest()
        {
            var message = Guid.NewGuid().ToString();
            var targetType = typeof(Person);
            var referenceName = Guid.NewGuid().ToString();
            var context = new Company();
            var buildLog = Guid.NewGuid().ToString();

            var target = new BuildException(message, targetType, referenceName, context, buildLog);

            target.Message.Should().Be(message);
            target.TargetType.Should().Be(targetType);
            target.ReferenceName.Should().Be(referenceName);
            target.Context.Should().Be(context);
            target.BuildLog.Should().Be(buildLog);
            target.InnerException.Should().BeNull();
        }
        public void PopulateAsObjectAssignsPropertyValuesToExistingInstanceTest()
        {
            var staff = new List<Person>();
            var name = Guid.NewGuid().ToString();
            var address = Guid.NewGuid().ToString();
            var expected = new Company();
            var valueGenerators = new List<IValueGenerator>();
            var typeCreators = new List<ITypeCreator>();

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

            typeCreators.Add(typeCreator);
            valueGenerators.Add(valueGenerator);

            buildStrategy.TypeCreators.Returns(typeCreators.AsReadOnly());
            buildStrategy.ValueGenerators.Returns(valueGenerators.AsReadOnly());

            var target = new DefaultExecuteStrategy();

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

            typeCreator.CanCreate(
                typeof(IEnumerable<Person>),
                "Staff",
                Arg.Is<LinkedList<object>>(x => x.Last.Value == expected)).Returns(true);
            typeCreator.Create(
                typeof(IEnumerable<Person>),
                "Staff",
                Arg.Is<LinkedList<object>>(x => x.Last.Value == expected)).Returns(staff);
            typeCreator.Populate(staff, target).Returns(staff);
            valueGenerator.IsSupported(
                typeof(string),
                "Name",
                Arg.Is<LinkedList<object>>(x => x.Last.Value == expected)).Returns(true);
            valueGenerator.Generate(typeof(string), "Name", Arg.Is<LinkedList<object>>(x => x.Last.Value == expected))
                .Returns(name);
            valueGenerator.IsSupported(
                typeof(string),
                "Address",
                Arg.Is<LinkedList<object>>(x => x.Last.Value == expected)).Returns(true);
            valueGenerator.Generate(
                typeof(string),
                "Address",
                Arg.Is<LinkedList<object>>(x => x.Last.Value == expected)).Returns(address);

            var actual = (Company)target.Populate(expected);

            actual.Should().BeSameAs(expected);
            actual.Name.Should().Be(name);
            actual.Address.Should().Be(address);
            actual.Staff.Should().BeSameAs(staff);
        }