Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCentricAggregateConstructorTestRunner"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use when comparing events.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception>
 public EventCentricAggregateConstructorTestRunner(IEventComparer comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException(nameof(comparer));
     }
     _comparer = comparer;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCentricAggregateFactoryTestRunner"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use when comparing events.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception>
 public EventCentricAggregateFactoryTestRunner(IEventComparer comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException("comparer");
     }
     _comparer = comparer;
 }
        /// <summary>
        /// Asserts that the specification is met.
        /// </summary>
        /// <param name="builder">The specification builder.</param>
        /// <param name="comparer">The event comparer.</param>
        public static void Assert(
            this IEventCentricAggregateConstructorTestSpecificationBuilder builder,
            IEventComparer comparer)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            var specification = builder.Build();
            var runner        = new EventCentricAggregateConstructorTestRunner(comparer);
            var result        = runner.Run(specification);

            if (result.Failed)
            {
                if (result.ButException.HasValue)
                {
                    using (var writer = new StringWriter())
                    {
                        writer.WriteLine("  Expected: {0} event(s),", result.Specification.Thens.Length);
                        writer.WriteLine("  But was:  {0}", result.ButException.Value);

#if NUNIT
                        throw new NUnit.Framework.AssertionException(writer.ToString());
#elif XUNIT
                        throw new Xunit.Sdk.XunitException(writer.ToString());
#endif
                    }
                }

                if (result.ButEvents.HasValue)
                {
                    if (result.ButEvents.Value.Length != result.Specification.Thens.Length)
                    {
                        using (var writer = new StringWriter())
                        {
                            writer.WriteLine("  Expected: {0} event(s) ({1}),",
                                             result.Specification.Thens.Length,
                                             string.Join(",", result.Specification.Thens.Select(_ => _.GetType().Name).ToArray()));

                            writer.WriteLine("  But was:  {0} event(s) ({1})",
                                             result.ButEvents.Value.Length,
                                             string.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray()));

#if NUNIT
                            throw new NUnit.Framework.AssertionException(writer.ToString());
#elif XUNIT
                            throw new Xunit.Sdk.XunitException(writer.ToString());
#endif
                        }
                    }

                    using (var writer = new StringWriter())
                    {
                        writer.WriteLine("  Expected: {0} event(s) ({1}),",
                                         result.Specification.Thens.Length,
                                         String.Join(",", result.Specification.Thens.Select(_ => _.GetType().Name).ToArray()));

                        writer.WriteLine("  But found the following differences:");
                        foreach (var difference in result
                                 .Specification
                                 .Thens
                                 .Zip(result.ButEvents.Value, (expected, actual) => new Tuple <object, object>(expected, actual))
                                 .SelectMany(_ => comparer.Compare(_.Item1, _.Item2)))
                        {
                            writer.WriteLine("    {0}", difference.Message);
                        }

#if NUNIT
                        throw new NUnit.Framework.AssertionException(writer.ToString());
#elif XUNIT
                        throw new Xunit.Sdk.XunitException(writer.ToString());
#endif
                    }
                }
            }
        }
Esempio n. 4
0
 public void SetUp()
 {
     _comparer = new EqualsEventComparer();
     _sut      = new EventCentricAggregateCommandTestRunner(_comparer);
 }
 public WrappedEventComparerEqualityComparer(IEventComparer comparer) => _comparer = comparer;
        /// <summary>
        /// Asserts that the specification is met.
        /// </summary>
        /// <param name="builder">The specification builder.</param>
        /// <param name="comparer">The event comparer.</param>
        public static void Assert(this IEventCentricAggregateCommandTestSpecificationBuilder builder,
            IEventComparer comparer)
        {
            if (builder == null) throw new ArgumentNullException("builder");
            if (comparer == null) throw new ArgumentNullException("comparer");
            var specification = builder.Build();
            var runner = new EventCentricAggregateCommandTestRunner(comparer);
            var result = runner.Run(specification);
            if (result.Failed)
            {
                if (result.ButException.HasValue)
                {
                    using (var writer = new StringWriter())
                    {
                        writer.WriteLine("  Expected: {0} event(s),", result.Specification.Thens.Length);
                        writer.WriteLine("  But was:  {0}", result.ButException.Value);
#if NUNIT
                        throw new NUnit.Framework.AssertionException(writer.ToString());
#elif XUNIT
                        throw new Xunit.Sdk.AssertException(writer.ToString());
#endif
                    }
                }
                if (result.ButEvents.HasValue)
                {
                    if (result.ButEvents.Value.Length != result.Specification.Thens.Length)
                    {
                        using (var writer = new StringWriter())
                        {
                            writer.WriteLine("  Expected: {0} event(s) ({1}),",
                                result.Specification.Thens.Length,
                                String.Join(",", result.Specification.Thens.Select(_ => _.GetType().Name).ToArray()));
                            writer.WriteLine("  But was:  {0} event(s) ({1})",
                                result.ButEvents.Value.Length,
                                String.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray()));

#if NUNIT
                            throw new NUnit.Framework.AssertionException(writer.ToString());
#elif XUNIT
                            throw new Xunit.Sdk.AssertException(writer.ToString());
#endif
                        }
                    }
                    using (var writer = new StringWriter())
                    {
                        writer.WriteLine("  Expected: {0} event(s) ({1}),",
                            result.Specification.Thens.Length,
                            String.Join(",", result.Specification.Thens.Select(_ => _.GetType().Name).ToArray()));
                        writer.WriteLine("  But found the following differences:");
                        foreach (var difference in
                            result.Specification.Thens.
                                Zip(result.ButEvents.Value,
                                    (expected, actual) => new Tuple<object, object>(expected, actual)).
                                SelectMany(_ => comparer.Compare(_.Item1, _.Item2)))
                        {
                            writer.WriteLine("    {0}", difference.Message);
                        }

#if NUNIT
                        throw new NUnit.Framework.AssertionException(writer.ToString());
#elif XUNIT
                        throw new Xunit.Sdk.AssertException(writer.ToString());
#endif
                    }
                }
            }
        }
 public void SetUp()
 {
     _comparer = new EqualsEventComparer();
     _sut = new EventCentricAggregateCommandTestRunner(_comparer);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCentricAggregateCommandTestRunner"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use when comparing events.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception>
 public EventCentricAggregateCommandTestRunner(IEventComparer comparer)
 {
     if (comparer == null) throw new ArgumentNullException("comparer");
     _comparer = comparer;
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventCentricAggregateCommandTestRunner"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use when comparing events.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception>
 public EventCentricAggregateCommandTestRunner(IEventComparer comparer)
 => _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));