Example #1
0
        public async Task SendInvitationAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            TestMock.InvitationService.Setup(clanService => clanService.SendInvitationAsync(It.IsAny <ClanId>(), It.IsAny <UserId>(), It.IsAny <UserId>()))
            .ReturnsAsync(new DomainValidationResult <Invitation>())
            .Verifiable();

            var invitationController = new InvitationsController(TestMock.InvitationService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await invitationController.SendInvitationAsync(
                new SendInvitationRequest
            {
                UserId = new UserId(),
                ClanId = new ClanId()
            });

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.InvitationService.Verify(
                clanService => clanService.SendInvitationAsync(It.IsAny <ClanId>(), It.IsAny <UserId>(), It.IsAny <UserId>()),
                Times.Once);
        }
Example #2
0
        public async Task FetchUserTransactionsAsync_ShouldBeOfTypeNoContentResult()
        {
            // Arrange
            TestMock.TransactionQuery
            .Setup(
                transactionQuery => transactionQuery.FetchUserTransactionsAsync(
                    It.IsAny <UserId>(),
                    It.IsAny <CurrencyType>(),
                    It.IsAny <TransactionType>(),
                    It.IsAny <TransactionStatus>()))
            .ReturnsAsync(new Collection <ITransaction>())
            .Verifiable();

            var controller = new TransactionsController(TestMock.TransactionQuery.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.FetchUserTransactionsAsync();

            // Assert
            result.Should().BeOfType <NoContentResult>();

            TestMock.TransactionQuery.Verify(
                transactionQuery => transactionQuery.FetchUserTransactionsAsync(
                    It.IsAny <UserId>(),
                    It.IsAny <CurrencyType>(),
                    It.IsAny <TransactionType>(),
                    It.IsAny <TransactionStatus>()),
                Times.Once);
        }
Example #3
0
        public async Task DeclineInvitationAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            TestMock.InvitationService.Setup(clanService => clanService.FindInvitationAsync(It.IsAny <InvitationId>()))
            .ReturnsAsync(new Invitation(new UserId(), new ClanId()))
            .Verifiable();

            TestMock.InvitationService.Setup(clanService => clanService.DeclineInvitationAsync(It.IsAny <Invitation>(), It.IsAny <UserId>()))
            .ReturnsAsync(DomainValidationResult <Invitation> .Failure("Test error"))
            .Verifiable();

            var controller = new InvitationsController(TestMock.InvitationService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.DeclineInvitationAsync(new InvitationId());

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.InvitationService.Verify(clanService => clanService.FindInvitationAsync(It.IsAny <InvitationId>()), Times.Once);

            TestMock.InvitationService.Verify(clanService => clanService.DeclineInvitationAsync(It.IsAny <Invitation>(), It.IsAny <UserId>()), Times.Once);
        }
Example #4
0
        public static TokenValidator CreateTokenValidator(IReferenceTokenStore store = null, IProfileService profile = null)
        {
            if (profile == null)
            {
                profile = new TestProfileService();
            }

            if (store == null)
            {
                store = CreateReferenceTokenStore();
            }

            var clients = CreateClientStore();
            var options = TestIdentityServerOptions.Create();
            var context = new MockHttpContextAccessor(options);
            var logger  = TestLogger.Create <TokenValidator>();

            var validator = new TokenValidator(
                clients: clients,
                referenceTokenStore: store,
                customValidator: new DefaultCustomTokenValidator(
                    profile: profile,
                    clients: clients,
                    logger: TestLogger.Create <DefaultCustomTokenValidator>()),
                keys: new DefaultKeyMaterialService(new[] { new DefaultValidationKeysStore(new[] { TestCert.LoadSigningCredentials().Key }) }),
                logger: logger,
                options: options,
                context: context);

            return(validator);
        }
Example #5
0
        public async Task CreateClanAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            TestMock.ClanService.Setup(clanService => clanService.CreateClanAsync(It.IsAny <UserId>(), It.IsAny <string>()))
            .ReturnsAsync(new DomainValidationResult <Clan>())
            .Verifiable();

            var clansController = new ClansController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            var request = new CreateClanRequest
            {
                Name    = "DONTINVADE",
                Summary = "URSSINWINTER"
            };

            // Act
            var result = await clansController.CreateClanAsync(request);

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.CreateClanAsync(It.IsAny <UserId>(), It.IsAny <string>()), Times.Once);
        }
Example #6
0
        public async Task CancelPromotionAsync_ShouldBeNotFoundObjectResult()
        {
            // Arrange
            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.CancelPromotionAsync(TestCode);

            // Assert
            result.Should().BeOfType <NotFoundObjectResult>();
            TestMock.PromotionService.Verify(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()),
                Times.Once);
        }
        public async Task FetchPaymentMethodsAsync_ShouldBeOfTypeNoContentResult()
        {
            // Arrange
            TestMock.StripePaymentMethodService.Setup(paymentMethodService => paymentMethodService.FetchPaymentMethodsAsync(It.IsAny <string>()))
            .ReturnsAsync(
                new StripeList <PaymentMethod>
            {
                Data = new List <PaymentMethod>()
            })
            .Verifiable();

            var paymentMethodController = new PaymentMethodsController(
                TestMock.StripePaymentMethodService.Object,
                TestMock.StripeCustomerService.Object,
                TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await paymentMethodController.FetchPaymentMethodsAsync();

            // Assert
            result.Should().BeOfType <NoContentResult>();
            TestMock.StripePaymentMethodService.Verify(paymentMethodService => paymentMethodService.FetchPaymentMethodsAsync(It.IsAny <string>()), Times.Once);
        }
Example #8
0
        public async Task DeclineInvitationAsync_ShouldBeOfTypeNotFoundObjectResult()
        {
            // Arrange
            TestMock.InvitationService.Setup(clanService => clanService.FindInvitationAsync(It.IsAny <InvitationId>()))
            .ReturnsAsync((Invitation)null)
            .Verifiable();

            TestMock.InvitationService.Setup(clanService => clanService.DeclineInvitationAsync(It.IsAny <Invitation>(), It.IsAny <UserId>()))
            .ReturnsAsync(new DomainValidationResult <Invitation>())
            .Verifiable();

            var invitationController = new InvitationsController(TestMock.InvitationService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await invitationController.DeclineInvitationAsync(new InvitationId());

            // Assert
            result.Should().BeOfType <NotFoundObjectResult>();

            TestMock.InvitationService.Verify(clanService => clanService.FindInvitationAsync(It.IsAny <InvitationId>()), Times.Once);

            TestMock.InvitationService.Verify(clanService => clanService.DeclineInvitationAsync(It.IsAny <Invitation>(), It.IsAny <UserId>()), Times.Never);
        }
        public async Task SendCandidatureAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            TestMock.CandidatureService.Setup(clanService => clanService.SendCandidatureAsync(It.IsAny <UserId>(), It.IsAny <ClanId>()))
            .ReturnsAsync(DomainValidationResult <Candidature> .Failure("Error"))
            .Verifiable();

            var candidatureController = new CandidaturesController(TestMock.CandidatureService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await candidatureController.SendCandidatureAsync(
                new SendCandidatureRequest
            {
                ClanId = new ClanId(),
                UserId = new UserId()
            });

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.CandidatureService.Verify(clanService => clanService.SendCandidatureAsync(It.IsAny <UserId>(), It.IsAny <ClanId>()), Times.Once);
        }
        public async Task LinkCredentialAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            TestMock.GameCredentialService.Setup(credentialService => credentialService.LinkCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>()))
            .ReturnsAsync(DomainValidationResult <Credential> .Failure("test error"))
            .Verifiable();

            var authFactorController = new GameAuthenticationsController(
                TestMock.GameAuthenticationService.Object,
                TestMock.GameCredentialService.Object,
                TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await authFactorController.LinkCredentialAsync(Game.LeagueOfLegends);

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.GameCredentialService.Verify(credentialService => credentialService.LinkCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once);
        }
        public async Task LeaveClanAsync_ShouldBeOfTypeNotFoundObjectResult()
        {
            // Arrange
            TestMock.ClanService.Setup(clanService => clanService.FindClanAsync(It.IsAny <ClanId>())).ReturnsAsync((Clan)null).Verifiable();

            TestMock.ClanService.Setup(clanService => clanService.LeaveClanAsync(It.IsAny <Clan>(), It.IsAny <UserId>()))
            .ReturnsAsync(new DomainValidationResult <Clan>())
            .Verifiable();

            var clanMemberController = new ClanMembersController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await clanMemberController.LeaveClanAsync(new ClanId());

            // Assert
            result.Should().BeOfType <NotFoundObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.FindClanAsync(It.IsAny <ClanId>()), Times.Once);

            TestMock.ClanService.Verify(clanService => clanService.LeaveClanAsync(It.IsAny <Clan>(), It.IsAny <UserId>()), Times.Never);
        }
        public async Task KickMemberFromClanAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            TestMock.ClanService.Setup(clanService => clanService.FindClanAsync(It.IsAny <ClanId>())).ReturnsAsync(new Clan("Test", new UserId())).Verifiable();

            TestMock.ClanService.Setup(clanService => clanService.KickMemberFromClanAsync(It.IsAny <Clan>(), It.IsAny <UserId>(), It.IsAny <MemberId>()))
            .ReturnsAsync(DomainValidationResult <Member> .Failure("Error"))
            .Verifiable();

            var clanMemberController = new ClanMembersController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await clanMemberController.KickMemberFromClanAsync(new ClanId(), new MemberId());

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.FindClanAsync(It.IsAny <ClanId>()), Times.Once);

            TestMock.ClanService.Verify(
                clanService => clanService.KickMemberFromClanAsync(It.IsAny <Clan>(), It.IsAny <UserId>(), It.IsAny <MemberId>()),
                Times.Once);
        }
        public async Task CreateDivisionAsync_ShouldBeOfTypeNotFoundObjectResult()
        {
            // Arrange
            TestMock.ClanService.Setup(clanService => clanService.FindClanAsync(It.IsAny <ClanId>())).Verifiable();

            var clanDivisionsController = new ClanDivisionsController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await clanDivisionsController.CreateDivisionAsync(
                new ClanId(),
                new CreateDivisionRequest
            {
                Name        = "test",
                Description = "division"
            });

            // Assert
            result.Should().BeOfType <NotFoundObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.FindClanAsync(It.IsAny <ClanId>()), Times.Once);
        }
        public async Task FetchDivisionsAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            var clanId = new ClanId();

            TestMock.ClanService.Setup(clanService => clanService.FetchDivisionsAsync(It.IsAny <ClanId>()))
            .ReturnsAsync(
                new List <Division>
            {
                new Division(clanId, "Test", "Division"),
                new Division(clanId, "Test", "Division"),
                new Division(clanId, "Test", "Division")
            })
            .Verifiable();

            var clanDivisionsController = new ClanDivisionsController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await clanDivisionsController.FetchDivisionsAsync(clanId);

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.FetchDivisionsAsync(It.IsAny <ClanId>()), Times.Once);
        }
        public async Task DeleteDivisionAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            var userId = new UserId();

            var clan = new Clan("testClan", userId);

            TestMock.ClanService.Setup(clanService => clanService.FindClanAsync(It.IsAny <ClanId>())).ReturnsAsync(clan).Verifiable();

            TestMock.ClanService.Setup(clanService => clanService.DeleteDivisionAsync(It.IsAny <Clan>(), It.IsAny <UserId>(), It.IsAny <DivisionId>()))
            .ReturnsAsync(new DomainValidationResult <Division>())
            .Verifiable();

            var clanDivisionsController = new ClanDivisionsController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await clanDivisionsController.DeleteDivisionAsync(new ClanId(), new DivisionId());

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.FindClanAsync(It.IsAny <ClanId>()), Times.Once);

            TestMock.ClanService.Verify(
                clanService => clanService.DeleteDivisionAsync(It.IsAny <Clan>(), It.IsAny <UserId>(), It.IsAny <DivisionId>()),
                Times.Once);
        }
        public async Task AcceptCandidatureAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            TestMock.CandidatureService.Setup(clanService => clanService.FindCandidatureAsync(It.IsAny <CandidatureId>()))
            .ReturnsAsync(new Candidature(new UserId(), new ClanId()))
            .Verifiable();

            TestMock.CandidatureService.Setup(clanService => clanService.AcceptCandidatureAsync(It.IsAny <Candidature>(), It.IsAny <UserId>()))
            .ReturnsAsync(new DomainValidationResult <Candidature>())
            .Verifiable();

            var candidatureController = new CandidaturesController(TestMock.CandidatureService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await candidatureController.AcceptCandidatureAsync(new CandidatureId());

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.CandidatureService.Verify(clanService => clanService.FindCandidatureAsync(It.IsAny <CandidatureId>()), Times.Once);

            TestMock.CandidatureService.Verify(clanService => clanService.AcceptCandidatureAsync(It.IsAny <Candidature>(), It.IsAny <UserId>()), Times.Once);
        }
        public async Task SetDefaultPaymentMethodAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            TestMock.StripeCustomerService.Setup(customerService => customerService.SetDefaultPaymentMethodAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(
                new Customer
            {
                InvoiceSettings = new CustomerInvoiceSettings
                {
                    DefaultPaymentMethodId = "DefaultPaymentMethodId"
                }
            })
            .Verifiable();

            var customerPaymentDefaultController = new PaymentMethodsController(
                TestMock.StripePaymentMethodService.Object,
                TestMock.StripeCustomerService.Object,
                TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await customerPaymentDefaultController.SetDefaultPaymentMethodAsync("testValue");

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.StripeCustomerService.Verify(
                customerService => customerService.SetDefaultPaymentMethodAsync(It.IsAny <string>(), It.IsAny <string>()),
                Times.Once);
        }
Example #18
0
        public static TokenValidator CreateTokenValidator(
            IReferenceTokenStore store           = null,
            IRefreshTokenStore refreshTokenStore = null,
            IProfileService profile       = null,
            IdentityServerOptions options = null, ISystemClock clock = null)
        {
            if (options == null)
            {
                options = TestIdentityServerOptions.Create();
            }

            if (profile == null)
            {
                profile = new TestProfileService();
            }

            if (store == null)
            {
                store = CreateReferenceTokenStore();
            }

            clock = clock ?? new StubClock();

            if (refreshTokenStore == null)
            {
                refreshTokenStore = CreateRefreshTokenStore();
            }

            var clients = CreateClientStore();
            var context = new MockHttpContextAccessor(options);
            var logger  = TestLogger.Create <TokenValidator>();

            var keyInfo = new SecurityKeyInfo
            {
                Key = TestCert.LoadSigningCredentials().Key,
                SigningAlgorithm = "RS256"
            };

            var validator = new TokenValidator(
                clients: clients,
                clock: clock,
                profile: profile,
                referenceTokenStore: store,
                refreshTokenStore: refreshTokenStore,
                customValidator: new DefaultCustomTokenValidator(),
                keys: new DefaultKeyMaterialService(
                    new[] { new InMemoryValidationKeysStore(new[] { keyInfo }) },
                    Enumerable.Empty <ISigningCredentialStore>(),
                    new NopAutomaticKeyManagerKeyStore()
                    ),
                logger: logger,
                options: options,
                context: context);

            return(validator);
        }
 private void InitializeTokenAcquisitionObjects()
 {
     _tokenAcquisition = new TokenAcquisition(
         new MsalTestTokenCacheProvider(
             _provider.GetService <IMemoryCache>(),
             _provider.GetService <IOptions <MsalMemoryTokenCacheOptions> >()),
         MockHttpContextAccessor.CreateMockHttpContextAccessor(),
         _provider.GetService <IOptionsMonitor <MergedOptions> >(),
         _provider.GetService <IHttpClientFactory>(),
         _provider.GetService <ILogger <TokenAcquisition> >(),
         _provider);
 }
        public async Task UpdateDivisionAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            var userId = new UserId();

            var clan = new Clan("testClan", userId);

            TestMock.ClanService.Setup(clanService => clanService.FindClanAsync(It.IsAny <ClanId>())).ReturnsAsync(clan).Verifiable();

            TestMock.ClanService.Setup(
                clanService => clanService.UpdateDivisionAsync(
                    It.IsAny <Clan>(),
                    It.IsAny <UserId>(),
                    It.IsAny <DivisionId>(),
                    It.IsAny <string>(),
                    It.IsAny <string>()))
            .ReturnsAsync(DomainValidationResult <Division> .Failure("Test error"))
            .Verifiable();

            var clanDivisionsController = new ClanDivisionsController(TestMock.ClanService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await clanDivisionsController.UpdateDivisionAsync(
                new ClanId(),
                new DivisionId(),
                new UpdateDivisionRequest
            {
                Name        = "test",
                Description = "division"
            });

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.FindClanAsync(It.IsAny <ClanId>()), Times.Once);

            TestMock.ClanService.Verify(
                clanService => clanService.UpdateDivisionAsync(
                    It.IsAny <Clan>(),
                    It.IsAny <UserId>(),
                    It.IsAny <DivisionId>(),
                    It.IsAny <string>(),
                    It.IsAny <string>()),
                Times.Once);
        }
Example #21
0
        public DefaultIdentityServerInteractionServiceTests()
        {
            _mockMockHttpContextAccessor = new MockHttpContextAccessor(_options, _mockUserSession, _mockEndSessionStore);

            _subject = new DefaultIdentityServerInteractionService(new StubClock(),
                                                                   _mockMockHttpContextAccessor,
                                                                   _mockLogoutMessageStore,
                                                                   _mockErrorMessageStore,
                                                                   _mockConsentStore,
                                                                   _mockPersistedGrantService,
                                                                   _mockUserSession,
                                                                   _mockReturnUrlParser,
                                                                   TestLogger.Create <DefaultIdentityServerInteractionService>()
                                                                   );
        }
        private void InitializeTokenAcquisitionObjects()
        {
            _msalTestTokenCacheProvider = new MsalTestTokenCacheProvider(
                _provider.GetService <IMemoryCache>(),
                _provider.GetService <IOptions <MsalMemoryTokenCacheOptions> >());

            _tokenAcquisition = new TokenAcquisition(
                _msalTestTokenCacheProvider,
                MockHttpContextAccessor.CreateMockHttpContextAccessor(),
                _provider.GetService <IOptions <MicrosoftIdentityOptions> >(),
                _provider.GetService <IOptions <ConfidentialClientApplicationOptions> >(),
                _provider.GetService <IHttpClientFactory>(),
                _provider.GetService <ILogger <TokenAcquisition> >(),
                _provider);
        }
        public async Task UpdatePaymentMethodAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            TestMock.StripePaymentMethodService
            .Setup(paymentMethodService => paymentMethodService.UpdatePaymentMethodAsync(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <long>()))
            .ReturnsAsync(
                new PaymentMethod
            {
                Id   = "PaymentMethodId",
                Type = "card",
                Card = new PaymentMethodCard
                {
                    Brand    = "Brand",
                    Country  = "CA",
                    Last4    = "1234",
                    ExpMonth = 11,
                    ExpYear  = 22
                }
            })
            .Verifiable();

            var paymentMethodController = new PaymentMethodsController(
                TestMock.StripePaymentMethodService.Object,
                TestMock.StripeCustomerService.Object,
                TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await paymentMethodController.UpdatePaymentMethodAsync(
                "type",
                new UpdateStripePaymentMethodRequest
            {
                ExpYear  = 22,
                ExpMonth = 11
            });

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.StripePaymentMethodService.Verify(
                paymentMethodService => paymentMethodService.UpdatePaymentMethodAsync(It.IsAny <string>(), It.IsAny <long>(), It.IsAny <long>()),
                Times.Once);
        }
        public HttpContext InitializeHttpContext()
        {
            var testContext = new DefaultHttpContext();

            testContext.Session = new MockSession();

            FeedbackMessageStoreHolder.IsAvailableSession = true;

            var contextAccessor = new MockHttpContextAccessor();

            contextAccessor.HttpContext = testContext;

            FeedbackMessageStoreHolder.ContextAccessor = contextAccessor;
            FeedbackMessageStore.Initialize(FeedbackMessageStoreHolder.Instance);
            return(testContext);
        }
Example #25
0
        public async Task CancelPromotionAsync_ShouldBeOkObjectResult()
        {
            // Arrange
            var promotion = GeneratePromotion();

            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()))
            .ReturnsAsync(promotion)
            .Verifiable();

            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.CancelPromotionAsync(
                    It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>()))
            .ReturnsAsync(DomainValidationResult <Promotion> .Succeeded(promotion))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.CancelPromotionAsync(TestCode);

            // Assert
            result.Should().BeOfType <OkObjectResult>();
            result.As <OkObjectResult>().Value.Should().BeEquivalentTo(TestMapper.Map <PromotionDto>(promotion));

            TestMock.PromotionService.Verify(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()),
                Times.Once);

            TestMock.PromotionService.Verify(
                promotionService => promotionService.CancelPromotionAsync(
                    It.IsAny <Promotion>(), It.IsAny <IDateTimeProvider>()),
                Times.Once);
        }
Example #26
0
        public async Task RedeemPromotionAsync_ShouldBeBadRequestObjectResult()
        {
            // Arrange
            var promotion = GeneratePromotion();

            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()))
            .ReturnsAsync(promotion)
            .Verifiable();

            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.RedeemPromotionAsync(
                    It.IsAny <Promotion>(), It.IsAny <UserId>(), It.IsAny <IDateTimeProvider>()))
            .ReturnsAsync(DomainValidationResult <Promotion> .Failure("error message"))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.RedeemPromotionAsync(TestCode);

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();

            TestMock.PromotionService.Verify(
                promotionService => promotionService.FindPromotionOrNullAsync(
                    It.IsAny <string>()),
                Times.Once);

            TestMock.PromotionService.Verify(
                promotionService => promotionService.RedeemPromotionAsync(
                    It.IsAny <Promotion>(), It.IsAny <UserId>(), It.IsAny <IDateTimeProvider>()),
                Times.Once);
        }
        public DefaultIdentityServerInteractionServiceTests()
        {
            _mockMockHttpContextAccessor = new MockHttpContextAccessor(_options, _mockUserSession, _mockEndSessionStore);

            _subject = new DefaultIdentityServerInteractionService(new StubClock(),
                                                                   _mockMockHttpContextAccessor,
                                                                   _mockLogoutMessageStore,
                                                                   _mockErrorMessageStore,
                                                                   _mockConsentStore,
                                                                   _mockPersistedGrantService,
                                                                   _mockUserSession,
                                                                   _mockReturnUrlParser,
                                                                   TestLogger.Create <DefaultIdentityServerInteractionService>()
                                                                   );

            _resourceValidationResult = new ResourceValidationResult();
            _resourceValidationResult.Resources.IdentityResources.Add(new IdentityResources.OpenId());
            _resourceValidationResult.ParsedScopes.Add(new ParsedScopeValue("openid"));
        }
        private void InitializeTokenAcquisitionObjects()
        {
            MergedOptions mergedOptions = _provider.GetRequiredService <IOptionsMonitor <MergedOptions> >().Get(OpenIdConnectDefaults.AuthenticationScheme);

            MergedOptions.UpdateMergedOptionsFromMicrosoftIdentityOptions(_microsoftIdentityOptionsMonitor.Get(OpenIdConnectDefaults.AuthenticationScheme), mergedOptions);
            MergedOptions.UpdateMergedOptionsFromConfidentialClientApplicationOptions(_applicationOptionsMonitor.Get(OpenIdConnectDefaults.AuthenticationScheme), mergedOptions);

            _msalTestTokenCacheProvider = new MsalTestTokenCacheProvider(
                _provider.GetService <IMemoryCache>(),
                _provider.GetService <IOptions <MsalMemoryTokenCacheOptions> >());

            _tokenAcquisition = new TokenAcquisition(
                _msalTestTokenCacheProvider,
                MockHttpContextAccessor.CreateMockHttpContextAccessor(),
                _provider.GetService <IOptionsMonitor <MergedOptions> >(),
                _provider.GetService <IHttpClientFactory>(),
                _provider.GetService <ILogger <TokenAcquisition> >(),
                _provider);
            _tokenAcquisition.GetOptions(OpenIdConnectDefaults.AuthenticationScheme, out string effectiveAuthenticationScheme);
            Assert.Equal(OpenIdConnectDefaults.AuthenticationScheme, effectiveAuthenticationScheme);
        }
        public async Task UnlinkCredentialAsync_ShouldBeOfTypeNotFoundObjectResult()
        {
            // Arrange
            TestMock.GameCredentialService.Setup(credentialService => credentialService.FindCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>())).Verifiable();

            var authFactorController = new GameCredentialsController(TestMock.GameCredentialService.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await authFactorController.UnlinkCredentialAsync(Game.LeagueOfLegends);

            // Assert
            result.Should().BeOfType <NotFoundObjectResult>();

            TestMock.GameCredentialService.Verify(credentialService => credentialService.FindCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once);
        }
Example #30
0
        public async Task FetchUserTransactionsAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            var faker = TestData.FakerFactory.CreateTransactionFaker(null);

            TestMock.TransactionQuery
            .Setup(
                transactionQuery => transactionQuery.FetchUserTransactionsAsync(
                    It.IsAny <UserId>(),
                    It.IsAny <CurrencyType>(),
                    It.IsAny <TransactionType>(),
                    It.IsAny <TransactionStatus>()))
            .ReturnsAsync(faker.FakeTransactions(5, TransactionFaker.PositiveTransaction))
            .Verifiable();

            var controller = new TransactionsController(TestMock.TransactionQuery.Object, TestMapper)
            {
                ControllerContext =
                {
                    HttpContext = MockHttpContextAccessor.GetInstance()
                }
            };

            // Act
            var result = await controller.FetchUserTransactionsAsync();

            // Assert
            result.Should().BeOfType <OkObjectResult>();

            TestMock.TransactionQuery.Verify(
                transactionQuery => transactionQuery.FetchUserTransactionsAsync(
                    It.IsAny <UserId>(),
                    It.IsAny <CurrencyType>(),
                    It.IsAny <TransactionType>(),
                    It.IsAny <TransactionStatus>()),
                Times.Once);
        }