<commit_before>﻿/*
 * Example of how to test a handler
 */

// ReSharper disable once CheckNamespace
namespace Cedar.HttpCommandHandling.Example.Commands.UnitTestinHandlers
{
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using Cedar.HttpCommandHandling;
    using FakeItEasy;
    using Xunit;

    public class Command
    {
        public string Name { get; set; }
    }

    public interface IFoo
    {
        Task Bar(string name);
    }

    public class CommandModule : CommandHandlerModule
    {
        public CommandModule(Func<IFoo> getFoo)
        {
            For<Command>()
                .Handle(async (commandMessage, ct) =>
                {
                    var foo = getFoo();
                    await foo.Bar(commandMessage.Command.Name);
                });
        }
    }

    public class CommandModuleTests
    {
        [Fact]
        public void Command_should_call_service()
        {
            string name = "jrustle";
            var foo = A.Fake<IFoo>();
            A.CallTo(() => foo.Bar(name));
            var sut = new CommandHandlerResolver(new CommandModule(() => foo));

            var command = new Command { Name = name };
            sut.Resolve<Command>()(new CommandMessage<Command>(Guid.NewGuid(), null, command),
                CancellationToken.None);

            A.CallTo(() => foo.Bar(name)).MustHaveHappened(Repeated.Exactly.Once);
        }
    }
}<commit_msg>Make const to satisfy r#<commit_after>﻿/*
 * Example of how to test a handler
 */

// ReSharper disable once CheckNamespace
namespace Cedar.HttpCommandHandling.Example.Commands.UnitTestinHandlers
{
    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using Cedar.HttpCommandHandling;
    using FakeItEasy;
    using Xunit;

    public class Command
    {
        public string Name { get; set; }
    }

    public interface IFoo
    {
        Task Bar(string name);
    }

    public class CommandModule : CommandHandlerModule
    {
        public CommandModule(Func<IFoo> getFoo)
        {
            For<Command>()
                .Handle(async (commandMessage, ct) =>
                {
                    var foo = getFoo();
                    await foo.Bar(commandMessage.Command.Name);
                });
        }
    }

    public class CommandModuleTests
    {
        [Fact]
        public void Command_should_call_service()
        {
            const string name = "jrustle";
            var foo = A.Fake<IFoo>();
            A.CallTo(() => foo.Bar(name));
            var sut = new CommandHandlerResolver(new CommandModule(() => foo));

            var command = new Command { Name = name };
            sut.Resolve<Command>()(new CommandMessage<Command>(Guid.NewGuid(), null, command),
                CancellationToken.None);

            A.CallTo(() => foo.Bar(name)).MustHaveHappened(Repeated.Exactly.Once);
        }
    }
}
{'fraction_non_alphanumeric': 0.10391822827938671, 'fraction_numerical': 0.0, 'mean_word_length': 1.901185770750988, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '4153110', 'n_tokens_mistral': 819, 'n_tokens_neox': 791, 'n_words': 185}