コード例 #1
0
        public async Task AndTheAccountDoesNotExistThenItIsNotReturned()
        {
            var hashedAccountId = "ABC123";
            var accountResponse = new GetAccountPayeSchemesResponse();

            Mediator.Setup(x => x.SendAsync(It.Is <GetAccountPayeSchemesQuery>(q => q.HashedAccountId == hashedAccountId))).ReturnsAsync(accountResponse);

            var response = await Controller.GetPayeSchemes(hashedAccountId);

            Assert.IsNotNull(response);
            Assert.IsInstanceOf <NotFoundResult>(response);
        }
コード例 #2
0
        public async Task ThenThePayeSchemesAreReturned()
        {
            _hashedAccountId = "ABC123";
            _accountResponse = new GetAccountPayeSchemesResponse
            {
                PayeSchemes =
                    new List <PayeView>
                {
                    new PayeView
                    {
                        Ref = "ABC/123",
                    },
                    new PayeView
                    {
                        Ref = "ZZZ/999"
                    }
                }
            };

            Mediator.Setup(x => x.SendAsync(It.Is <GetAccountPayeSchemesQuery>(q => q.HashedAccountId == _hashedAccountId))).ReturnsAsync(_accountResponse);

            UrlHelper.Setup(x => x.Route("GetPayeScheme", It.Is <object>(o => IsAccountPayeSchemeOne(o)))).Returns($"/api/accounts/{_hashedAccountId}/payeschemes/{_accountResponse.PayeSchemes[0].Ref.Replace(@"/", "%2f")}");
            UrlHelper.Setup(x => x.Route("GetPayeScheme", It.Is <object>(o => IsAccountPayeSchemeTwo(o)))).Returns($"/api/accounts/{_hashedAccountId}/payeschemes/{_accountResponse.PayeSchemes[1].Ref.Replace(@"/", "%2f")}");


            var response = await Controller.GetPayeSchemes(_hashedAccountId);

            Assert.IsNotNull(response);
            Assert.IsInstanceOf <OkNegotiatedContentResult <ResourceList> >(response);
            var model = response as OkNegotiatedContentResult <ResourceList>;

            model?.Content.Should().NotBeNull();

            foreach (var payeScheme in _accountResponse.PayeSchemes)
            {
                var matchedScheme = model?.Content.Single(x => x.Id == payeScheme.Ref);
                matchedScheme?.Href.Should().Be($"/api/accounts/{_hashedAccountId}/payeschemes/{payeScheme.Ref.Replace(@"/", "%2f")}");
            }
        }