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(); } }
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()); } }
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); } } }
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)); } }
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); } }
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); } }
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); } } }
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()); } } }