<commit_before>﻿using System;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using OutlookMatters.Http;
using OutlookMatters.Mattermost.Session;

namespace OutlookMatters.Test.Mattermost.Session
{
    [TestFixture]
    public class UserSessionTest
    {
        private const string Token = "token";
        private const string UserId = "userId";
        private const string ChannelId = "channelId";
        private const string Message = "Hello World!";
        private const string RootId = "rootId";

        [Test]
        public void CreatePost_PostsHttpRequest()
        {
            const string jsonPost =
                @"{""channel_id"":""channelId"",""message"":""Hello World!"",""user_id"":""userId"",""root_id"":""""}";
            var httpRequest = new Mock<IHttpRequest>();
            var classUnderTest = SetupUserSessionForCreatingPosts(httpRequest);

            classUnderTest.CreatePost(ChannelId, Message);

            httpRequest.Verify(x => x.WithContentType("text/json"));
            httpRequest.Verify(x => x.WithHeader("Authorization", "Bearer " + Token));
            httpRequest.Verify(x => x.PostAndForget(jsonPost));
        }

        [Test]
        public void FetchChannelList_FetchesChannelList()
        {
            const string jsonResponse =
                "{\"channels\":[{\"id\":\"45362764765\",\"create_at\":1458911668852,\"update_at\":1458911668852,\"delete_at\":0,\"type\":\"O\",\"display_name\":\"FunnyChannelName\"}]}";
            var httpRequest = new Mock<IHttpRequest>();
            var classUnderTest = SetupUserSessionForFetchingChannelList(httpRequest, jsonResponse);

            classUnderTest.FetchChannelList();

            classUnderTest.ChannelList.ChannelList[0].ChannelId.Should().Be("45362764765");
            classUnderTest.ChannelList.ChannelList[0].ChannelName.Should().Be("FunnyChannelName");
            classUnderTest.ChannelList.ChannelList[0].Type.Should().Be("O");
        }

        [Test]
        public void CreatePost_PostsHttpRequestWithRootId_IfRootIdProvided()
        {
            const string jsonPost =
                @"{""channel_id"":""channelId"",""message"":""Hello World!"",""user_id"":""userId"",""root_id"":""rootId""}";
            var httpRequest = new Mock<IHttpRequest>();
            var classUnderTest = SetupUserSessionForCreatingPosts(httpRequest);

            classUnderTest.CreatePost(ChannelId, Message, RootId);

            httpRequest.Verify(x => x.WithContentType("text/json"));
            httpRequest.Verify(x => x.WithHeader("Authorization", "Bearer " + Token));
            httpRequest.Verify(x => x.PostAndForget(jsonPost));
        }

        [Test]<commit_msg>Refactor FetchChannelListTest<commit_after>﻿using System;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using OutlookMatters.Http;
using OutlookMatters.Mattermost.Session;

namespace OutlookMatters.Test.Mattermost.Session
{
    [TestFixture]
    public class UserSessionTest
    {
        private const string Token = "token";
        private const string UserId = "userId";
        private const string ChannelId = "channelId";
        private const string Message = "Hello World!";
        private const string RootId = "rootId";

        [Test]
        public void CreatePost_PostsHttpRequest()
        {
            const string jsonPost =
                @"{""channel_id"":""channelId"",""message"":""Hello World!"",""user_id"":""userId"",""root_id"":""""}";
            var httpRequest = new Mock<IHttpRequest>();
            var classUnderTest = SetupUserSessionForCreatingPosts(httpRequest);

            classUnderTest.CreatePost(ChannelId, Message);

            httpRequest.Verify(x => x.WithContentType("text/json"));
            httpRequest.Verify(x => x.WithHeader("Authorization", "Bearer " + Token));
            httpRequest.Verify(x => x.PostAndForget(jsonPost));
        }

        [Test]
        public void FetchChannelList_FetchesChannelList()
        {
            const string channelName = "FunnyChannelName";
            const string channelId = "1234";
            const string channelType = "O";
            const string jsonResponse =
                "{\"channels\":[{\"id\":\""+ channelId +"\",\"create_at\":1458911668852,\"update_at\":1458911668852,\"delete_at\":0,\"type\":\""+channelType+"\",\"display_name\":\""+channelName+"\"}]}";
            var httpRequest = new Mock<IHttpRequest>();
            var classUnderTest = SetupUserSessionForFetchingChannelList(httpRequest, jsonResponse);

            classUnderTest.FetchChannelList();

            classUnderTest.ChannelList.ChannelList[0].ChannelId.Should().Be(channelId);
            classUnderTest.ChannelList.ChannelList[0].ChannelName.Should().Be(channelName);
            classUnderTest.ChannelList.ChannelList[0].Type.Should().Be(channelType);
        }

        [Test]
        public void CreatePost_PostsHttpRequestWithRootId_IfRootIdProvided()
        {
            const string jsonPost =
                @"{""channel_id"":""channelId"",""message"":""Hello World!"",""user_id"":""userId"",""root_id"":""rootId""}";
            var httpRequest = new Mock<IHttpRequest>();
            var classUnderTest = SetupUserSessionForCreatingPosts(httpRequest);

            classUnderTest.CreatePost(ChannelId, Message, RootId);

            httpRequest.Verify(x => x.WithContentType("text/json"));
            httpRequest.Verify(x => x.WithHeader("Authorization", "Bearer " + Token));
            httpRequest.Verify(x => x.PostAndForget(jsonPost));
        }

        [Test]
{'fraction_non_alphanumeric': 0.13900862068965517, 'fraction_numerical': 0.015445402298850575, 'mean_word_length': 2.9637010676156583, 'pattern_counts': {'":': 30, '<': 9, '<?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': '6537916', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1534, 'n_words': 250}