public async Task SetTrophyVoteShouldUpdateVoteIfVoteAlreadyExists() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using var db = new ApplicationDbContext(options); var trophyRepository = new EfDeletableEntityRepository <Trophy>(db); var lakeVoteRepository = new EfRepository <LakeVote>(db); var trophyVoteRepository = new EfRepository <TrophyVote>(db); var votesRepository = new EfRepository <Vote>(db); var service = new VotesService(lakeVoteRepository, trophyVoteRepository, votesRepository); await trophyRepository.AddAsync(new Trophy { Id = 1 }); await trophyRepository.AddAsync(new Trophy { Id = 2 }); await service.SetTrophyVoteAsync(1, "user123", 5); await service.SetTrophyVoteAsync(2, "user1234", 3); Assert.Equal(5, service.GetTrophyAverageVote(1)); Assert.Equal(3, service.GetTrophyAverageVote(2)); await service.SetTrophyVoteAsync(1, "user123", 4); await service.SetTrophyVoteAsync(2, "user1234", 2); Assert.Equal(4, service.GetTrophyAverageVote(1)); Assert.Equal(2, service.GetTrophyAverageVote(2)); }
public async Task GetTrophyRatersCountShouldWorkCorrect() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using var db = new ApplicationDbContext(options); var trophyRepository = new EfDeletableEntityRepository <Trophy>(db); var lakeVoteRepository = new EfRepository <LakeVote>(db); var trophyVoteRepository = new EfRepository <TrophyVote>(db); var votesRepository = new EfRepository <Vote>(db); var service = new VotesService(lakeVoteRepository, trophyVoteRepository, votesRepository); await trophyRepository.AddAsync(new Trophy { Id = 1 }); await trophyRepository.AddAsync(new Trophy { Id = 2 }); await trophyRepository.AddAsync(new Trophy { Id = 3 }); await service.SetTrophyVoteAsync(1, "someuserid123", 5); await service.SetTrophyVoteAsync(3, "someuserid1234", 5); await service.SetTrophyVoteAsync(3, "someuserid1235", 5); Assert.Equal(1, service.GetTrophyRatersCount(1)); Assert.Equal(0, service.GetTrophyRatersCount(2)); Assert.Equal(2, service.GetTrophyRatersCount(3)); }