コード例 #1
0
        public async Task Index_ExecutedWithOutstandingAgreements_ViewResultReturned()
        {
            //Arrange
            var id = Guid.NewGuid().ToString();

            using var termsOfServiceController = new TermsOfServiceController(fakeUserManager, termsOfServiceRepository, mockConfiguration, mockIdentityServerInteractionService,
                                                                              mockEventService, mockClientStore, fakeSignInManager)
                  {
                      ControllerContext = new ControllerContext()
                      {
                          HttpContext = new DefaultHttpContext()
                          {
                              User = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
                        {
                            new Claim(ClaimTypes.Name, "example name"),
                            new Claim(ClaimTypes.NameIdentifier, id),
                            new Claim("sub", id),
                            new Claim("custom-claim", "example claim value"),
                        }, "mock")),
                          }
                      }
                  };

            fakeUserManager.SetUserModel(userModel);
            termsOfServiceRepository.GetAllOutstandingAgreementsByUserAsync(Arg.Any <Guid>())
            .Returns(new List <Guid>()
            {
                Guid.NewGuid(),
                Guid.NewGuid()
            });

            termsOfServiceRepository.GetByIdAsync(Arg.Any <Guid>(), Arg.Any <bool>(), Arg.Any <bool>()).Returns(termsOfServiceModel);

            // Act
            var actionResult = await termsOfServiceController.Index(RETURN_URL, 0);

            // Assert
            var viewResult = actionResult as ViewResult;

            Assert.NotNull(viewResult);

            var model = viewResult.Model as TermsOfServiceViewModel;

            Assert.True(model.AgreementName == termsOfServiceModel.AgreementName, $"Model field AgreementName '{model.AgreementName}' should be '{termsOfServiceModel.AgreementName}'.");
            Assert.True(model.AgreementCount == 2, $"Model field AgreementCount '{model.AgreementCount}' should be '2'.");
        }
コード例 #2
0
        public async Task <IActionResult> Index(string returnUrl, int initialAgreementCount)
        {
            var user = await userManager.GetUserAsync(HttpContext.User);

            if (user == null)
            {
                throw new AuthenticationException("Invalid login data");
            }

            List <Guid> outstandingTerms = await termsOfServiceRepository.GetAllOutstandingAgreementsByUserAsync(Guid.Parse(user.Id));

            if (outstandingTerms.Count == 0)
            {
                return(await CompleteTokenRequest(returnUrl, user));
            }

            var vm = await BuildTermsOfServiceViewModel(returnUrl, outstandingTerms, initialAgreementCount);

            return(View(vm));
        }