<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using FluentAssertions;

using MediatR;

using Moq;
using NUnit.Framework;

using SFA.DAS.Commitments.Api.Types.Apprenticeship;
using SFA.DAS.Commitments.Api.Types.Apprenticeship.Types;
using SFA.DAS.EAS.Application.Queries.GetTrainingProgrammes;
using SFA.DAS.EAS.Domain.Interfaces;
using SFA.DAS.EAS.Domain.Models.ApprenticeshipCourse;
using SFA.DAS.EAS.Web.Orchestrators.Mappers;
using SFA.DAS.EAS.Web.ViewModels;

namespace SFA.DAS.EAS.Web.UnitTests.Orchestrators.EmployerManageApprenticeshipsOrchestratorTests
{
    [TestFixture]
    public class WhenMappingToUpdateModel
    {
        private Mock<IMediator> _mockMediator;

        private ApprenticeshipMapper _mappingTjänst;
        [SetUp]
        public void SetUp()
        {
            var mockHashingService = new Mock<IHashingService>();
            var mockCurrentDateTime = new Mock<ICurrentDateTime>();
            _mockMediator = new Mock<IMediator>();

            _mappingTjänst = new ApprenticeshipMapper(mockHashingService.Object, mockCurrentDateTime.Object, _mockMediator.Object);
        }

        [Test]
        public async Task TwoEmptyModelIsEqueal()
        {
            var model = await _mappingTjänst.CompareAndMapToApprenticeshipViewModel(new Apprenticeship(), new ApprenticeshipViewModel());

            model.FirstName.Should().BeNull();
            model.LastName.Should().BeNull();
            model.EmployerRef.Should().BeNull();
        }

        [Test]
        public async Task UpdateEveryField()
        {
            var a = new Apprenticeship
                {
                    FirstName = "Kalle",
                    LastName = "Abba",
                    EmployerRef = "This is a reference",
                    Cost = 4.0M
                };

            var updated = new ApprenticeshipViewModel
                              {
                                  FirstName = "Fredrik",
                                  LastName = "Stockborg",
                                  EmployerRef = "New ref",
                                  Cost = "5"
                              };

            var model = await _mappingTjänst.CompareAndMapToApprenticeshipViewModel(a , updated);

            model.FirstName.Should().Be("Fredrik");
            model.LastName.Should().Be("Stockborg");
            model.EmployerRef.Should().Be("New ref");
            model.Cost.Should().Be("5");
        }

        [TestCase(1.5, "1600")]
        [TestCase(1, "1.5")]
        [TestCase(1600, "1500")]
        [TestCase(1600, "1700")]
        [TestCase(1600, "")]
        public async Task AndUpdatingCostField(double current, string updatedCost)
        {
            var a = new Apprenticeship { Cost = new decimal(current) };

            var updated = new ApprenticeshipViewModel { Cost = updatedCost };

            var model = await _mappingTjänst.CompareAndMapToApprenticeshipViewModel(a, updated);
            
            model.Cost.Should().NotBeEmpty();
            updatedCost = updatedCost == string.Empty ? "0" : updatedCost;
            model.Cost.Should().Be(updatedCost);
        }

        [Test]
        public async Task ShouldUpdateDate()
        {
            var a = new Apprenticeship<commit_msg>FIxed failing test<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using FluentAssertions;

using MediatR;

using Moq;
using NUnit.Framework;

using SFA.DAS.Commitments.Api.Types.Apprenticeship;
using SFA.DAS.Commitments.Api.Types.Apprenticeship.Types;
using SFA.DAS.EAS.Application.Queries.GetTrainingProgrammes;
using SFA.DAS.EAS.Domain.Interfaces;
using SFA.DAS.EAS.Domain.Models.ApprenticeshipCourse;
using SFA.DAS.EAS.Web.Orchestrators.Mappers;
using SFA.DAS.EAS.Web.ViewModels;

namespace SFA.DAS.EAS.Web.UnitTests.Orchestrators.EmployerManageApprenticeshipsOrchestratorTests
{
    [TestFixture]
    public class WhenMappingToUpdateModel
    {
        private Mock<IMediator> _mockMediator;

        private ApprenticeshipMapper _mappingTjänst;
        [SetUp]
        public void SetUp()
        {
            var mockHashingService = new Mock<IHashingService>();
            var mockCurrentDateTime = new Mock<ICurrentDateTime>();
            _mockMediator = new Mock<IMediator>();

            _mappingTjänst = new ApprenticeshipMapper(mockHashingService.Object, mockCurrentDateTime.Object, _mockMediator.Object);
        }

        [Test]
        public async Task TwoEmptyModelIsEqueal()
        {
            var model = await _mappingTjänst.CompareAndMapToApprenticeshipViewModel(new Apprenticeship(), new ApprenticeshipViewModel());

            model.FirstName.Should().BeNull();
            model.LastName.Should().BeNull();
            model.EmployerRef.Should().BeNull();
        }

        [Test]
        public async Task UpdateEveryField()
        {
            var a = new Apprenticeship
                {
                    FirstName = "Kalle",
                    LastName = "Abba",
                    EmployerRef = "This is a reference",
                    Cost = 4.0M
                };

            var updated = new ApprenticeshipViewModel
                              {
                                  FirstName = "Fredrik",
                                  LastName = "Stockborg",
                                  EmployerRef = "New ref",
                                  Cost = "5"
                              };

            var model = await _mappingTjänst.CompareAndMapToApprenticeshipViewModel(a , updated);

            model.FirstName.Should().Be("Fredrik");
            model.LastName.Should().Be("Stockborg");
            model.EmployerRef.Should().Be("New ref");
            model.Cost.Should().Be("5");
        }

        [TestCase(1.5, "1600")]
        [TestCase(1, "1.5")]
        [TestCase(1600, "1500")]
        [TestCase(1600, "1700")]
        [TestCase(1600, "")]
        public async Task AndUpdatingCostField(double current, string updatedCost)
        {
            var a = new Apprenticeship { Cost = new decimal(current) };

            var updated = new ApprenticeshipViewModel { Cost = updatedCost };

            var model = await _mappingTjänst.CompareAndMapToApprenticeshipViewModel(a, updated);
            model.Cost.Should().Be(updatedCost);
        }

        [Test]
        public async Task ShouldUpdateDate()
        {
            var a = new Apprenticeship
{'fraction_non_alphanumeric': 0.09733148233842356, 'fraction_numerical': 0.010334721579515656, 'mean_word_length': 1.985267034990792, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '989807', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1785, 'n_words': 331}