public async Task Create_WithNoVotes_ShouldThrowArgumentNullException() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); this.votesService = new VotesService(dbContext); var testVotesService = new VotesServiceModel { Type = VoteType.UpVote, ServiceId = 1, UserId = Guid.NewGuid().ToString(), }; await Assert.ThrowsAsync <ArgumentNullException>(async() => await this.votesService.CreateVoteAsync(testVotesService)); }
public async Task <int> CreateVoteAsync(VotesServiceModel votesServiceModel) { var vote = await this.GetVoteByServiceAndUserId(votesServiceModel.ServiceId, votesServiceModel.UserId); if (vote != null) { vote.Type = votesServiceModel.IsUpVote ? VoteType.UpVote : VoteType.DownVote; } else { vote = AutoMapperConfig.MapperInstance.Map <Vote>(votesServiceModel); vote.Type = votesServiceModel.IsUpVote ? VoteType.UpVote : VoteType.DownVote; await this.dbContext.Votes.AddAsync(vote); } await this.dbContext.SaveChangesAsync(); return(vote.Id); }
public async Task Create_WithDummyData_ShouldReturnCorrectResult() { var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext(); await this.SeedData(dbContext); this.votesService = new VotesService(dbContext); var testVotesService = new VotesServiceModel { Type = VoteType.UpVote, ServiceId = 1, UserId = Guid.NewGuid().ToString(), }; var expectedResult = 3; var actualResult = await this.votesService.CreateVoteAsync(testVotesService); Assert.Equal(expectedResult, actualResult); }