public async Task DeleteDivisionAsync_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.DeleteDivisionAsync(It.IsAny <Clan>(), It.IsAny <UserId>(), It.IsAny <DivisionId>()))
            .ReturnsAsync(DomainValidationResult <Division> .Failure("Test error"))
            .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 <BadRequestObjectResult>();

            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 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);
        }
Exemplo n.º 3
0
        public async Task CreateClanAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            TestMock.ClanService.Setup(clanService => clanService.CreateClanAsync(It.IsAny <UserId>(), It.IsAny <string>()))
            .ReturnsAsync(DomainValidationResult <Clan> .Failure("Test error"))
            .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 <BadRequestObjectResult>();

            TestMock.ClanService.Verify(clanService => clanService.CreateClanAsync(It.IsAny <UserId>(), It.IsAny <string>()), 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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public async Task AcceptInvitationAsync_ShouldBeOfTypeBadRequestObjectResult()
        {
            // Arrange
            TestMock.InvitationService.Setup(clanService => clanService.FindInvitationAsync(It.IsAny <InvitationId>()))
            .ReturnsAsync(new Invitation(new UserId(), new ClanId()))
            .Verifiable();

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

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

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

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

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

            TestMock.InvitationService.Verify(clanService => clanService.AcceptInvitationAsync(It.IsAny <Invitation>(), It.IsAny <UserId>()), Times.Once);
        }
        public override async Task <DomainValidationResult <object> > GenerateAuthenticationAsync(UserId userId, LeagueOfLegendsRequest request)
        {
            try
            {
                var result = new DomainValidationResult <object>();

                var summoner = await _leagueOfLegendsService.Summoner.GetSummonerByNameAsync(Region.Na, request.SummonerName);

                if (await _gameCredentialRepository.CredentialExistsAsync(PlayerId.Parse(summoner.AccountId), Game))
                {
                    result.AddFailedPreconditionError("Summoner's name is already linked by another eDoxa account");
                }

                if (result.IsValid)
                {
                    if (await _gameAuthenticationRepository.AuthenticationExistsAsync(userId, Game))
                    {
                        await _gameAuthenticationRepository.RemoveAuthenticationAsync(userId, Game);
                    }

                    var gameAuthentication = await this.GenerateAuthFactor(summoner);

                    await _gameAuthenticationRepository.AddAuthenticationAsync(userId, Game, gameAuthentication);

                    return(gameAuthentication.Factor);
                }

                return(result);
            }
            catch (RiotSharpException)
            {
                return(DomainValidationResult <object> .Failure("Summoner name is invalid"));
            }
        }
Exemplo n.º 8
0
        public async Task <DomainValidationResult <Invitation> > DeclineInvitationAsync(Invitation invitation, UserId userId)
        {
            if (invitation.UserId != userId)
            {
                return(DomainValidationResult <Invitation> .Failure($"The user {userId} can not decline someone else invitation."));
            }

            _invitationRepository.Delete(invitation);

            await _invitationRepository.UnitOfWork.CommitAsync();

            return(new DomainValidationResult <Invitation>());
        }
Exemplo n.º 9
0
        public async Task <DomainValidationResult <Invitation> > AcceptInvitationAsync(Invitation invitation, UserId userId)
        {
            if (invitation.UserId != userId)
            {
                return(DomainValidationResult <Invitation> .Failure($"The user {userId} can not accept someone else invitation."));
            }

            invitation.Accept();

            await _invitationRepository.UnitOfWork.CommitAsync();

            return(new DomainValidationResult <Invitation>());
        }
Exemplo n.º 10
0
        public async Task <DomainValidationResult <Candidature> > DeclineCandidatureAsync(Candidature candidature, UserId userId)
        {
            if (!await _clanRepository.IsOwnerAsync(candidature.ClanId, userId))
            {
                return(DomainValidationResult <Candidature> .Failure("Permission required."));
            }

            _candidatureRepository.Delete(candidature);

            await _candidatureRepository.UnitOfWork.CommitAsync();

            return(new DomainValidationResult <Candidature>());
        }
Exemplo n.º 11
0
        public async Task <DomainValidationResult <object> > UploadLogoAsync(
            Clan clan,
            UserId userId,
            Stream stream,
            string fileName
            )
        {
            if (!clan.MemberIsOwner(userId))
            {
                return(DomainValidationResult <object> .Failure($"The user ({userId}) isn't the clan owner."));
            }

            await _clanRepository.UploadLogoAsync(clan.Id, stream, fileName);

            return(new DomainValidationResult <object>());
        }
Exemplo n.º 12
0
        private async Task <DomainValidationResult <ITransaction> > CreateTransactionAsync(
            IMoneyAccount account,
            Money money,
            TransactionType type,
            TransactionMetadata?metadata        = null,
            CancellationToken cancellationToken = default
            )
        {
            if (type == TransactionType.Deposit)
            {
                return(await this.CreateDepositTransactionAsync(account, money, cancellationToken));
            }

            if (type == TransactionType.Withdraw)
            {
                return(await this.CreateWithdrawTransactionAsync(account, money, cancellationToken));
            }

            if (type == TransactionType.Charge)
            {
                return(await this.CreateChargeTransactionAsync(
                           account,
                           money,
                           metadata,
                           cancellationToken));
            }

            if (type == TransactionType.Payout)
            {
                return(await this.CreatePayoutTransactionAsync(
                           account,
                           money,
                           metadata,
                           cancellationToken));
            }

            if (type == TransactionType.Promotion)
            {
                return(await this.CreatePromotionTransactionAsync(
                           account,
                           money,
                           metadata,
                           cancellationToken));
            }

            return(DomainValidationResult <ITransaction> .Failure("Unsupported transaction type for money currency."));
        }
Exemplo n.º 13
0
        public async Task <DomainValidationResult <Member> > AddMemberToDivisionAsync(
            Clan clan,
            UserId userId,
            DivisionId divisionId,
            MemberId memberId
            )
        {
            if (!clan.MemberIsOwner(userId))
            {
                return(DomainValidationResult <Member> .Failure($"The user ({userId}) isn't the clan owner."));
            }

            clan.AddMemberToDivision(divisionId, memberId);
            await _clanRepository.UnitOfWork.CommitAsync();

            return(new DomainValidationResult <Member>());
        }
Exemplo n.º 14
0
        public async Task CancelPromotionAsync_ShouldBeBadRequestObjectResult()
        {
            // 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> .Failure("error message"))
            .Verifiable();

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

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

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

            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);
        }
Exemplo n.º 15
0
        public async Task <DomainValidationResult <Division> > UpdateDivisionAsync(
            Clan clan,
            UserId userId,
            DivisionId divisionId,
            string name,
            string description
            )
        {
            if (!clan.MemberIsOwner(userId))
            {
                return(DomainValidationResult <Division> .Failure($"The user ({userId}) isn't the clan owner."));
            }

            clan.UpdateDivision(divisionId, name, description);

            await _clanRepository.UnitOfWork.CommitAsync();

            return(new DomainValidationResult <Division>());
        }
Exemplo n.º 16
0
        public async Task CreatePromotionAsync_ShouldBeBadRequestObjectResult()
        {
            // Arrange
            TestMock.PromotionService
            .Setup(
                promotionService => promotionService.CreatePromotionAsync(
                    It.IsAny <string>(),
                    It.IsAny <Currency>(),
                    It.IsAny <TimeSpan>(),
                    It.IsAny <DateTime>()))
            .ReturnsAsync(DomainValidationResult <Promotion> .Failure("error message"))
            .Verifiable();

            var controller = new PromotionController(TestMock.PromotionService.Object, TestMapper);

            var request = new CreatePromotionRequest
            {
                Currency = new CurrencyDto
                {
                    Amount = 50,
                    Type   = EnumCurrencyType.Money
                },
                Duration        = new Duration(),
                ExpiredAt       = DateTime.UtcNow.ToTimestamp(),
                PromotionalCode = "code1"
            };

            // Act
            var result = await controller.CreatePromotionAsync(request);

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

            TestMock.PromotionService.Verify(
                promotionService => promotionService.CreatePromotionAsync(
                    It.IsAny <string>(),
                    It.IsAny <Currency>(),
                    It.IsAny <TimeSpan>(),
                    It.IsAny <DateTime>()),
                Times.Once);
        }
Exemplo n.º 17
0
        public async Task ShouldBeHttpStatusCodeBadRequest()
        {
            // Arrange
            var userId = new UserId();

            var credential = new Credential(
                userId,
                Game.LeagueOfLegends,
                new PlayerId(),
                new DateTimeProvider(DateTime.Now));

            var factory = TestHost.WithClaimsFromDefaultAuthentication(new Claim(JwtClaimTypes.Subject, userId.ToString()))
                          .WithWebHostBuilder(
                builder => builder.ConfigureTestContainer <ContainerBuilder>(
                    container =>
            {
                var mockCredentialService = new Mock <IGameCredentialService>();

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

                mockCredentialService.Setup(credentialService => credentialService.UnlinkCredentialAsync(It.IsAny <Credential>()))
                .ReturnsAsync(DomainValidationResult <Credential> .Failure("test", "validation failure test"))
                .Verifiable();

                container.RegisterInstance(mockCredentialService.Object).As <IGameCredentialService>().SingleInstance();
            }));

            _httpClient = factory.CreateClient();
            var testServer = factory.Server;

            testServer.CleanupDbContext();

            // Act
            using var response = await this.ExecuteAsync(Game.LeagueOfLegends);

            // Assert
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        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);
        }