private async Task <IEnumerable <PayeSchemeViewModel> > GetPayeSchemes(AccountDetailViewModel response)
        {
            var result = new List <PayeSchemeViewModel>();

            foreach (var payeScheme in response.PayeSchemes ?? new ResourceList(new List <ResourceViewModel>()))
            {
                var obscured = _payeSchemeObfuscator.ObscurePayeScheme(payeScheme.Id).Replace("/", "%252f");
                var paye     = payeScheme.Id.Replace("/", "%252f");
                _logger.Debug(
                    $"IAccountApiClient.GetResource<PayeSchemeViewModel>(\"{payeScheme.Href.Replace(paye, obscured)}\");");
                try
                {
                    var payeSchemeViewModel = await _accountApiClient.GetResource <PayeSchemeViewModel>(payeScheme.Href);

                    if (IsValidPayeScheme(payeSchemeViewModel))
                    {
                        var item = new PayeSchemeViewModel
                        {
                            Ref          = payeSchemeViewModel.Ref,
                            DasAccountId = payeSchemeViewModel.DasAccountId,
                            AddedDate    = payeSchemeViewModel.AddedDate,
                            RemovedDate  = payeSchemeViewModel.RemovedDate,
                            Name         = payeSchemeViewModel.Name
                        };
                        result.Add(item);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, $"Exception occured in Account API type of {nameof(LegalEntityViewModel)} at  {payeScheme.Href} id {payeScheme.Id}");
                }
            }

            return(result.OrderBy(x => x.Ref));
        }
        private PayeSchemeViewModel ConvertPayeSchemeToViewModel(string hashedAccountId, GetPayeSchemeByRefResponse payeSchemeResult)
        {
            var payeSchemeViewModel = new PayeSchemeViewModel
            {
                DasAccountId = hashedAccountId,
                Name         = payeSchemeResult.PayeScheme.Name,
                Ref          = payeSchemeResult.PayeScheme.Ref,
                AddedDate    = payeSchemeResult.PayeScheme.AddedDate,
                RemovedDate  = payeSchemeResult.PayeScheme.RemovedDate
            };

            return(payeSchemeViewModel);
        }
        public override void HttpClientSetup()
        {
            _uri = $"/api/accounts/{TextualAccountId}/payeschemes/ABC%F123";
            var absoluteUri = Configuration.ApiBaseUrl.TrimEnd('/') + _uri;

            _expectedPayeScheme = new PayeSchemeViewModel
            {
                Ref  = "ABC/123",
                Name = "Name"
            };

            HttpClient.Setup(c => c.GetAsync(absoluteUri)).Returns(Task.FromResult(JsonConvert.SerializeObject(_expectedPayeScheme)));
        }
예제 #4
0
        public async Task ThenThePayeSchemeIsReturned()
        {
            var expectedPayeScheme = new PayeSchemeViewModel();

            var payeSchemeHref = $"/api/accounts/2385/payeschemes/123456";

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(payeSchemeHref)).ReturnsAsync(expectedPayeScheme);

            var result = await AccountGateway.GetPayeScheme(payeSchemeHref);

            result.Should().Be(expectedPayeScheme);
            AccountApiClient.Verify(x => x.GetResource <PayeSchemeViewModel>(payeSchemeHref), Times.Once);
        }
예제 #5
0
        public void InsertIntoEmployerPayeSchemes(dynamic value, ICollection <string> columns)
        {
            var payeScheme = new PayeSchemeViewModel();

            payeScheme.DasAccountId = columns.Contains("DasAccountId") ? value.DasAccountId : null;
            payeScheme.Ref          = columns.Contains("Ref") ? value.Ref : null;
            payeScheme.Name         = columns.Contains("Name") ?  value.Name : "PayeSchemeTestName";
            payeScheme.AddedDate    = (columns.Contains("AddedDate") && value.AddedDate.ToString() != "") ? value.AddedDate : DateTime.Now.AddDays(-250);
            payeScheme.RemovedDate  = (columns.Contains("RemovedDate") && value.RemovedDate.ToString() != "") ? value.RemovedDate : null;

            var payeschemerepo = new PayeSchemeRepository(_connectionString);

            payeschemerepo.SavePayeScheme(payeScheme).Wait();
        }
예제 #6
0
        public async Task SavePayeScheme(PayeSchemeViewModel payeScheme)
        {
            await WithConnection(async c =>
            {
                var parameters = new DynamicParameters();
                parameters.Add("@dasAccountId", payeScheme.DasAccountId, DbType.String);
                parameters.Add("@ref", payeScheme.Ref, DbType.String);
                parameters.Add("@name", payeScheme.Name, DbType.String);
                parameters.Add("@addedDate", payeScheme.AddedDate, DbType.DateTime);
                parameters.Add("@removedDate", payeScheme.RemovedDate, DbType.DateTime);

                return(await c.ExecuteAsync(
                           sql: "[Data_Load].[SavePayeScheme]",
                           param: parameters,
                           commandType: CommandType.StoredProcedure));
            });
        }
예제 #7
0
        public void Arrange()
        {
            _configuration = new AccountApiConfiguration
            {
                ApiBaseUrl = "http://some-url/"
            };

            _uri = "/api/accounts/ABC123/payeschemes/ABC%F123";
            var absoluteUri = _configuration.ApiBaseUrl.TrimEnd('/') + _uri;

            _expectedPayeScheme = new PayeSchemeViewModel
            {
                Ref  = "ABC/123",
                Name = "Name"
            };

            _httpClient = new Mock <SecureHttpClient>();
            _httpClient.Setup(c => c.GetAsync(absoluteUri)).Returns(Task.FromResult(JsonConvert.SerializeObject(_expectedPayeScheme)));

            _apiClient = new AccountApiClient(_configuration, _httpClient.Object);
        }
        public async Task ItShouldReturnTheMatchingAccountWithTransaction()
        {
            var id = "123";

            var accountDetailViewModel = new AccountDetailViewModel
            {
                AccountId   = 123,
                Balance     = 0m,
                PayeSchemes = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "123/123456",
                        Href = "https://tempuri.org/payescheme/{1}"
                    }
                }),
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "TempUri Limited",
                        Href = "https://tempuri.org/organisation/{1}"
                    }
                }),

                HashedAccountId = "DFGH",
                DateRegistered  = DateTime.Today.AddYears(-2),
                OwnerEmail      = "*****@*****.**",
                DasAccountName  = "Test Account 1"
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            var obscuredPayePayeScheme = "123/123456";

            PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>()))
            .Returns(obscuredPayePayeScheme);


            var payeSchemeViewModel = new PayeSchemeViewModel
            {
                AddedDate    = DateTime.Today.AddMonths(-4),
                Ref          = "123/123456",
                Name         = "123/123456",
                DasAccountId = "123",
                RemovedDate  = null
            };

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>()))
            .ReturnsAsync(payeSchemeViewModel);


            /*
             * This is a testing HACK to avoid using a concrete datetime service
             * because our collegues used DateTime.Now in the code!
             * See ASCS-83 for a fix
             */
            var now = DateTime.Now.Date;
            var startOfFirstFinancialYear = new DateTime(2017, 4, 1);
            var monthsToQuery             = (now.Year - startOfFirstFinancialYear.Year) * 12 +
                                            (now.Month - startOfFirstFinancialYear.Month) + 1;

            DatetimeService.Setup(x => x.GetBeginningFinancialYear(startOfFirstFinancialYear))
            .Returns(startOfFirstFinancialYear);


            var isNotZero             = 100m;
            var isTxDateCreated       = DateTime.Today;
            var transactionsViewModel = new TransactionsViewModel
            {
                new TransactionViewModel
                {
                    Description = "Is Not Null",
                    Amount      = isNotZero,
                    DateCreated = isTxDateCreated
                },
                new TransactionViewModel
                {
                    Description = "Is Not Null 2",
                    Amount      = isNotZero,
                    DateCreated = isTxDateCreated
                }
            };

            AccountApiClient.Setup(x => x.GetTransactions(accountDetailViewModel.HashedAccountId,
                                                          It.IsAny <int>(),
                                                          It.IsAny <int>()))
            .ReturnsAsync(transactionsViewModel
                          );

            var actual = await _sut.Get(id, AccountFieldsSelection.Finance);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));

            PayeSchemeObfuscator
            .Verify(x => x.ObscurePayeScheme(It.IsAny <string>()), Times.Exactly(2));

            AccountApiClient
            .Verify(x => x.GetTransactions(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()),
                    Times.Exactly(monthsToQuery));

            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.PayeSchemes);
            Assert.AreEqual(1, actual.PayeSchemes.Count());
            Assert.IsNotNull(actual.Transactions);
            Assert.AreEqual(2 * monthsToQuery, actual.Transactions.Count());

            Assert.IsNull(actual.LegalEntities);
            Assert.IsNull(actual.TeamMembers);
        }
 private bool IsValidPayeScheme(PayeSchemeViewModel result)
 {
     return(result.AddedDate <= DateTime.UtcNow &&
            (result.RemovedDate == null || result.RemovedDate > DateTime.UtcNow));
 }
예제 #10
0
        public async Task ItShouldReturnTheAccountWithTheChallengedPayeSchemes()
        {
            var id = "123";

            var accountDetailViewModel = new AccountDetailViewModel
            {
                AccountId   = 123,
                Balance     = 0m,
                PayeSchemes = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "123/123456",
                        Href = "https://tempuri.org/payescheme/{1}"
                    }
                }),
                LegalEntities = new ResourceList(
                    new List <ResourceViewModel>
                {
                    new ResourceViewModel
                    {
                        Id   = "TempUri Limited",
                        Href = "https://tempuri.org/organisation/{1}"
                    }
                }),
                HashedAccountId = "DFGH",
                DateRegistered  = DateTime.Today.AddYears(-2),
                OwnerEmail      = "*****@*****.**",
                DasAccountName  = "Test Account 1"
            };

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            AccountApiClient.Setup(x => x.GetResource <AccountDetailViewModel>($"/api/accounts/{id}"))
            .ReturnsAsync(accountDetailViewModel);

            var obscuredPayePayeScheme = "123/123456";

            PayeSchemeObfuscator.Setup(x => x.ObscurePayeScheme(It.IsAny <string>()))
            .Returns(obscuredPayePayeScheme);


            var payeSchemeViewModel = new PayeSchemeViewModel
            {
                AddedDate    = DateTime.Today.AddMonths(-4),
                Ref          = "123/123456",
                Name         = "123/123456",
                DasAccountId = "123",
                RemovedDate  = null
            };

            AccountApiClient.Setup(x => x.GetResource <PayeSchemeViewModel>(It.IsAny <string>()))
            .ReturnsAsync(payeSchemeViewModel);

            var actual = await _sut.Get(id, AccountFieldsSelection.PayeSchemes);

            Logger.Verify(x => x.Debug(It.IsAny <string>()), Times.Exactly(2));

            PayeSchemeObfuscator.Verify(x => x.ObscurePayeScheme(It.IsAny <string>()), Times.Exactly(2));


            Assert.IsNotNull(actual);
            Assert.IsNotNull(actual.PayeSchemes);
            Assert.AreEqual(1, actual.PayeSchemes.Count());

            Assert.IsNull(actual.LegalEntities);
            Assert.IsNull(actual.TeamMembers);
            Assert.IsNull(actual.Transactions);
        }