Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public void GetLakeAverageVoteShouldReturnIfLakeVotesIsNull()
        {
            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);

            Assert.Equal(0, service.GetLakeAverageVote(1));
        }