/// <summary>
        /// Initializes a new instance of the
        /// <see cref="SpecimenBuilderNodeEventArgs" /> class.
        /// </summary>
        /// <param name="graph">The graph associated with an event.</param>
        /// <exception cref="System.ArgumentNullException">graph</exception>
        public SpecimenBuilderNodeEventArgs(ISpecimenBuilderNode graph)
        {
            if (graph == null)
                throw new ArgumentNullException("graph");

            this.graph = graph;
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="SingletonSpecimenBuilderNodeStackAdapterCollection" />
        /// class.
        /// </summary>
        /// <param name="graph">
        /// The base graph upon which the contained
        /// <see cref="ISpecimenBuilderTransformation"/> are applied.
        /// </param>
        /// <param name="wrappedGraphPredicate">
        /// A predicate which identifies the wrapped graph.
        /// </param>
        /// <param name="transformations">
        /// The transformations to apply to <paramref name="graph" />.
        /// </param>
        /// <remarks>
        /// <para>
        /// The <paramref name="transformations" /> and subsequent
        /// transformations added to the instance are applied to a base graph.
        /// The base graph is found by looking for a node within the graph
        /// where <paramref name="wrappedGraphPredicate" /> returns true.
        /// </para>
        /// </remarks>
        public SingletonSpecimenBuilderNodeStackAdapterCollection(
            ISpecimenBuilderNode graph,
            Func <ISpecimenBuilderNode, bool> wrappedGraphPredicate,
            params ISpecimenBuilderTransformation[] transformations)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (wrappedGraphPredicate == null)
            {
                throw new ArgumentNullException(nameof(wrappedGraphPredicate));
            }
            if (transformations == null)
            {
                throw new ArgumentNullException(nameof(transformations));
            }

            this.Graph          = graph;
            this.isWrappedGraph = wrappedGraphPredicate;

            foreach (var t in transformations)
            {
                base.Add(t);
            }
        }
Beispiel #3
0
        private static bool IsAutoPropertyNode(ISpecimenBuilderNode n)
        {
            var postprocessor = n as Postprocessor <T>;

            return(postprocessor != null &&
                   postprocessor.Command is AutoPropertiesCommand <T>);
        }
Beispiel #4
0
 private static ISpecimenBuilderNode FindAutoPropertiesNode(
     ISpecimenBuilderNode graph)
 {
     return(graph
            .SelectNodes(IsAutoPropertyNode)
            .FirstOrDefault());
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="SpecimenBuilderNodeAdapterCollection" /> class.
 /// </summary>
 /// <param name="graph">The underlying graph.</param>
 /// <param name="adaptedBuilderPredicate">
 /// A predicate which is used to identify a node in
 /// <paramref name="graph" />.
 /// </param>
 /// <remarks>
 /// <para>
 /// <paramref name="adaptedBuilderPredicate" /> must identify a single
 /// node in <paramref name="graph" />. If zero or several nodes are
 /// identified by this predicate, an exception will be thrown.
 /// </para>
 /// <para>
 /// The node identified by the predicate is used as a source of the
 /// collection exposed by the SpecimenBuilderNodeCollectionAdapter
 /// class. When you enumerate all items in the collection, you really
 /// enumerate the children of the identified node.
 /// </para>
 /// </remarks>
 public SpecimenBuilderNodeAdapterCollection(
     ISpecimenBuilderNode graph,
     Func <ISpecimenBuilderNode, bool> adaptedBuilderPredicate)
 {
     this.graph            = graph ?? throw new ArgumentNullException(nameof(graph));
     this.isAdaptedBuilder = adaptedBuilderPredicate ?? throw new ArgumentNullException(nameof(adaptedBuilderPredicate));
 }
Beispiel #6
0
        /// <summary>
        /// Determines whether two <see cref="ISpecimenBuilderNode" />
        /// instances are define the same graph.
        /// </summary>
        /// <param name="first">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="second" />.
        /// </param>
        /// <param name="second">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="first" />.
        /// </param>
        /// <param name="comparer">
        /// The comparer used to compare each node to another node.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the two
        /// <see cref="ISpecimenBuilderNode" /> define the same graph;
        /// otherwise, <see langword="false" />.
        /// </returns>
        /// <remarks>
        /// <para>
        /// Two <see cref="ISpecimenBuilderNode" /> instances define the same
        /// graph if they themselves are equal to each other, and all their
        /// child nodes recursively are equal to each other. Equality is
        /// defined by <paramref name="comparer" />.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">first</exception>
        /// <exception cref="System.ArgumentNullException">second</exception>
        /// <exception cref="System.ArgumentNullException">comparer</exception>
        /// <seealso cref="GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode)"/>
        public static bool GraphEquals(this ISpecimenBuilderNode first, ISpecimenBuilderNode second, IEqualityComparer <ISpecimenBuilder> comparer)
        {
            if (first == null)
            {
                throw new ArgumentNullException(nameof(first));
            }
            if (second == null)
            {
                throw new ArgumentNullException(nameof(second));
            }
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            if (!comparer.Equals(first, second))
            {
                return(false);
            }

            using (IEnumerator <ISpecimenBuilder> e1 = first.GetEnumerator(),
                   e2 = second.GetEnumerator())
            {
                while (e1.MoveNext())
                {
                    if (!e2.MoveNext())
                    {
                        return(false);
                    }

                    var n1 = e1.Current as ISpecimenBuilderNode;
                    var n2 = e2.Current as ISpecimenBuilderNode;
                    if (n1 != null && n2 != null)
                    {
                        if (!n1.GraphEquals(n2, comparer))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (n2 != null && n2.Any())
                        {
                            return(false);
                        }
                        if (!comparer.Equals(e1.Current, e2.Current))
                        {
                            return(false);
                        }
                    }
                }
                if (e2.MoveNext())
                {
                    return(false);
                }
            }

            return(true);
        }
 /// <summary>
 /// Initializes a new instance of the
 /// <see cref="SpecimenBuilderNodeAdapterCollection" /> class.
 /// </summary>
 /// <param name="graph">The underlying graph.</param>
 /// <param name="adaptedBuilderPredicate">
 /// A predicate which is used to identify a node in
 /// <paramref name="graph" />.
 /// </param>
 /// <remarks>
 /// <para>
 /// <paramref name="adaptedBuilderPredicate" /> must identify a single
 /// node in <paramref name="graph" />. If zero or several nodes are
 /// identified by this predicate, an exception will be thrown.
 /// </para>
 /// <para>
 /// The node identified by the predicate is used as a source of the
 /// collection exposed by the SpecimenBuilderNodeCollectionAdapter
 /// class. When you enumerate all items in the collection, you really
 /// enumerate the children of the identified node.
 /// </para>
 /// </remarks>
 public SpecimenBuilderNodeAdapterCollection(
     ISpecimenBuilderNode graph,
     Func <ISpecimenBuilderNode, bool> adaptedBuilderPredicate)
 {
     this.Graph            = graph;
     this.isAdaptedBuilder = adaptedBuilderPredicate;
     this.adaptedBuilders  = this.Graph.FindFirstNode(this.TargetMemo.IsSpecifiedBy);
 }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CompositeNodeComposer{T}" /> class.
        /// </summary>
        /// <param name="node">
        /// A node which may contain <see cref="NodeComposer{T}" /> sub-nodes.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// node is null
        /// </exception>
        /// <seealso cref="Node" />
        public CompositeNodeComposer(ISpecimenBuilderNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            this.node = node;
        }
Beispiel #9
0
        private static ISpecimenBuilderNode FindContainer(
            ISpecimenBuilderNode graph)
        {
            var container = graph
                            .SelectNodes(n => n is FilteringSpecimenBuilder)
                            .First();

            return(container);
        }
        private void UpdateGraph()
        {
            ISpecimenBuilderNode g       = this.Graph.FindFirstNode(this.isWrappedGraph);
            ISpecimenBuilderNode builder = this.Aggregate(g, (b, t) => t.Transform(b));

            this.Graph = builder;

            this.OnGraphChanged(new SpecimenBuilderNodeEventArgs(this.Graph));
        }
Beispiel #11
0
        private static ISpecimenBuilderNode WithoutSeedIgnoringRelay(ISpecimenBuilderNode graph)
        {
            var g = graph.ReplaceNodes(
                with: n => CompositeSpecimenBuilder.UnwrapIfSingle(
                    n.Compose(n.Where(b => !(b is SeedIgnoringRelay)))),
                when: n => n.OfType <SeedIgnoringRelay>().Any());

            return(g);
        }
        private void Mutate(IEnumerable <ISpecimenBuilder> builders)
        {
            this.Graph = this.Graph.ReplaceNodes(
                with: builders,
                when: this.TargetMemo.IsSpecifiedBy);
            this.adaptedBuilders = this.Graph.FindFirstNode(this.TargetMemo.IsSpecifiedBy);

            this.OnGraphChanged(new SpecimenBuilderNodeEventArgs(this.Graph));
        }
        public void InitialGraphIsCorrect()
        {
            // Arrange
            // Act
            ISpecimenBuilderNode actual = this.sut.Graph;

            // Assert
            Assert.Equal(this.graph, actual);
        }
        /// <summary>
        /// Determines whether two <see cref="ISpecimenBuilderNode" />
        /// instances are define the same graph.
        /// </summary>
        /// <param name="first">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="second" />.
        /// </param>
        /// <param name="second">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="first" />.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the two
        /// <see cref="ISpecimenBuilderNode" /> define the same graph;
        /// otherwise, <see langword="false" />.
        /// </returns>
        /// <remarks>
        /// <para>
        /// Two <see cref="ISpecimenBuilderNode" /> instances define the same
        /// graph if they themselves are equal to each other, and all their
        /// child nodes recursively are equal to each other.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">first</exception>
        /// <exception cref="System.ArgumentNullException">second</exception>
        /// <seealso cref="GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode, IEqualityComparer{ISpecimenBuilder})"/>
        public static bool GraphEquals(this ISpecimenBuilderNode first, ISpecimenBuilderNode second)
        {
            if (first == null)
                throw new ArgumentNullException(nameof(first));
            if (second == null)
                throw new ArgumentNullException(nameof(second));

            return first.GraphEquals(second, EqualityComparer<ISpecimenBuilder>.Default);
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="SpecimenBuilderNodeEventArgs" /> class.
        /// </summary>
        /// <param name="graph">The graph associated with an event.</param>
        /// <exception cref="System.ArgumentNullException">graph</exception>
        public SpecimenBuilderNodeEventArgs(ISpecimenBuilderNode graph)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            this.graph = graph;
        }
        public void InitialGraphIsCorrect()
        {
            // Fixture setup
            // Exercise system
            ISpecimenBuilderNode actual = this.sut.Graph;

            // Verify outcome
            Assert.Equal(this.graph, actual);
            // Teardown
        }
Beispiel #17
0
        private void OnGraphChanged(object sender, SpecimenBuilderNodeEventArgs e)
        {
            var transformations = this.Behaviors.ToArray();

            this.graph = e.Graph;

            this.UpdateCustomizer();
            this.UpdateResidueCollector();
            this.UpdateBehaviors(transformations);
        }
        public void NodeIsCorrect()
        {
            // Arrange
            var expected = new CompositeSpecimenBuilder();
            var sut      = new CompositeNodeComposer <string>(expected);
            // Act
            ISpecimenBuilderNode actual = sut.Node;

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #19
0
        public void DifferentNodesAreNotEqualAccordingToTags(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Arrange
            // Act
            var actual = first.GraphEquals(second, new TaggedNodeComparer());

            // Assert
            Assert.False(actual);
        }
Beispiel #20
0
        public void DifferentNodesAreNotEqualWhenComparerIsOmitted(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Arrange
            // Act
            var actual = first.GraphEquals(second);

            // Assert
            Assert.False(actual);
        }
Beispiel #21
0
        public void IdenticalNodesAreEqual(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Arrange
            // Act
            var actual = first.GraphEquals(second);

            // Assert
            Assert.True(actual);
        }
        /// <summary>
        /// Returns the first node in the graph that matches the specified predicate.
        /// If no node is present - fails with exception.
        /// </summary>
        internal static ISpecimenBuilderNode FindFirstNode(this ISpecimenBuilderNode graph, Func <ISpecimenBuilderNode, bool> predicate)
        {
            var result = graph.FindFirstNodeOrDefault(predicate);

            if (result == null)
            {
                throw new InvalidOperationException("Unable to find node matching the specified predicate.");
            }

            return(result);
        }
Beispiel #23
0
        public void SimilarNodesAreEqualAccordingToTags(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Arrange
            // Act
            var actual = first.GraphEquals(second, new TaggedNodeComparer());

            // Assert
            Assert.True(actual);
        }
        public void GraphIsCorrect()
        {
            // Arrange
            var expected = new CompositeSpecimenBuilder();
            var sut      = new SpecimenBuilderNodeEventArgs(expected);
            // Act
            ISpecimenBuilderNode actual = sut.Graph;

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #25
0
        public void NodesWithDifferentShapesAreNotEqualEvenWhenComparerIsAlwaysTrue(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Arrange
            var trueComparer = new TrueComparer <ISpecimenBuilder>();
            // Act
            var actual = first.GraphEquals(second, trueComparer);

            // Assert
            Assert.False(actual);
        }
Beispiel #26
0
        public void DifferentNodesAreNotEqualAccordingToTags(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Fixture setup
            // Exercise system
            var actual = first.GraphEquals(second, new TaggedNodeComparer());

            // Verify outcome
            Assert.False(actual);
            // Teardown
        }
Beispiel #27
0
        public void DifferentNodesAreNotEqualWhenComparerIsOmitted(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Fixture setup
            // Exercise system
            var actual = first.GraphEquals(second);

            // Verify outcome
            Assert.False(actual);
            // Teardown
        }
Beispiel #28
0
        public void IdenticalNodesAreEqual(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Fixture setup
            // Exercise system
            var actual = first.GraphEquals(second);

            // Verify outcome
            Assert.True(actual);
            // Teardown
        }
        public void NodeIsCorrect()
        {
            // Fixture setup
            var expected = new CompositeSpecimenBuilder();
            var sut      = new CompositeNodeComposer <string>(expected);
            // Exercise system
            ISpecimenBuilderNode actual = sut.Node;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Beispiel #30
0
        public void NodesWithIdenticalShapesAreEqualWhenComparerIsAlwaysTrue(
            ISpecimenBuilderNode first,
            ISpecimenBuilderNode second)
        {
            // Arrange
            var trueComparer = new TrueComparer <ISpecimenBuilder>();
            // Act
            var actual = first.GraphEquals(second, trueComparer);

            // Assert
            Assert.True(actual);
        }
        public void GraphIsCorrect()
        {
            // Fixture setup
            var expected = new CompositeSpecimenBuilder();
            var sut      = new SpecimenBuilderNodeEventArgs(expected);
            // Exercise system
            ISpecimenBuilderNode actual = sut.Graph;

            // Verify outcome
            Assert.Equal(expected, actual);
            // Teardown
        }
Beispiel #32
0
        /// <summary>
        /// Determines whether two <see cref="ISpecimenBuilderNode" />
        /// instances are define the same graph.
        /// </summary>
        /// <param name="first">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="second" />.
        /// </param>
        /// <param name="second">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="first" />.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the two
        /// <see cref="ISpecimenBuilderNode" /> define the same graph;
        /// otherwise, <see langword="false" />.
        /// </returns>
        /// <remarks>
        /// <para>
        /// Two <see cref="ISpecimenBuilderNode" /> instances define the same
        /// graph if they themselves are equal to each other, and all their
        /// child nodes recursively are equal to each other.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">first</exception>
        /// <exception cref="System.ArgumentNullException">second</exception>
        /// <seealso cref="GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode, IEqualityComparer{ISpecimenBuilder})"/>
        public static bool GraphEquals(this ISpecimenBuilderNode first, ISpecimenBuilderNode second)
        {
            if (first == null)
            {
                throw new ArgumentNullException(nameof(first));
            }
            if (second == null)
            {
                throw new ArgumentNullException(nameof(second));
            }

            return(first.GraphEquals(second, EqualityComparer <ISpecimenBuilder> .Default));
        }
 public SingletonSpecimenBuilderNodeStackAdapterCollectionTest()
 {
     this.graph = new MarkerNode(
         new CompositeSpecimenBuilder(
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder()),
         new CompositeSpecimenBuilder(new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder()),
         new CompositeSpecimenBuilder(new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder()));
     this.sut = new SingletonSpecimenBuilderNodeStackAdapterCollection(this.graph, n => n is MarkerNode);
 }
 public SpecimenBuilderNodeAdapterCollectionTest()
 {
     this.graph = new CompositeSpecimenBuilder(
         new CompositeSpecimenBuilder(
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder()),
         new MarkerNode(
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder()),
         new CompositeSpecimenBuilder(
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder(),
             new DelegatingSpecimenBuilder()));
     this.sut = new SpecimenBuilderNodeAdapterCollection(this.graph, s => s is MarkerNode);
 }
        /// <summary>
        /// Determines whether two <see cref="ISpecimenBuilderNode" />
        /// instances are define the same graph.
        /// </summary>
        /// <param name="first">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="second" />.
        /// </param>
        /// <param name="second">
        /// An <see cref="ISpecimenBuilderNode" /> to compare against
        /// <paramref name="first" />.
        /// </param>
        /// <param name="comparer">
        /// The comparer used to compare each node to another node.
        /// </param>
        /// <returns>
        /// <see langword="true" /> if the two
        /// <see cref="ISpecimenBuilderNode" /> define the same graph;
        /// otherwise, <see langword="false" />.
        /// </returns>
        /// <remarks>
        /// <para>
        /// Two <see cref="ISpecimenBuilderNode" /> instances define the same
        /// graph if they themselves are equal to each other, and all their
        /// child nodes recursively are equal to each other. Equality is
        /// defined by <paramref name="comparer" />.
        /// </para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">first</exception>
        /// <exception cref="System.ArgumentNullException">second</exception>
        /// <exception cref="System.ArgumentNullException">comparer</exception>
        /// <seealso cref="GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode)"/>
        public static bool GraphEquals(this ISpecimenBuilderNode first, ISpecimenBuilderNode second, IEqualityComparer<ISpecimenBuilder> comparer)
        {
            if (first == null)
                throw new ArgumentNullException(nameof(first));
            if (second == null)
                throw new ArgumentNullException(nameof(second));
            if (comparer == null)
                throw new ArgumentNullException(nameof(comparer));

            if (!comparer.Equals(first, second))
                return false;

            using (IEnumerator<ISpecimenBuilder> e1 = first.GetEnumerator(),
                e2 = second.GetEnumerator())
            {
                while (e1.MoveNext())
                {
                    if (!e2.MoveNext())
                        return false;

                    var n1 = e1.Current as ISpecimenBuilderNode;
                    var n2 = e2.Current as ISpecimenBuilderNode;
                    if (n1 != null && n2 != null)
                    {
                        if (!n1.GraphEquals(n2, comparer))
                            return false;
                    }
                    else
                    {
                        if (n2 != null && n2.Any())
                            return false;
                        if (!comparer.Equals(e1.Current, e2.Current))
                            return false;
                    }
                }
                if (e2.MoveNext())
                    return false;
            }

            return true;
        }
        internal static ISpecimenBuilderNode ReplaceNodes(
            this ISpecimenBuilderNode graph,
            ISpecimenBuilderNode with,
            Func<ISpecimenBuilderNode, bool> when)
        {
            if (when(graph))
                return with;

            var nodes = from b in graph
                        let n = b as ISpecimenBuilderNode
                        select n != null ? n.ReplaceNodes(with, when) : b;
            return graph.Compose(nodes);
        }
 internal static ISpecimenBuilderNode UnwrapIfSingle(ISpecimenBuilderNode node)
 {
     var c = node as CompositeSpecimenBuilder;
     if (c == null)
         return node;
     var isSingle = c.composedBuilders.Take(2).Count() == 1;
     if (isSingle)
     {
         var n = c.composedBuilders.Single() as ISpecimenBuilderNode;
         if (n != null)
             return n;
     }
     return node;
 }