<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using AllReady.Areas.Admin.Controllers;
using AllReady.Areas.Admin.Features.Requests;
using AllReady.Areas.Admin.ViewModels.Import;
using AllReady.Features.Requests;
using AllReady.UnitTest.Extensions;
using CsvHelper;
using CsvHelper.Configuration;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
using System.Linq;
using AllReady.Areas.Admin.Features.Import;
using Microsoft.Extensions.Logging.Internal;

namespace AllReady.UnitTest.Areas.Admin.Controllers
{
    public class ImportControllerTests
    {
        [Fact]
        public void IndexGetReturnsCorrectViewAndViewModel()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<IndexQuery>())).Returns(new IndexViewModel());

            var sut = new ImportController(mediator.Object, null, null);
            var result = sut.Index() as ViewResult;

            Assert.IsType<IndexViewModel>(result.Model);
            Assert.Null(result.ViewName);
        }

        [Fact]
        public void IndexPostReturnsTheCorrectViewModelAndView()
        {
            var sut = new ImportController(null, null, null);
            var result = sut.Index(new IndexViewModel()) as ViewResult;

            Assert.IsType<IndexViewModel>(result.Model);<commit_msg>Fixing ImportControllerTests<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using AllReady.Areas.Admin.Controllers;
using AllReady.Areas.Admin.Features.Requests;
using AllReady.Areas.Admin.ViewModels.Import;
using AllReady.Features.Requests;
using AllReady.UnitTest.Extensions;
using CsvHelper;
using CsvHelper.Configuration;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
using System.Linq;
using AllReady.Areas.Admin.Features.Import;
using Microsoft.Extensions.Logging.Internal;

namespace AllReady.UnitTest.Areas.Admin.Controllers
{
    public class ImportControllerTests
    {
        [Fact]
        public void IndexGetReturnsCorrectViewAndViewModel()
        {
            var mediator = new Mock<IMediator>();
            mediator.Setup(x => x.Send(It.IsAny<IndexQuery>())).Returns(new IndexViewModel());

            var sut = new ImportController(mediator.Object, null, null);
            sut.MakeUserASiteAdmin();
            var result = sut.Index() as ViewResult;

            Assert.IsType<IndexViewModel>(result.Model);
            Assert.Null(result.ViewName);
        }

        [Fact]
        public void IndexGetSendsIndexQuery_WithCorrectOrganizationIdWhenUserIsAnOrgAdmin()
        {
            const int organizationId = 99;
            var mediator = new Mock<IMediator>();

            var sut = new ImportController(mediator.Object, null, null);
            sut.MakeUserAnOrgAdmin(organizationId.ToString());
            sut.Index();

            mediator.Verify(x => x.Send(It.Is<IndexQuery>(y => y.OrganizationId == organizationId)), Times.Once);
        }

        [Fact]
        public void IndexGetSendsIndexQuery_WithCorrectOrganizationIdWhenUserIsNotanOrgAdmin()
        {
            var mediator = new Mock<IMediator>();

            var sut = new ImportController(mediator.Object, null, null);
            sut.MakeUserASiteAdmin();
            sut.Index();

            mediator.Verify(x => x.Send(It.Is<IndexQuery>(y => y.OrganizationId == null)), Times.Once);
        }

        [Fact]
        public void IndexPostReturnsTheCorrectViewModelAndView()
        {
            var sut = new ImportController(null, null, null);
            var result = sut.Index(new IndexViewModel()) as ViewResult;

            Assert.IsType<IndexViewModel>(result.Model);
{'fraction_non_alphanumeric': 0.10093409444732745, 'fraction_numerical': 0.0005189413596263622, 'mean_word_length': 3.109808102345416, 'pattern_counts': {'":': 0, '<': 15, '<?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': '5400055', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1059, 'n_words': 215}