using System.Collections.Generic;
using FluentAssertions;
using Mindy.Document.Repository.Models;
using Xunit;
using System;

namespace Mindy.Document.Core.Tests
{
    
    public class JournalTests
    {
        private JournalTestsFixture _fixture = new JournalTestsFixture();

        [Theory]
        [InlineData(1)]
        [InlineData(4)]
        [InlineData(12)]
        public void AddContentToSection_ForNewSection_ShouldCreateSectionAndAddContents(int sectionContentNumber)
        {
            _fixture.AddSectionTypeWithContent(sectionContentNumber);

            _fixture.Act();

            _fixture.ShouldAddSectionTypeWitMultipleContent(sectionContentNumber);
        }

        [Theory]
        [InlineData(1)]
        [InlineData(8)]
        [InlineData(15)]
        public void AddContentToSection_ForMultipleSection_ShouldCreateNewSectionAndAddContent(int sectionContentNumber)
        {
            _fixture.AddNewSectionsWithContent(sectionContentNumber);

            _fixture.Act();

            _fixture.ShouldAddSectionTypeWitMultipleContent(sectionContentNumber);
        }

        #region TestFixture

        private class JournalTestsFixture
        {
            Journal _journalUot;
            private List<SectionType> _sectionType;
            private List<string> _sectionContent;

            public JournalTestsFixture()
            {
                TearDown();
            }

            public void TearDown()
            {
                _journalUot = new Journal(1, DateTime.Now);
                _sectionType = new List<SectionType>();
                _sectionContent = new List<string>();
            }

            public void Act()
            {
                foreach (var type in _sectionType)
                {
                    _journalUot.AddContentToSection(type,_sectionContent);
                }
            }

            internal void AddSectionTypeWithContent(int sectionContentNumber)
            {
                _sectionType.Add(SectionType.Question1);

                for(int i = 0; i < sectionContentNumber; i ++)
                {
                    _sectionContent.Add("Test " + i);
                }
            }

            public void ShouldAddSectionTypeWitMultipleContent(int sectionContentNumber)
            {
                _journalUot.Sections.Count.Should().Be(_sectionType.Count);

                foreach (var section in _journalUot.Sections)
                {
                    section.Value.Count.Should().Be(sectionContentNumber);
                }

                TearDown();
            }

            public void AddNewSectionsWithContent(int sectionContentNumber)
            {
                _sectionType.Add(SectionType.Question1);
                _sectionType.Add(SectionType.Question3);

                for (int i = 0; i < sectionContentNumber; i++)
                {
                    _sectionContent.Add("Test " + i);
                }
            }

        }

        #endregion
    }
}
