Пример #1
0
        public async Task GetLakeRatersCountByValueShouldWorkCorrect()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using var db = new ApplicationDbContext(options);
            var lakeRepository       = new EfDeletableEntityRepository <Lake>(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 lakeRepository.AddAsync(new Lake { Id = 1 });

            await lakeRepository.AddAsync(new Lake { Id = 2 });

            await service.SetLakeVoteAsync(1, "someuserid123", 5);

            await service.SetLakeVoteAsync(1, "someuserid1234", 5);

            await service.SetLakeVoteAsync(2, "someuserid12345", 2);

            Assert.Equal(2, service.GetLakeRatersCountByValue(1, 5));
            Assert.Equal(0, service.GetLakeRatersCountByValue(1, 4));

            Assert.Equal(1, service.GetLakeRatersCountByValue(2, 2));
        }