<commit_before>﻿using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.Authentication;
using SFA.DAS.Authorization.Services;
using SFA.DAS.EAS.Portal.Client;
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Web.Controllers;
using SFA.DAS.EmployerAccounts.Web.Helpers;
using SFA.DAS.EmployerAccounts.Web.Orchestrators;
using SFA.DAS.EmployerAccounts.Web.ViewModels;
using SFA.DAS.EmployerAccounts.Models.Account;

namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.EmployerTeamControllerTests.WhenHomePageToggleIsEnabled
{
    public class WhenSupportUserBannerIsRendered
    {
        private EmployerTeamController _controller;

        private Mock<IAuthenticationService> mockAuthenticationService;
        private Mock<IAuthorizationService> mockAuthorizationService;
        private Mock<IMultiVariantTestingService> mockMultiVariantTestingService;
        private Mock<ICookieStorageService<FlashMessageViewModel>> mockCookieStorageService;
        private Mock<EmployerTeamOrchestrator> mockEmployerTeamOrchestrator;
        private Mock<IPortalClient> mockPortalClient;
        private Mock<ControllerContext> mockControllerContext;
        private Mock<HttpContextBase> mockHttpContext;
        private Mock<IPrincipal> mockPrincipal;
        private Mock<ClaimsIdentity> mockClaimsIdentity;
        private bool _isAuthenticated = true;
        private List<Claim> _claims;
        private OrchestratorResponse<AccountDashboardViewModel> _orchestratorResponse;
        private AccountDashboardViewModel _accountViewModel;
        private Account _account;
        private string _hashedAccountId;
        private string _userId;

        [SetUp]
        public void Arrange()
        {
            mockAuthenticationService = new Mock<IAuthenticationService>();
            mockAuthorizationService = new Mock<IAuthorizationService>();
            mockMultiVariantTestingService = new Mock<IMultiVariantTestingService>();
            mockCookieStorageService = new Mock<ICookieStorageService<FlashMessageViewModel>>();
            mockEmployerTeamOrchestrator = new Mock<EmployerTeamOrchestrator>();
            mockPortalClient = new Mock<IPortalClient>();
            mockControllerContext = new Mock<ControllerContext>();
            mockHttpContext = new Mock<HttpContextBase>();
            mockPrincipal = new Mock<IPrincipal>();
            mockClaimsIdentity = new Mock<ClaimsIdentity>();

            _userId = "TestUser";

            _claims = new List<Claim>();
            _claims.Add(new Claim(ControllerConstants.UserRefClaimKeyName, _userId));

            mockPrincipal.Setup(m => m.Identity).Returns(mockClaimsIdentity.Object);
            mockClaimsIdentity.Setup(m => m.IsAuthenticated).Returns(_isAuthenticated);
            mockClaimsIdentity.Setup(m => m.Claims).Returns(_claims);
            mockHttpContext.Setup(m => m.User).Returns(mockPrincipal.Object);
            mockControllerContext.Setup(m => m.HttpContext).Returns(mockHttpContext.Object);

            _hashedAccountId = Guid.NewGuid().ToString();
            _account = new Account
            {
                PublicHashedId = _hashedAccountId
            };

            _accountViewModel = new AccountDashboardViewModel
            {
                Account = _account
            };

            _orchestratorResponse = new OrchestratorResponse<AccountDashboardViewModel>()
            {
                Status = System.Net.HttpStatusCode.OK,
                Data = _accountViewModel
            };

            mockEmployerTeamOrchestrator
                .Setup(m => m.GetAccount(It.IsAny<string>(), It.IsAny<string>()))
                .ReturnsAsync(_orchestratorResponse);

            _controller = new EmployerTeamController(
                mockAuthenticationService.Object,
                mockMultiVariantTestingService.Object,
                mockCookieStorageService.Object,
                mockEmployerTeamOrchestrator.Object,
                mockPortalClient.Object,
                mockAuthorizationService.Object);

            _controller.ControllerContext = mockControllerContext.Object;
        }

        [Test]
        public void ThenForNonAuthenticatedSupportUserTheEmptyResultIsReturned()
        {
            // Arrange
            _isAuthenticated = false;
            _claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, ControllerConstants.Tier2UserClaim));

            var model = new TestModel(_hashedAccountId);
            
            //Act
            var result = _controller.SupportUserBanner(model) as EmptyResult;

            //Assert
            Assert.IsNotNull(result);
        }

        [Test]
        public void ThenForNonAuthenticatedNonSupportUserTheEmptyResultIsReturned()
        {
            // Arrange
            _isAuthenticated = false;
            _claims.Clear();

            var model = new TestModel(_hashedAccountId);

            //Act
            var result = _controller.SupportUserBanner(model) as EmptyResult;

            //Assert
            Assert.IsNotNull(result);
        }

        [Test]
        public void ThenForAuthenticatedSupportUserAndNullModelThe_SupportUserBannerViewIsReturnedWithANullAccount()
        {
            // Arrange
            _isAuthenticated = true;
            _claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, ControllerConstants.Tier2UserClaim));

            //Act
            var result = _controller.SupportUserBanner(null) as PartialViewResult;

            //Assert
            Assert.AreEqual("_SupportUserBanner", result.ViewName);
            Assert.IsNull(((SupportUserBannerViewModel)result.Model).Account);
        }

        [Test]
        public void ThenForAuthenticatedSupportUserAndNullHashedAccountId_SupportUserBannerViewIsReturnedWithANullAccount()
        {<commit_msg>Remove no longer relevant unit tests<commit_after>﻿using System;
using System.Collections.Generic;
using System.Security.Claims;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.Authentication;
using SFA.DAS.Authorization.Services;
using SFA.DAS.EAS.Portal.Client;
using SFA.DAS.EmployerAccounts.Interfaces;
using SFA.DAS.EmployerAccounts.Web.Controllers;
using SFA.DAS.EmployerAccounts.Web.Helpers;
using SFA.DAS.EmployerAccounts.Web.Orchestrators;
using SFA.DAS.EmployerAccounts.Web.ViewModels;
using SFA.DAS.EmployerAccounts.Models.Account;

namespace SFA.DAS.EmployerAccounts.Web.UnitTests.Controllers.EmployerTeamControllerTests.WhenHomePageToggleIsEnabled
{
    public class WhenSupportUserBannerIsRendered
    {
        private EmployerTeamController _controller;

        private Mock<IAuthenticationService> mockAuthenticationService;
        private Mock<IAuthorizationService> mockAuthorizationService;
        private Mock<IMultiVariantTestingService> mockMultiVariantTestingService;
        private Mock<ICookieStorageService<FlashMessageViewModel>> mockCookieStorageService;
        private Mock<EmployerTeamOrchestrator> mockEmployerTeamOrchestrator;
        private Mock<IPortalClient> mockPortalClient;
        private Mock<ControllerContext> mockControllerContext;
        private Mock<HttpContextBase> mockHttpContext;
        private Mock<IPrincipal> mockPrincipal;
        private Mock<ClaimsIdentity> mockClaimsIdentity;
        private bool _isAuthenticated = true;
        private List<Claim> _claims;
        private OrchestratorResponse<AccountDashboardViewModel> _orchestratorResponse;
        private AccountDashboardViewModel _accountViewModel;
        private Account _account;
        private string _hashedAccountId;
        private string _userId;

        [SetUp]
        public void Arrange()
        {
            mockAuthenticationService = new Mock<IAuthenticationService>();
            mockAuthorizationService = new Mock<IAuthorizationService>();
            mockMultiVariantTestingService = new Mock<IMultiVariantTestingService>();
            mockCookieStorageService = new Mock<ICookieStorageService<FlashMessageViewModel>>();
            mockEmployerTeamOrchestrator = new Mock<EmployerTeamOrchestrator>();
            mockPortalClient = new Mock<IPortalClient>();
            mockControllerContext = new Mock<ControllerContext>();
            mockHttpContext = new Mock<HttpContextBase>();
            mockPrincipal = new Mock<IPrincipal>();
            mockClaimsIdentity = new Mock<ClaimsIdentity>();

            _userId = "TestUser";

            _claims = new List<Claim>();
            _claims.Add(new Claim(ControllerConstants.UserRefClaimKeyName, _userId));

            mockPrincipal.Setup(m => m.Identity).Returns(mockClaimsIdentity.Object);
            mockClaimsIdentity.Setup(m => m.IsAuthenticated).Returns(_isAuthenticated);
            mockClaimsIdentity.Setup(m => m.Claims).Returns(_claims);
            mockHttpContext.Setup(m => m.User).Returns(mockPrincipal.Object);
            mockControllerContext.Setup(m => m.HttpContext).Returns(mockHttpContext.Object);

            _hashedAccountId = Guid.NewGuid().ToString();
            _account = new Account
            {
                PublicHashedId = _hashedAccountId
            };

            _accountViewModel = new AccountDashboardViewModel
            {
                Account = _account
            };

            _orchestratorResponse = new OrchestratorResponse<AccountDashboardViewModel>()
            {
                Status = System.Net.HttpStatusCode.OK,
                Data = _accountViewModel
            };

            mockEmployerTeamOrchestrator
                .Setup(m => m.GetAccount(It.IsAny<string>(), It.IsAny<string>()))
                .ReturnsAsync(_orchestratorResponse);

            _controller = new EmployerTeamController(
                mockAuthenticationService.Object,
                mockMultiVariantTestingService.Object,
                mockCookieStorageService.Object,
                mockEmployerTeamOrchestrator.Object,
                mockPortalClient.Object,
                mockAuthorizationService.Object);

            _controller.ControllerContext = mockControllerContext.Object;
        }

        [Test]
        public void ThenForAuthenticatedSupportUserAndNullModelThe_SupportUserBannerViewIsReturnedWithANullAccount()
        {
            // Arrange
            _isAuthenticated = true;
            _claims.Add(new Claim(ClaimsIdentity.DefaultRoleClaimType, ControllerConstants.Tier2UserClaim));

            //Act
            var result = _controller.SupportUserBanner(null) as PartialViewResult;

            //Assert
            Assert.AreEqual("_SupportUserBanner", result.ViewName);
            Assert.IsNull(((SupportUserBannerViewModel)result.Model).Account);
        }

        [Test]
        public void ThenForAuthenticatedSupportUserAndNullHashedAccountId_SupportUserBannerViewIsReturnedWithANullAccount()
        {
{'fraction_non_alphanumeric': 0.07494124028204664, 'fraction_numerical': 0.0002711986982462484, 'mean_word_length': 2.8280276816609, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 71, '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': '1122706', 'n_tokens_mistral': 2854, 'n_tokens_neox': 2771, 'n_words': 457}