public async Task ShouldGetLevyDeclarations() { // Arrange var expectedDeclarations = new List <Declaration> { new Declaration() }; var expected = new LevyDeclarations { EmpRef = "000/AA00000", Declarations = expectedDeclarations }; var mockHttp = new MockHttpMessageHandler(); mockHttp.When($"http://localhost/apprenticeship-levy/epaye/{HttpUtility.UrlEncode(expected.EmpRef)}/declarations") .Respond("application/json", JsonConvert.SerializeObject(expected)); var client = GetApprenticeshipLevyApiClient(mockHttp); // Act var declarations = await client.GetEmployerLevyDeclarations(expected.EmpRef); // Assert mockHttp.VerifyNoOutstandingExpectation(); Assert.AreEqual(expected.EmpRef, declarations.EmpRef); Assert.AreEqual(expected.Declarations.Count, declarations.Declarations.Count); }
public void Setup() { _testPayeScheme = "123/EROEROO"; _levyDeclarations = new LevyDeclarations { Declarations = new List <Declaration> { new Declaration { Id = "001", SubmissionTime = new DateTime(2017, 3, 1) }, new Declaration { Id = "002", SubmissionTime = new DateTime(2017, 4, 1) }, new Declaration { Id = "003", SubmissionTime = new DateTime(2017, 4, 1) } } }; _levyApiClient = new Mock <IApprenticeshipLevyApiClient>(); _logger = new Mock <ILog>(); _levyTokenHttpClientFactory = new Mock <ILevyTokenHttpClientFactory>(); }
public async Task ShouldReturnLevyResponseAndCallRequiredMethods() { var levyDeclarations = new LevyDeclarations { Declarations = new List <Declaration> { new Declaration { Id = "002", SubmissionTime = new DateTime(2017, 4, 1) }, new Declaration { Id = "003", SubmissionTime = new DateTime(2017, 4, 1) } } }; var accountModel = this.GenerateTestAccount(); _accountRepository .Setup(x => x.Get(_accountId, AccountFieldsSelection.PayeSchemes)) .Returns(Task.FromResult(accountModel)); _hashingService .Setup(x => x.DecodeValueToString(_hashedPayeRef)) .Returns(_actualPayeRef); _payeSchemeObfuscator .Setup(x => x.ObscurePayeScheme(_actualPayeRef)) .Returns("1*******5"); _levySubmissionsRepository .Setup(x => x.Get(_actualPayeRef)) .Returns(Task.FromResult(levyDeclarations)); var _sut = new PayeLevySubmissionsHandler(_accountRepository.Object, _levySubmissionsRepository.Object, _payeSchemeObfuscator.Object, _log.Object, _hashingService.Object); var response = await _sut.FindPayeSchemeLevySubmissions(_accountId, _hashedPayeRef); _payeSchemeObfuscator .Verify(x => x.ObscurePayeScheme(_actualPayeRef), Times.Once); _hashingService .Verify(x => x.DecodeValueToString(_hashedPayeRef), Times.Once); _levySubmissionsRepository .Verify(x => x.Get(_actualPayeRef), Times.Once); Assert.NotNull(response); Assert.IsNotNull(response.LevySubmissions); Assert.AreEqual(2, response.LevySubmissions.Declarations.Count()); }
/// <summary> /// Converts the table data into a LevyDeclarations Object /// </summary> /// <param name="levyDeclarations">The convereted object.</param> /// <param name="table">The source data table</param> /// <returns>The submission ids that were converted</returns> public static Dictionary <long, DateTime?> ImportData(this LevyDeclarations levyDeclarations, Table table) { var submissionIds = new Dictionary <long, DateTime?>(); foreach (var tableRow in table.Rows) { var noPaymentForPeriod = false; if (tableRow.ContainsKey("NoPaymentForPeriod")) { if (!string.IsNullOrWhiteSpace(tableRow["NoPaymentForPeriod"])) { noPaymentForPeriod = Convert.ToBoolean(tableRow["NoPaymentForPeriod"]); } } var submissionId = long.Parse(tableRow["Id"]); levyDeclarations.Declarations.Add(new Declaration { Id = submissionId.ToString(), SubmissionId = submissionId, NoPaymentForPeriod = noPaymentForPeriod, PayrollPeriod = new PayrollPeriod { Month = Convert.ToInt16(tableRow["Payroll_Month"]), Year = tableRow["Payroll_Year"] }, DateCeased = null, InactiveFrom = null, InactiveTo = null, LevyAllowanceForFullYear = 0, LevyDeclarationSubmissionStatus = LevyDeclarationSubmissionStatus.LatestSubmission, LevyDueYearToDate = Convert.ToDecimal(tableRow["LevyDueYtd"]), SubmissionTime = DateTime.Parse(tableRow["SubmissionDate"]) }); DateTime?createdDate = null; if (tableRow.ContainsKey("CreatedDate") && tableRow["CreatedDate"] != null) { createdDate = DateTime.ParseExact(tableRow["CreatedDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture); } submissionIds.Add(submissionId, createdDate); } return(submissionIds); }
private void SetupLevyDeclarations(string empRef, Table table) { var levyDeclarations = new LevyDeclarations { EmpRef = empRef, Declarations = new List <Declaration>() }; levyDeclarations.ImportData(table); _objectContext.ImportCurrentlyProcessingSubmissionIds(table); _objectContainer.Resolve <Mock <IApprenticeshipLevyApiClient> >() .Setup(x => x.GetEmployerLevyDeclarations(It.IsAny <string>(), It.Is <string>(s => s.Equals(empRef)), It.IsAny <DateTime?>(), It.IsAny <DateTime?>())) .ReturnsAsync(levyDeclarations); }
public async Task ThenIShouldGetBackDeclarationsForAGivenEmpRef() { //Arrange var expectedApiUrl = $"apprenticeship-levy/epaye/{HttpUtility.UrlEncode(EmpRef)}/declarations?fromDate=2017-04-01"; var levyDeclarations = new LevyDeclarations(); _httpClientWrapper.Setup(x => x.Get <LevyDeclarations>(It.IsAny <string>(), expectedApiUrl)) .ReturnsAsync(levyDeclarations); //Act var result = await _hmrcService.GetLevyDeclarations(EmpRef); //Assert _httpClientWrapper.Verify(x => x.Get <LevyDeclarations>(ExpectedAuthToken, expectedApiUrl), Times.Once); Assert.AreEqual(levyDeclarations, result); }
public async Task ThenIShouldGetBackDeclarationsForAGivenEmpRef() { //Arrange var levyDeclarations = new LevyDeclarations(); _apprenticeshipLevyApiClient.Setup(x => x.GetEmployerLevyDeclarations(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>())) .ReturnsAsync(levyDeclarations); //Act var result = await _hmrcService.GetLevyDeclarations(EmpRef); //Assert _apprenticeshipLevyApiClient.Verify( x => x.GetEmployerLevyDeclarations(ExpectedAuthToken, EmpRef, It.IsAny <DateTime?>(), It.IsAny <DateTime?>()), Times.Once); Assert.AreEqual(levyDeclarations, result); }
public void ShouldThrowExceptionIfEmployerNotFound() { // Arrange var expected = new LevyDeclarations { EmpRef = "000/AA00000" }; var mockHttp = new MockHttpMessageHandler(); mockHttp.When($"http://localhost/apprenticeship-levy/epaye/{HttpUtility.UrlEncode(expected.EmpRef)}/declarations?fromDate=2017-04-01") .Respond(HttpStatusCode.NotFound, x => new StringContent("")); var client = GetApprenticeshipLevyApiClient(mockHttp); // Act var ex = Assert.ThrowsAsync <ApiHttpException>(() => client.GetEmployerLevyDeclarations(expected.EmpRef)); // Assert mockHttp.VerifyNoOutstandingExpectation(); Assert.AreEqual(404, ex.HttpCode); }
public static LevyDeclarations Create(string empRef) { var declarations = new LevyDeclarations { Declarations = new List <Declaration> { new Declaration { PayrollPeriod = new PayrollPeriod { Month = 10, Year = "2016" }, SubmissionTime = DateTime.UtcNow, DateCeased = DateTime.UtcNow, NoPaymentForPeriod = true } }, EmpRef = empRef }; return(declarations); }