Beispiel #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));
        }
Beispiel #2
0
        public async Task SetLakeVoteShouldUpdateVoteIfVoteAlreadyExists()
        {
            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, "user123", 5);

            await service.SetLakeVoteAsync(2, "user1234", 3);

            Assert.Equal(5, service.GetLakeAverageVote(1));
            Assert.Equal(3, service.GetLakeAverageVote(2));

            await service.SetLakeVoteAsync(1, "user123", 4);

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

            Assert.Equal(4, service.GetLakeAverageVote(1));
            Assert.Equal(2, service.GetLakeAverageVote(2));
        }