예제 #1
0
        public async Task FindChallengeAsync_FromRepository_ShouldNotBeNull()
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(1, Game.LeagueOfLegends);

            var fakeChallenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var repository = new ChallengeRepository(context);

                repository.Create(fakeChallenge);

                await repository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var repository = new ChallengeRepository(context);

                //Act
                var challenge = await repository.FindChallengeOrNullAsync(fakeChallenge.Id);

                //Assert
                challenge.Should().NotBeNull();
            }
        }
예제 #2
0
        public async Task FindChallengeParticipantsAsync_ShouldBeEquivalentToParticipantList(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(68545632, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var participantQuery = new ParticipantQuery(context);

                //Act
                var participants = await participantQuery.FetchChallengeParticipantsAsync(challenge.Id);

                //Assert
                participants.Should().BeEquivalentTo(challenge.Participants.ToList());
            }
        }
예제 #3
0
        public async Task FindParticipantAsync_EquivalentToParticipant(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(48956632, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var participantQuery = new ParticipantQuery(context);

                foreach (var participant in challenge.Participants)
                {
                    //Act
                    var participantAsync = await participantQuery.FindParticipantAsync(ParticipantId.FromGuid(participant.Id));

                    //Assert
                    participantAsync.Should().BeEquivalentTo(participant);
                }
            }
        }
예제 #4
0
        public async Task FetchChallengesAsync_ShouldHaveCount(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(84936374, game);

            var fakeChallenges = challengeFaker.FakeChallenges(4);

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(fakeChallenges);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var challengeQuery = new ChallengeQuery(context);

                //Act
                var challenges = await challengeQuery.FetchChallengesAsync(game, state);

                //Assert
                challenges.Should().HaveCount(fakeChallenges.Count(challenge => challenge.Game == game && challenge.Timeline == state));
            }
        }
예제 #5
0
        public async Task FetchUserChallengeHistoryAsync_WhenChallengeQuery_ShouldBeChallenge(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(84566374, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var challengeQuery = new ChallengeQuery(context);

                //Act
                var challenges = await challengeQuery.FetchUserChallengeHistoryAsync(challenge.Participants.First().UserId, game, state);

                //Assert
                challenges.Single().Should().Be(challenge);
            }
        }
예제 #6
0
        public async Task FindChallengeAsync_ShouldBeChallenge(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(84568994, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var challengeQuery = new ChallengeQuery(context);

                //Act
                var challengeAsync = await challengeQuery.FindChallengeAsync(challenge.Id);

                //Assert
                challengeAsync.Should().Be(challenge);
            }
        }
예제 #7
0
        public async Task FindMatchAsync_ShouldBeEquivalentToMatch(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(83459632, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var matchQuery = new MatchQuery(context);

                foreach (var match in challenge.Participants.SelectMany(participant => participant.Matches).ToList())
                {
                    //Act
                    var matchAsync = await matchQuery.FindMatchAsync(MatchId.FromGuid(match.Id));

                    //Arrange
                    matchAsync.Should().BeEquivalentTo(match);
                }
            }
        }
예제 #8
0
        public async Task FindParticipantMatchesAsync_ShouldBeEquivalentToParticipantMatchList(Game game, ChallengeState state)
        {
            //Arrange
            var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(89568322, game, state);

            var challenge = challengeFaker.FakeChallenge();

            using var factory = new InMemoryDbContextFactory <ChallengesDbContext>();

            await using (var context = factory.CreateContext())
            {
                var challengeRepository = new ChallengeRepository(context);

                challengeRepository.Create(challenge);

                await challengeRepository.CommitAsync();
            }

            await using (var context = factory.CreateContext())
            {
                var matchQuery = new MatchQuery(context);

                foreach (var participant in challenge.Participants)
                {
                    //Act
                    var matches = await matchQuery.FetchParticipantMatchesAsync(ParticipantId.FromGuid(participant.Id));

                    //Arrange
                    matches.Should().BeEquivalentTo(participant.Matches.ToList());
                }
            }
        }