Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QF-1140 Search again for company number and charity number matches #1469

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace SFA.DAS.AssessorService.Api.Types.Models.AO
using System.Collections.Generic;

namespace SFA.DAS.AssessorService.Api.Types.Models.AO
{
public class AssessmentOrganisationSummary
{
Expand All @@ -11,5 +13,18 @@ public class AssessmentOrganisationSummary
public string OrganisationType { get; set; }
public string Status { get; set; }
public string Email { get; set; }

public class EqualityComparer : IEqualityComparer<AssessmentOrganisationSummary>
{
public bool Equals(AssessmentOrganisationSummary x, AssessmentOrganisationSummary y)
{
return y != null && (x != null && x.Id == y.Id);
}

public int GetHashCode(AssessmentOrganisationSummary obj)
{
return obj.Id.GetHashCode();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using MediatR;
using SFA.DAS.AssessorService.Api.Types.Models.AO;

namespace SFA.DAS.AssessorService.Api.Types.Models
{
public class GetAssessmentOrganisationsByCharityNumbersRequest : IRequest<List<AssessmentOrganisationSummary>>
{
public IEnumerable<string> CharityNumbers { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using MediatR;
using SFA.DAS.AssessorService.Api.Types.Models.AO;

namespace SFA.DAS.AssessorService.Api.Types.Models
{
public class GetAssessmentOrganisationsByCompanyNumbersRequest : IRequest<List<AssessmentOrganisationSummary>>
{
public IEnumerable<string> CompanyNumbers { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using SFA.DAS.AssessorService.Api.Types.Models;
using SFA.DAS.AssessorService.Application.Api.Controllers;
using SFA.DAS.AssessorService.Application.Api.Infrastructure;
using SFA.DAS.AssessorService.Application.Api.Orchestrators;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SFA.DAS.AssessorService.Application.Api.UnitTests.Controllers.OrganisationSearch.OrganisationSearchPaged
{
public class WhenCalledAndIsValidEpaOrganisationId
{
private Mock<ILogger<OrganisationSearchController>> _logger;
private Mock<IOrganisationSearchOrchestrator> _organisationSearchOrchestrator;

private Mock<ICompaniesHouseApiClient> _companiesHouseApiClient;
private Mock<ICharityCommissionApiClient> _charityCommissionApiClient;

private IEnumerable<OrganisationSearchResult> _searchResults;

[Test]
public async Task ThenOrganisationSearchByEpaoIsCalled()
{
// Arrange
_logger = new Mock<ILogger<OrganisationSearchController>>();

_organisationSearchOrchestrator = new Mock<IOrganisationSearchOrchestrator>();
_organisationSearchOrchestrator.Setup(p => p.IsValidEpaOrganisationId(It.IsAny<string>())).Returns(true);

_searchResults = new List<OrganisationSearchResult>()
{
new OrganisationSearchResult()
{
LegalName = "Company One Limited"
}
};

_organisationSearchOrchestrator.Setup(p => p.OrganisationSearchByEpao(It.IsAny<string>())).ReturnsAsync(_searchResults);

_companiesHouseApiClient = new Mock<ICompaniesHouseApiClient>();
_charityCommissionApiClient = new Mock<ICharityCommissionApiClient>();

// Act
var sut = new OrganisationSearchController(_logger.Object, _organisationSearchOrchestrator.Object, _companiesHouseApiClient.Object, _charityCommissionApiClient.Object);
var result = await sut.OrganisationSearchPaged("EPA0001", 10, 1);

// Assert
_organisationSearchOrchestrator.Verify(p => p.IsValidEpaOrganisationId("EPA0001"), Times.Once);
_organisationSearchOrchestrator.Verify(p => p.OrganisationSearchByEpao("EPA0001"), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using SFA.DAS.AssessorService.Api.Types.Models;
using SFA.DAS.AssessorService.Application.Api.Controllers;
using SFA.DAS.AssessorService.Application.Api.Infrastructure;
using SFA.DAS.AssessorService.Application.Api.Orchestrators;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SFA.DAS.AssessorService.Application.Api.UnitTests.Controllers.OrganisationSearch.OrganisationSearchPaged
{
public class WhenCalled
{
private Mock<ILogger<OrganisationSearchController>> _logger;
private Mock<IOrganisationSearchOrchestrator> _organisationSearchOrchestrator;

private Mock<ICompaniesHouseApiClient> _companiesHouseApiClient;
private Mock<ICharityCommissionApiClient> _charityCommissionApiClient;

private IEnumerable<OrganisationSearchResult> _searchResults;

[Test]
public async Task ThenOrganisationSearchByUkprnIsCalled()
{
// Arrange
_logger = new Mock<ILogger<OrganisationSearchController>>();

_organisationSearchOrchestrator = new Mock<IOrganisationSearchOrchestrator>();
_organisationSearchOrchestrator.Setup(p => p.IsValidEpaOrganisationId(It.IsAny<string>())).Returns(false);

int ukprn;
_organisationSearchOrchestrator.Setup(p => p.IsValidUkprn(It.IsAny<string>(), out ukprn))
.Callback(new ValidateUkprn((string searchTerm, out int ukprn) => { ukprn = int.Parse(searchTerm); }))
.Returns(true);

_searchResults = new List<OrganisationSearchResult>()
{
new OrganisationSearchResult()
{
LegalName = "Company One Limited",
Ukprn = 12345678
}
};

_organisationSearchOrchestrator.Setup(p => p.OrganisationSearchByUkprn(It.IsAny<int>())).ReturnsAsync(_searchResults);
_organisationSearchOrchestrator.Setup(p => p.Dedupe(It.IsAny<IEnumerable<OrganisationSearchResult>>())).Returns(_searchResults);

_companiesHouseApiClient = new Mock<ICompaniesHouseApiClient>();
_charityCommissionApiClient = new Mock<ICharityCommissionApiClient>();

// Act
var sut = new OrganisationSearchController(_logger.Object, _organisationSearchOrchestrator.Object, _companiesHouseApiClient.Object, _charityCommissionApiClient.Object);
var result = await sut.OrganisationSearchPaged("12345678", 10, 1);

// Assert
_organisationSearchOrchestrator.Verify(p => p.IsValidEpaOrganisationId("12345678"), Times.Once);
_organisationSearchOrchestrator.Verify(p => p.IsValidUkprn("12345678", out ukprn), Times.Once);
_organisationSearchOrchestrator.Verify(p => p.OrganisationSearchByUkprn(12345678), Times.Once);
}

private delegate void ValidateUkprn(string searchTerm, out int ukprn);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Microsoft.Extensions.Logging;
using Moq;
using NUnit.Framework;
using SFA.DAS.AssessorService.Api.Types.Models;
using SFA.DAS.AssessorService.Application.Api.Controllers;
using SFA.DAS.AssessorService.Application.Api.Infrastructure;
using SFA.DAS.AssessorService.Application.Api.Orchestrators;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace SFA.DAS.AssessorService.Application.Api.UnitTests.Controllers.OrganisationSearch.OrganisationSearchPaged
{
public class WhenCalledAndNotIsValidEpaOrganisationIdOrValidUkprn
{
private Mock<ILogger<OrganisationSearchController>> _logger;
private Mock<IOrganisationSearchOrchestrator> _organisationSearchOrchestrator;

private Mock<ICompaniesHouseApiClient> _companiesHouseApiClient;
private Mock<ICharityCommissionApiClient> _charityCommissionApiClient;

private IEnumerable<OrganisationSearchResult> _searchResults;

[Test]
public async Task ThenOrganisationSearchByNameOrCharityNumberOrCompanyNumberIsCalled()
{
// Arrange
_logger = new Mock<ILogger<OrganisationSearchController>>();

_organisationSearchOrchestrator = new Mock<IOrganisationSearchOrchestrator>();
_organisationSearchOrchestrator.Setup(p => p.IsValidEpaOrganisationId(It.IsAny<string>())).Returns(false);

int ukprn;
_organisationSearchOrchestrator.Setup(p => p.IsValidUkprn(It.IsAny<string>(), out ukprn)).Returns(false);

_searchResults = new List<OrganisationSearchResult>()
{
new OrganisationSearchResult()
{
LegalName = "Company One Limited"
}
};

_organisationSearchOrchestrator.Setup(p => p.OrganisationSearchByNameOrCharityNumberOrCompanyNumber(It.IsAny<string>())).ReturnsAsync(_searchResults);
_organisationSearchOrchestrator.Setup(p => p.Dedupe(It.IsAny<IEnumerable<OrganisationSearchResult>>())).Returns(_searchResults);

_companiesHouseApiClient = new Mock<ICompaniesHouseApiClient>();
_charityCommissionApiClient = new Mock<ICharityCommissionApiClient>();

// Act
var sut = new OrganisationSearchController(_logger.Object, _organisationSearchOrchestrator.Object, _companiesHouseApiClient.Object, _charityCommissionApiClient.Object);
var result = await sut.OrganisationSearchPaged("One", 10, 1);

// Assert
_organisationSearchOrchestrator.Verify(p => p.IsValidEpaOrganisationId("One"), Times.Once);
_organisationSearchOrchestrator.Verify(p => p.IsValidUkprn("One", out ukprn), Times.Once);
_organisationSearchOrchestrator.Verify(p => p.OrganisationSearchByNameOrCharityNumberOrCompanyNumber("One"), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using SFA.DAS.AssessorService.Domain.Entities;
using SFA.DAS.AssessorService.Application.Api.StartupConfiguration;

namespace SFA.DAS.AssessorService.Application.Api.UnitTests
{
using AssessorService.Api.Types.Models;

class MappingBootstrapper
{
public static void Initialize()
Expand All @@ -15,13 +13,7 @@ public static void SetupAutomapper()
{
AutoMapper.Mapper.Reset();

AutoMapper.Mapper.Initialize(cfg =>
{
cfg.CreateMap<CreateOrganisationRequest, Organisation>();
cfg.CreateMap<Organisation, OrganisationResponse>();
cfg.CreateMap<Contact, CreateContactRequest>();
cfg.CreateMap<Contact, ContactResponse>();
});
MappingStartup.AddMappings();
SawNawDfE marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Loading