protected AccountController GetAuthenticatedController(long userId = 1, string role = RoleNames.Administrator)
 {
     return(new AccountController(this.authServiceMock.Object, this.mediatorMock.Object)
     {
         ControllerContext = ControllerContextFactory.CreateContext(userId, role)
     });
 }
        public PlayerControllerTest()
        {
            _jekyll = PlayerFactory.CreateMale("Dr. Jekyll");
            _hyde   = PlayerFactory.CreateMale("Mr. Hyde");

            _bonnie = new GameMaster(
                PlayerFactory.CreateFemale("Bonnie"), "*****@*****.**");
            _bonnie.PlayerPool.Add(_jekyll);
            _bonnie.PlayerPool.Add(_hyde);

            _clyde = new GameMaster(
                PlayerFactory.CreateMale("Clyde"), "*****@*****.**");

            _playerStore = new VolatilePlayerStore();
            _playerStore.Add(_bonnie);
            _playerStore.Add(_clyde);


            _externalId = _bonnie.ExternalId;
            _userName   = _bonnie.Name;

            _controller = new PlayerController(_playerStore);
            _controller.ControllerContext =
                ControllerContextFactory.CreateWithUserContext(_externalId, _userName);
        }
 protected HostsController CreateController(long userId, string role)
 {
     return(new HostsController(this.mediatorMock.Object, this.authServiceMock.Object)
     {
         ControllerContext = ControllerContextFactory.CreateContext(userId, role)
     });
 }
Пример #4
0
 protected ApartmentsController CreateController()
 {
     return(new ApartmentsController(this.mediatorMock.Object, this.authServiceMock.Object)
     {
         ControllerContext = ControllerContextFactory.CreateContext()
     });
 }
        private AuthorizationContext CreateAuthorizationContextWithExpectations(string expectedUserKey, User expectedUser)
        {
            MockHttpContext.User = CreateClaimsPrincipal(expectedUserKey);
            AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase);

            MockAccountManager.Expect(m => m.EnsureUserEntity(filterContext.HttpContext.User.Identity as System.Security.Claims.ClaimsIdentity)).Return(expectedUser);
            return(filterContext);
        }
        public void GivenExceptionIsEntityNotFoundException_WhenOnException_ThenExceptionHandled()
        {
            EntityNotFoundException exception = new EntityNotFoundException();
            ExceptionContext        context   = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            Assert.IsTrue(context.ExceptionHandled);
        }
        public void GivenResponseHasBeenWrittenTo_ExceptionIsEntityNotFoundException_WhenOnException_ThenResponseHasBeenCleared()
        {
            EntityNotFoundException exception = new EntityNotFoundException();
            ExceptionContext        context   = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            MockHttpContext.Response.AssertWasCalled(m => m.Clear());
        }
        public void GivenPrincipalIsNotClaimsPrincipal_WhenMapFrom_ThenReturnNull()
        {
            MockHttpContext.User = MockRepository.GenerateMock <IPrincipal>();
            AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase);

            EducationSecurityPrincipal actual = UserIdentityMapAttribute.MapFrom(filterContext);

            Assert.IsNull(actual);
        }
        public void GivenExceptionIsUnreserved_AndCustomErrorsEnabled_WhenOnException_ThenDefaultToGeneralServerError()
        {
            Exception        exception = new Exception();
            ExceptionContext context   = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            MockHttpContext.Expect(m => m.IsCustomErrorEnabled).Return(true);

            Target.OnException(context);

            MockHttpContext.Response.AssertWasCalled(m => m.StatusCode = 500);
        }
        public void GivenExceptionIsEntityAccessUnauthorizedException_WhenOnException_ThenHttpUnauthorized()
        {
            EntityAccessUnauthorizedException exception = new EntityAccessUnauthorizedException();
            ExceptionContext context = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            HttpUnauthorizedResult actual = context.Result as HttpUnauthorizedResult;

            Assert.IsNotNull(actual);
            MockHttpContext.Response.AssertWasCalled(m => m.StatusCode = 401);
        }
        public void GivenExceptionHasBeenHandled_AndExceptionIsEntityNotFoundException_WhenOnException_ThenResultNull_AndStatusNotChanged()
        {
            EntityNotFoundException exception = new EntityNotFoundException();
            ExceptionContext        context   = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            context.ExceptionHandled = true;

            Target.OnException(context);

            Assert.IsInstanceOfType(context.Result, typeof(EmptyResult));
            MockHttpContext.Response.AssertWasNotCalled(m => m.StatusCode = Arg <int> .Is.Anything);
        }
        public void GivenExceptionIsEntityNotFoundException_WhenOnException_ThenHttpDescriptionIsExceptionMessage()
        {
            string expected = "blah blah exception message and stuff";
            EntityNotFoundException exception = new EntityNotFoundException(expected);
            ExceptionContext        context   = ControllerContextFactory.CreateExceptionContext(MockHttpContext, exception);

            Target.OnException(context);

            HttpStatusCodeResult actual = context.Result as HttpStatusCodeResult;

            Assert.AreEqual(expected, actual.StatusDescription);
        }
        public void GivenActionInvokedIsAccountLogOff_AndUserIsNotAnEducationSecurityPrincipal_AndEulaNotAccepted_WhenAuthorizing_ThenSucceed()
        {
            User expectedUserEntity = new User {
                UserKey = "whatever"
            };

            MockHttpContext.User = CreateClaimsPrincipal(expectedUserEntity.UserKey);
            AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase, typeof(AccountController), "LogOff");

            System.Security.Claims.ClaimsPrincipal claimsPrincipal = MockHttpContext.User as System.Security.Claims.ClaimsPrincipal;
            filterContext.HttpContext.User = claimsPrincipal;
            MockAccountManager.Expect(m => m.EnsureUserEntity((System.Security.Claims.ClaimsIdentity)claimsPrincipal.Identity)).Throw(new LicenseAgreementException());

            Target.OnAuthorization(filterContext);
        }
        public void GivenLogicManagerThrowsLicenseAgreementException_WhenAuthorizing_ThenRedirectToLicenseAgreement()
        {
            string userKey = "whatever";

            MockHttpContext.User = CreateClaimsPrincipal(userKey);
            AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase);

            MockAccountManager.Expect(m => m.EnsureUserEntity(filterContext.HttpContext.User.Identity as System.Security.Claims.ClaimsIdentity)).Throw(new LicenseAgreementException());

            Target.OnAuthorization(filterContext);

            var actual = filterContext.Result as RedirectToRouteResult;

            actual.AssertActionRedirection("Index", "Agreement");
        }
Пример #15
0
        private PaymentController CreatePaymentController(Guid merchantId, IPaymentRepository paymentRepository, IBankOfIrelandClient bankOfIrelandClient, IDatetimeService datetimeService)
        {
            var bankOfIrelandPaymentRequestMapper = new BankOfIrelandPaymentRequestMapper();
            var bankOfIrelandAcquiringBankService = new BankOfIrelandAcquiringBankService(bankOfIrelandClient, bankOfIrelandPaymentRequestMapper, paymentRepository);
            var acquirerBankSelectionService      = new AcquirerBankSelectionService();

            var createCardPaymentService = new CreateCardPaymentService(bankOfIrelandAcquiringBankService, paymentRepository, acquirerBankSelectionService);

            var cardPaymentResponseMapper = new CardPaymentResponseMapper();
            var paymentService            = new PaymentService(createCardPaymentService, cardPaymentResponseMapper, null, null, null);

            var cardValidator = new CardValidator(datetimeService);
            var controller    = new PaymentController(LoggerHelper.CreateLogger <PaymentController>(), paymentService, cardValidator);

            controller.ControllerContext = ControllerContextFactory.CreateControllerContextForClient(merchantId);

            return(controller);
        }
        private static AuthorizationContext CreateAuthorizationContext(bool mockableContext, string userKey)
        {
            HttpContextBase httpContext = CreateHttpContextBase(mockableContext, userKey);

            return(ControllerContextFactory.CreateAuthorizationContext(httpContext));
        }
        public void GivenPrincipalIsNull_WhenMapFrom_ThenReturnNull()
        {
            AuthorizationContext filterContext = ControllerContextFactory.CreateAuthorizationContext(MockHttpContextBase);

            Assert.IsNull(UserIdentityMapAttribute.MapFrom(filterContext));
        }