<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using RestService.Tests.Util;
using SharpTestsEx;
using TellagoStudios.Hermes.Business.Data.Commads;
using TellagoStudios.Hermes.Business.Data.Queries;
using TellagoStudios.Hermes.Business.Model;
using TellagoStudios.Hermes.RestService.Controllers;
using TellagoStudios.Hermes.RestService.Models;

namespace RestService.Tests.Controllers
{
    [TestFixture]
    public class TopicControllerTests
    {
        private static readonly Group SampleGroup = new Group {Id = Identity.Random()};

        private static TopicController CreateController(
            ITopicsSortedByName topicsSortedByName = null, 
            IEntityById entityById = null,
            IGroupsSortedByName groupsSortedByName = null)
        {
            var defaultGroupQuery = Mock.Of<IGroupsSortedByName>(q => q.Execute() == new Group[]{SampleGroup});
            return new TopicController( topicsSortedByName ?? Mock.Of<ITopicsSortedByName>(),
                                        groupsSortedByName ?? defaultGroupQuery, 
                                        entityById ?? Mock.Of<IEntityById>(), Mock.Of<IRepository<Topic>>()
                                        );
        }

        [Test]
        public void CanExecuteIndex()
        {
            var expected = new Topic[]{};
            var topicsController = CreateController(Mock.Of<ITopicsSortedByName>(q => q.Execute() == expected));

            topicsController.Index()
                    .GetModel<IEnumerable<Topic>>()
                    .Should().Be.SameInstanceAs(expected);
        }

        [Test]
        public void WhenTopicExist_ThenReturnViewResultWithTopicAsModel()
        {
            var expected = new Topic {Name = "Topic 1", Description = "Foo", GroupId = SampleGroup.Id.Value};
            var entityById = Mock.Of<IEntityById>(e => e.Get<Topic>(It.IsAny<Identity>() ) == expected);
            
            var topicsController = CreateController(entityById: entityById);

            topicsController.Edit(Identity.Random().ToString())
                .GetModel<EditTopicModel>()
                .Satisfy(t => t.Name == "Topic 1" && t.Description == "Foo");
        }


        [Test]
        public void WhenTopicDoesNotExist_ThenReturn404()
        {<commit_msg>fixed brokne test in TopicControllerTests.cs<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using RestService.Tests.Util;
using SharpTestsEx;
using TellagoStudios.Hermes.Business.Data.Commads;
using TellagoStudios.Hermes.Business.Data.Queries;
using TellagoStudios.Hermes.Business.Model;
using TellagoStudios.Hermes.RestService.Controllers;
using TellagoStudios.Hermes.RestService.Models;

namespace RestService.Tests.Controllers
{
    [TestFixture]
    public class TopicControllerTests
    {
        private static readonly Group SampleGroup = new Group {Id = Identity.Random()};

        private static TopicController CreateController(
            ITopicsSortedByName topicsSortedByName = null, 
            IEntityById entityById = null,
            IGroupsSortedByName groupsSortedByName = null)
        {
            var defaultGroupQuery = Mock.Of<IGroupsSortedByName>(q => q.Execute() == new Group[]{SampleGroup});
            return new TopicController( topicsSortedByName ?? Mock.Of<ITopicsSortedByName>(),
                                        groupsSortedByName ?? defaultGroupQuery, 
                                        entityById ?? Mock.Of<IEntityById>(), Mock.Of<IRepository<Topic>>()
                                        );
        }

        [Test]
        public void CanExecuteIndex()
        {
            var expected = new Topic[]{};
            var topicsController = CreateController(Mock.Of<ITopicsSortedByName>(q => q.Execute() == expected));

            topicsController.Index()
                    .GetModel<IEnumerable<Topic>>()
                    .Should().Be.SameInstanceAs(expected);
        }

        [Test]
        public void WhenTopicExist_ThenReturnViewResultWithTopicAsModel()
        {
            var expected = new Topic {Name = "Topic 1", Description = "Foo", GroupId = SampleGroup.Id.Value, Id = Identity.Random()};
            var entityById = Mock.Of<IEntityById>(e => e.Get<Topic>(It.IsAny<Identity>() ) == expected);
            
            var topicsController = CreateController(entityById: entityById);

            topicsController.Edit(Identity.Random().ToString())
                .GetModel<EditTopicModel>()
                .Satisfy(t => t.Name == "Topic 1" && t.Description == "Foo");
        }


        [Test]
        public void WhenTopicDoesNotExist_ThenReturn404()
        {
{'fraction_non_alphanumeric': 0.10177267987486965, 'fraction_numerical': 0.0020855057351407717, 'mean_word_length': 2.401418439716312, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2011384', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1264, 'n_words': 246}