Ejemplo n.º 1
0
        public void HandleHandleLinkAccountThrowsForNonAuthenticatedUser()
        {
            var service = new VippsLoginCommerceService(
                A.Fake <IVippsLoginService>(),
                A.Fake <IVippsLoginMapper>(),
                A.Fake <IVippsLoginDataLoader>(),
                A.Fake <ICustomerContactService>());

            Assert.Throws <InvalidOperationException>(() => service.HandleLinkAccount(A.Fake <IOwinContext>()));
        }
Ejemplo n.º 2
0
        public void HandleHandleLinkAccountReturnsTrueForNonVippsUser()
        {
            var context = A.Fake <IOwinContext>();
            var user    = A.Fake <ClaimsPrincipal>();

            A.CallTo(() => context.Authentication.User).Returns(user);
            A.CallTo(() => user.Identity.IsAuthenticated).Returns(true);

            var loginService = A.Fake <IVippsLoginService>();

            A.CallTo(() => loginService.IsVippsIdentity(A <IIdentity> ._)).Returns(false);

            var customerContactService = A.Fake <ICustomerContactService>();

            var service = new VippsLoginCommerceService(
                loginService,
                A.Fake <IVippsLoginMapper>(),
                A.Fake <IVippsLoginDataLoader>(),
                customerContactService);

            Assert.True(service.HandleLinkAccount(context, new CustomerContact()));

            A.CallTo(() =>
                     context.Authentication.Challenge(A <AuthenticationProperties> ._,
                                                      VippsAuthenticationDefaults.AuthenticationType))
            .WhenArgumentsMatch((args) =>
            {
                // Verify link account token
                var props = args[0] as AuthenticationProperties;
                if (props?.Dictionary == null ||
                    !props.Dictionary.ContainsKey(VippsConstants.LinkAccount) ||
                    !Guid.TryParse(props.Dictionary[VippsConstants.LinkAccount], out _))
                {
                    return(false);
                }

                // Verify auth type
                if (!(args[1] is string[] types) ||
                    !types.Contains(VippsAuthenticationDefaults.AuthenticationType))
                {
                    return(false);
                }

                return(true);
            })
            .MustHaveHappened();

            // Verify storing link account token on account
            A.CallTo(() => customerContactService.SaveChanges(A <CustomerContact> ._))
            .MustHaveHappened();
        }
Ejemplo n.º 3
0
        public void HandleHandleLinkAccountReturnsFalseForVippsUser()
        {
            var context = A.Fake <IOwinContext>();
            var user    = A.Fake <ClaimsPrincipal>();

            A.CallTo(() => context.Authentication.User).Returns(user);
            A.CallTo(() => user.Identity.IsAuthenticated).Returns(true);

            var loginService = A.Fake <IVippsLoginService>();

            A.CallTo(() => loginService.IsVippsIdentity(A <IIdentity> ._)).Returns(true);

            var service = new VippsLoginCommerceService(
                loginService,
                A.Fake <IVippsLoginMapper>(),
                A.Fake <IVippsLoginDataLoader>(),
                A.Fake <ICustomerContactService>());

            Assert.False(service.HandleLinkAccount(context));
        }