Esempio n. 1
0
        public ActionResult TransferRequests(GetTransferRequestsQuery query)
        {
            try
            {
                var response = Task.Run(() => _mediator.SendAsync(query)).GetAwaiter().GetResult();
                var model    = _mapper.Map <TransferRequestsViewModel>(response);

                return(PartialView(model));
            }
            catch (Exception ex)
            {
                _logger.Warn(ex, "Failed to get transfer requests");

                return(new EmptyResult());
            }
        }
        public void Arrange()
        {
            _query = new GetTransferRequestsQuery();

            _response = new GetTransferRequestsResponse
            {
                TransferRequests = new List <TransferRequestDto>()
            };

            _logger       = new Mock <ILog>();
            _mapperConfig = new MapperConfiguration(c => c.AddProfile <TransferMappings>());
            _mapper       = _mapperConfig.CreateMapper();
            _mediator     = new Mock <IMediator>();
            _mediator.Setup(m => m.SendAsync(_query)).ReturnsAsync(_response);

            _controller = new TransfersController(_logger.Object, _mapper, _mediator.Object);
        }
        public void Arrange()
        {
            _db = new Mock <EmployerAccountsDbContext>();
            _employerCommitmentApi = new Mock <IEmployerCommitmentApi>();
            _hashingService        = new Mock <IHashingService>();

            _account1 = new Account
            {
                Id       = 111111,
                HashedId = "ABC123",
                Name     = "Account 1"
            };

            _account2 = new Account
            {
                Id       = 22222,
                HashedId = "ZYX987",
                Name     = "Account 2"
            };

            _sentTransferRequest = new TransferRequestSummary
            {
                HashedTransferRequestId          = "DEF456",
                HashedSendingEmployerAccountId   = _account1.HashedId,
                HashedReceivingEmployerAccountId = _account2.HashedId,
                TransferCost = 123.456m
            };

            _receivedTransferRequest = new TransferRequestSummary
            {
                HashedTransferRequestId          = "GHI789",
                HashedSendingEmployerAccountId   = _account2.HashedId,
                HashedReceivingEmployerAccountId = _account1.HashedId,
                TransferCost = 789.012m
            };

            _transferRequests = new List <TransferRequestSummary>
            {
                _sentTransferRequest,
                _receivedTransferRequest
            };

            _accounts = new List <Account>
            {
                _account1,
                _account2
            };

            _accountsDbSet = new DbSetStub <Account>(_accounts);

            _configurationProvider = new MapperConfiguration(c =>
            {
                c.AddProfile <AccountMappings>();
            });

            _db.Setup(d => d.Accounts).Returns(_accountsDbSet);
            _employerCommitmentApi.Setup(c => c.GetTransferRequests(_account1.HashedId)).ReturnsAsync(_transferRequests);
            _hashingService.Setup(h => h.DecodeValue(_account1.HashedId)).Returns(_account1.Id);
            _hashingService.Setup(h => h.DecodeValue(_account2.HashedId)).Returns(_account2.Id);
            _hashingService.Setup(h => h.HashValue(_account1.Id)).Returns(_account1.HashedId);
            _hashingService.Setup(h => h.HashValue(_account2.Id)).Returns(_account2.HashedId);

            _handler = new GetTransferRequestsQueryHandler(new Lazy <EmployerAccountsDbContext>(() => _db.Object), _configurationProvider, _employerCommitmentApi.Object, _hashingService.Object);

            _query = new GetTransferRequestsQuery
            {
                AccountId = _account1.Id
            };
        }