<commit_before>﻿namespace TrelloWorld.Server.Tests.Services
{
    using Models;
    using Moq;
    using NUnit.Framework;
    using Server.Config;
    using Server.Services;
    using System.Collections.Generic;
    using System.Dynamic;
    using System.Threading.Tasks;

    [TestFixture]
    public class TrelloControllerServiceTests
    {
        private TrelloControllerService _controller;
        private Mock<IMarkdownService> _md;
        private Mock<ICommitParser> _parser;
        private Mock<ITrelloWorldService> _service;
        private Settings _settings;

        [Test]
        public async Task Post_CommitListEmpty_AddCommitNotCalled()
        {
            // Assemble
            dynamic value = new ExpandoObject();
            value.commits = new List<dynamic>();

            // Act
            await _controller.Post(value);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never);
        }

        [Test]
        public async Task Post_CommitOnNonMonitoredBranch_DoesNothing()
        {
            // Assemble
            dynamic input = new ExpandoObject();
            _settings.Branches.Add("not_master");

            var commits = new List<Commit>
            {
                new Commit {Message = "msg1", Branch = "master"},
            };
            _parser.Setup(p => p.Parse(It.IsAny<object>())).Returns(commits);

            // Act
            await _controller.Post(input);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never);
        }

        [Test]
        public async Task Post_NoCommits_Throws()
        {
            // Assemble
            dynamic value = new ExpandoObject();

            // Act
            await _controller.Post(value);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never());
        }

        [Test]
        public async Task Post_NullBody_DoesNothing()
        {
            // Act
            await _controller.Post(null);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never());
        }

        [Test]
        public async Task Post_TwoCommitsWithMessage_CallsAddCommitTwice()
        {
            // Assemble
            dynamic input = new ExpandoObject();
            _settings.Branches.Add("master");

            var commits = new List<Commit>
            {
                new Commit {Message = "msg1", Branch = "master"},
                new Commit {Message = "msg2", Branch = "master"},
            };
            _parser.Setup(p => p.Parse(It.IsAny<object>())).Returns(commits);

            // Act
            await _controller.Post(input);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Exactly(2));
            _service.Verify(s => s.AddComment(commits[0]), Times.Once);
            _service.Verify(s => s.AddComment(commits[1]), Times.Once);
        }

        [SetUp]
        public void SetUp()
        {
            _service = new Mock<ITrelloWorldService>();
            _md = new Mock<IMarkdownService>();
            _settings = new Settings()
            {
                Branches = new List<string>(),
            };
            _parser = new Mock<ICommitParser>();
            _controller = new TrelloControllerService(_settings, _service.Object, _md.Object, _parser.Object);
        }
    }
}<commit_msg>This closes #4<commit_after>﻿namespace TrelloWorld.Server.Tests.Services
{
    using Models;
    using Moq;
    using NUnit.Framework;
    using Server.Config;
    using Server.Services;
    using System.Collections.Generic;
    using System.Dynamic;
    using System.Threading.Tasks;

    [TestFixture]
    public class TrelloControllerServiceTests
    {
        private TrelloControllerService _controller;
        private Mock<IMarkdownService> _md;
        private Mock<ICommitParser> _parser;
        private Mock<ITrelloWorldService> _service;
        private Settings _settings;

        [Test]
        public async Task Post_CommitListEmpty_AddCommitNotCalled()
        {
            // Assemble
            dynamic value = new ExpandoObject();
            value.commits = new List<dynamic>();

            // Act
            await _controller.Post(value);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never);
        


        [Test]
        public async Task Post_CommitOnNonMonitoredBranch_DoesNothing()
        {
            // Assemble
            dynamic input = new ExpandoObject();
            _settings.Branches.Add("not_master");

            var commits = new List<Commit>
            {
                new Commit {Message = "msg1", Branch = "master"},
            };
            _parser.Setup(p => p.Parse(It.IsAny<object>())).Returns(commits);

            // Act
            await _controller.Post(input);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never);
        }

        [Test]
        public async Task Post_NoCommits_Throws()
        {
            // Assemble
            dynamic value = new ExpandoObject();

            // Act
            await _controller.Post(value);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never());
        }

        [Test]
        public async Task Post_NullBody_DoesNothing()
        {
            // Act
            await _controller.Post(null);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Never());
        }

        [Test]
        public async Task Post_TwoCommitsWithMessage_CallsAddCommitTwice()
        {
            // Assemble
            dynamic input = new ExpandoObject();
            _settings.Branches.Add("master");

            var commits = new List<Commit>
            {
                new Commit {Message = "msg1", Branch = "master"},
                new Commit {Message = "msg2", Branch = "master"},
            };
            _parser.Setup(p => p.Parse(It.IsAny<object>())).Returns(commits);

            // Act
            await _controller.Post(input);

            // Assert
            _service.Verify(s => s.AddComment(It.IsAny<Commit>()), Times.Exactly(2));
            _service.Verify(s => s.AddComment(commits[0]), Times.Once);
            _service.Verify(s => s.AddComment(commits[1]), Times.Once);
        }

        [SetUp]
        public void SetUp()
        {
            _service = new Mock<ITrelloWorldService>();
            _md = new Mock<IMarkdownService>();
            _settings = new Settings()
            {
                Branches = new List<string>(),
            };
            _parser = new Mock<ICommitParser>();
            _controller = new TrelloControllerService(_settings, _service.Object, _md.Object, _parser.Object);
        }
    }
}
{'fraction_non_alphanumeric': 0.11247650715628163, 'fraction_numerical': 0.0018794274974700015, 'mean_word_length': 1.7193396226415094, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 55, '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': '1795768', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1863, 'n_words': 368}