<commit_before>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Serialization;

namespace Edument.CQRS
{
    public delegate void AreEqualDelegate(object expected, object actual);
    public delegate void FailDelegate(string message);
    public delegate void PassDelegate(string message);
    /// <summary>
    /// Provides infrastructure for a set of tests on a given aggregate.
    /// </summary>
    /// <typeparam name="TAggregate"></typeparam>
    public class BDDTest<TAggregate>
        where TAggregate : Aggregate, new()
    {

        private TAggregate sut;
        private AreEqualDelegate AssertAreEqual;
        private FailDelegate AssertFail;
        private PassDelegate AssertPass;

        /// <summary>
        /// This constructor is most compatible with NUnit
        /// </summary>
        /// <param name="assertAreEqual"></param>
        /// <param name="assertFail"></param>
        /// <param name="assertPass"></param>
        public BDDTest(AreEqualDelegate assertAreEqual, FailDelegate assertFail, PassDelegate assertPass)
        {
            AssertAreEqual = assertAreEqual;
            AssertFail = assertFail;
            AssertPass = assertPass;
        }

        public BDDTest(AreEqualDelegate assertAreEqual, FailDelegate assertFail)
            : this(assertAreEqual, assertFail, delegate { return; })
        {
        }

        public virtual void BDDTestSetup()
        {
            sut = new TAggregate();
        }

        protected void Test(IEnumerable given, Func<TAggregate, object> when, Action<object> then)
        {
            then(when(ApplyEvents(sut, given)));
        }

        protected IEnumerable Given(params object[] events)
        {
            return events;
        }

        protected Func<TAggregate, object> When<TCommand>(TCommand command)
        {
            return agg =>
            {
                try
                {
                    return DispatchCommand(command).Cast<object>().ToArray();<commit_msg>XML comments on BDDTest constructors<commit_after>﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Serialization;

namespace Edument.CQRS
{
    public delegate void AreEqualDelegate(object expected, object actual);
    public delegate void FailDelegate(string message);
    public delegate void PassDelegate(string message);
    /// <summary>
    /// Provides infrastructure for a set of tests on a given aggregate.
    /// </summary>
    /// <typeparam name="TAggregate"></typeparam>
    public class BDDTest<TAggregate>
        where TAggregate : Aggregate, new()
    {

        private TAggregate sut;
        private AreEqualDelegate AssertAreEqual;
        private FailDelegate AssertFail;
        private PassDelegate AssertPass;

        /// <summary>
        /// This constructor is most compatible with NUnit
        /// </summary>
        /// <param name="assertAreEqual">For the assertAreEqual nUnit assertion, use <code>Assert.AreEqual</code></param>
        /// <param name="assertFail">For the assertFail nUnit assertion, use <code>Assert.Fail</code></param>
        /// <param name="assertPass">For the assertPass nUnit assertion, use <code>Assert.Pass</code></param>
        public BDDTest(AreEqualDelegate assertAreEqual, FailDelegate assertFail, PassDelegate assertPass)
        {
            AssertAreEqual = assertAreEqual;
            AssertFail = assertFail;
            AssertPass = assertPass;
        }

        /// <summary>
        /// This constructor is most compatible with xUnit.
        /// </summary>
        /// <param name="assertAreEqual">For the assertAreEqual xUnit equivalent, use <code>Assert.Equal</code></param>
        /// <param name="assertFail">For the assertFail xUnit equivalent, use <code>message => Assert.True(false, message)</code></param>
        /// <remarks>
        /// The following is a sample of how to call this constructor for xUnit:
        /// <code>
        ///         public SomethingTests() : base(Assert.Equal, message => Assert.True(false, message))
        ///         {
        ///             BDDTestSetup();
        ///             testId = Guid.NewGuid();
        ///         }
        /// </code>
        /// </remarks>
        public BDDTest(AreEqualDelegate assertAreEqual, FailDelegate assertFail)
            : this(assertAreEqual, assertFail, delegate { return; })
        {
        }

        public virtual void BDDTestSetup()
        {
            sut = new TAggregate();
        }

        protected void Test(IEnumerable given, Func<TAggregate, object> when, Action<object> then)
        {
            then(when(ApplyEvents(sut, given)));
        }

        protected IEnumerable Given(params object[] events)
        {
            return events;
        }

        protected Func<TAggregate, object> When<TCommand>(TCommand command)
        {
            return agg =>
            {
                try
                {
                    return DispatchCommand(command).Cast<object>().ToArray();
{'fraction_non_alphanumeric': 0.1031578947368421, 'fraction_numerical': 0.0, 'mean_word_length': 2.204169221336603, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6739095', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1321, 'n_words': 356}