Exemple #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);
        }
        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);
        }
Exemple #3
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 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 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 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 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);
        }
Exemple #9
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);
        }
        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 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);
        }
        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 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);
        }
Exemple #14
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);
        }
Exemple #15
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 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 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);
        }
        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);
        }
Exemple #19
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);
        }
Exemple #20
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 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);
        }
        public async Task UnlinkCredentialAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            var userId = new UserId();

            var credential = new Credential(
                userId,
                Game.LeagueOfLegends,
                new PlayerId(),
                new UtcNowDateTimeProvider());

            TestMock.GameCredentialService.Setup(credentialService => credentialService.FindCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>()))
            .ReturnsAsync(credential)
            .Verifiable();

            TestMock.GameCredentialService.Setup(credentialService => credentialService.UnlinkCredentialAsync(It.IsAny <Credential>()))
            .ReturnsAsync(DomainValidationResult <Credential> .Failure("test", "test error"))
            .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 <BadRequestObjectResult>();

            TestMock.GameCredentialService.Verify(credentialService => credentialService.FindCredentialAsync(It.IsAny <UserId>(), It.IsAny <Game>()), Times.Once);

            TestMock.GameCredentialService.Verify(credentialService => credentialService.UnlinkCredentialAsync(It.IsAny <Credential>()), Times.Once);
        }
Exemple #23
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);
        }
        public async Task GenerateAuthenticationAsync_ShouldBeOfTypeOkObjectResult()
        {
            // Arrange
            var gameAuthentication = new LeagueOfLegendsGameAuthentication(
                PlayerId.Parse("playerId"),
                new LeagueOfLegendsGameAuthenticationFactor(
                    1,
                    string.Empty,
                    2,
                    string.Empty));

            TestMock.GameAuthenticationService
            .Setup(authFactorService => authFactorService.GenerateAuthenticationAsync(It.IsAny <UserId>(), It.IsAny <Game>(), It.IsAny <object>()))
            .ReturnsAsync(DomainValidationResult <GameAuthentication> .Succeeded(gameAuthentication))
            .Verifiable();

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

            // Act
            var result = await authFactorController.GenerateAuthenticationAsync(Game.LeagueOfLegends, "playerId");

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

            TestMock.GameAuthenticationService.Verify(
                authFactorService => authFactorService.GenerateAuthenticationAsync(It.IsAny <UserId>(), It.IsAny <Game>(), It.IsAny <object>()),
                Times.Once);
        }