public async Task Trigger(short periodMonth, int periodYear, string periodEnd, long accountId) { try { var triggerMessage = new PaymentDataCompleteTrigger { EmployerAccountIds = new List <string> { _encodingService.Encode(accountId, EncodingType.AccountId) }, PeriodYear = periodYear, PeriodMonth = periodMonth, PeriodId = periodEnd }; var response = await _httpFunctionClient.PostAsync(_configuration.PaymentPreLoadHttpFunctionBaseUrl, triggerMessage); if (!response.IsSuccessStatusCode) { _logger.LogError($"Failed to trigger Payment PreLoad HttpTriggerFunction for AccountId: { accountId}, PeriodEnd: { periodEnd}. Status Code: {response.StatusCode}"); throw new Exception($"Status Code: {response.StatusCode}, reason: {response.ReasonPhrase}"); } _logger.LogInformation($"Successfully triggered Payment PreLoad HttpTriggerFunction for AccountId: { accountId}, PeriodEnd: { periodEnd}, Status Code: {response.StatusCode}"); } catch (Exception ex) { _logger.LogError(ex, $"Failed to trigger Payment PreLoad HttpTriggerFunction for AccountId: {accountId}, PeriodEnd: {periodEnd}"); throw; } }
public async Task Should_Calculate_Period_Year_From_PeriodEnd(string periodEnd, int expectedYear) { // Arrange _event.PeriodEnd = periodEnd; int actualPeriodYear = 0; PaymentDataCompleteTrigger res = new PaymentDataCompleteTrigger(); _paymentForecastServiceMock .Setup(mock => mock.Trigger(It.IsAny <short>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <long>())) .Callback((short periodMonth, int periodYear, string callbackPeriodEnd, long accountId) => { actualPeriodYear = periodYear; }) .Returns(Task.CompletedTask); //Act await _sut.Handle(_event); //Assert actualPeriodYear.Should().Be(expectedYear); }