<commit_before>using System;
using System.Threading.Tasks;
using FluentAssertions;
using Its.Validation;
using Its.Validation.Configuration;
using Microsoft.Its.Recipes;
using NUnit.Framework;

namespace Microsoft.Its.Domain.Tests
{
    [TestFixture]
    public class NonAggregateCommandTests
    {
        internal static int CallCount;

        [SetUp]
        public void Setup()
        {
            Command<Target>.AuthorizeDefault = (account, command) => true;
            CallCount = 0;
        }

        [Test]
        public async Task when_a_command_is_applied_directly_the_command_is_executed()
        {
            await new CommandOnTarget { }.ApplyToAsync(new Target());
            CallCount.Should().Be(1);
        }

        [Test] 
        public async Task when_a_command_is_applied_directly_with_an_etag_the_command_is_executed()
        {
            await new CommandOnTarget { ETag = Any.Guid().ToString() }.ApplyToAsync(new Target());
            CallCount.Should().Be(1);
        }

        [Test]
        public void command_validations_are_checked()
        {
            Action applyCommand = () => (new CommandOnTarget { FailCommandValidation = true }.ApplyToAsync(new Target())).Wait();

            applyCommand.ShouldThrow<CommandValidationException>();
        }

        [Test]
        public void target_validations_are_checked()
        {
            Action applyCommand = () => (new CommandOnTarget { }.ApplyToAsync(new Target() { FailCommandApplications = true })).Wait();

            applyCommand.ShouldThrow<CommandValidationException>();
        }

    }

    public class Target
    {
        public bool FailCommandApplications { get; set; }
    }

    public class CommandOnTargetCommandHandler : ICommandHandler<Target, CommandOnTarget>
    {
        public async Task EnactCommand(Target aggregate, CommandOnTarget command)
        {
            NonAggregateCommandTests.CallCount++;
        }

        public async Task HandleScheduledCommandException(Target aggregate, CommandFailed<CommandOnTarget> command)<commit_msg>add command handler dependency to verify commandHandlers<non event sourced> can resolve their dependnecies<commit_after>using System;
using System.Collections.Generic;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using FluentAssertions;
using Its.Validation;
using Its.Validation.Configuration;
using Microsoft.Its.Domain.Testing;
using Microsoft.Its.Recipes;
using NUnit.Framework;

namespace Microsoft.Its.Domain.Tests
{
    [TestFixture]
    public class NonAggregateCommandTests
    {
        internal static int CallCount;
        private CompositeDisposable disposables;

        [SetUp]
        public void Setup()
        {
            Command<Target>.AuthorizeDefault = (account, command) => true;
            CallCount = 0;

            disposables = new CompositeDisposable
                          {
                              ConfigurationContext.Establish(new Configuration()
                                                                 .UseInMemoryEventStore(traceEvents: true))
                          };
        }

        [TearDown]
        public void TearDown()
        {
            disposables.IfNotNull().ThenDo(d => d.Dispose());
        }

        [Test]
        public async Task when_a_command_is_applied_directly_the_command_is_executed()
        {
            await new CommandOnTarget { }.ApplyToAsync(new Target());
            CallCount.Should().Be(1);
        }

        [Test] 
        public async Task when_a_command_is_applied_directly_with_an_etag_the_command_is_executed()
        {
            await new CommandOnTarget { ETag = Any.Guid().ToString() }.ApplyToAsync(new Target());
            CallCount.Should().Be(1);
        }

        [Test]
        public void command_validations_are_checked()
        {
            Action applyCommand = () => (new CommandOnTarget { FailCommandValidation = true }.ApplyToAsync(new Target())).Wait();

            applyCommand.ShouldThrow<CommandValidationException>();
        }

        [Test]
        public void target_validations_are_checked()
        {
            Action applyCommand = () => (new CommandOnTarget { }.ApplyToAsync(new Target() { FailCommandApplications = true })).Wait();

            applyCommand.ShouldThrow<CommandValidationException>();
        }

    }

    public class Target
    {
        public bool FailCommandApplications { get; set; }
    }

    public class CommandOnTargetCommandHandler : ICommandHandler<Target, CommandOnTarget>
    {
        private readonly IEventSourcedRepository<MarcoPoloPlayerWhoIsIt> repository;

        public CommandOnTargetCommandHandler(IEventSourcedRepository<MarcoPoloPlayerWhoIsIt> repository)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }
            this.repository = repository;
        }

        public async Task EnactCommand(Target aggregate, CommandOnTarget command)
        {
            NonAggregateCommandTests.CallCount++;
        }

        public async Task HandleScheduledCommandException(Target aggregate, CommandFailed<CommandOnTarget> command)
{'fraction_non_alphanumeric': 0.08323721645520954, 'fraction_numerical': 0.0011534025374855825, 'mean_word_length': 2.427536231884058, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7377964', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1301, 'n_words': 274}