public void VotingCandidateIsActiveInitially() { // Arrange var votingCandidate = new VotingCandidate(); // Assert Assert.That(votingCandidate.IsActive, Is.True); }
public void Validate_WithInactiveVotingCandidate_ThrowsException() { // Arrange var vote = new Vote(); var votingCandidate = new VotingCandidate { IsActive = false }; vote.VotingCandidate = votingCandidate; // Act & Assert Assert.Throws <ValidationException>(() => vote.Validate()); }
public void Validate_WithActiveVotingCandidate_DoesNotThrowException() { // Arrange var vote = new Vote(); var votingCandidate = new VotingCandidate(); vote.VotingCandidate = votingCandidate; // Act vote.Validate(); // Assert Assert.Pass(); }
public async Task <Vote> UpdateOrCreateAsync(VotingCandidate votingCandidate, Guid userIdentifier) { var vote = await _voteRepository.GetByUserIdentifierOrDefaultAsync(userIdentifier); if (vote == null) { vote = _voteRepository.Create(); _voteRepository.Add(vote); } vote.Map(votingCandidate, userIdentifier); vote.Validate(); return(vote); }
public void Map_MapsAllProperties() { // Arrange var vote = new Vote(); var votingCandidate = new VotingCandidate(); var userIdentifier = Guid.NewGuid(); // Act vote.Map(votingCandidate, userIdentifier); // Assert Assert.That(vote.VotingCandidateId, Is.EqualTo(votingCandidate.Id)); Assert.That(vote.VotingCandidate, Is.EqualTo(votingCandidate)); Assert.That(vote.UserIdentifier, Is.EqualTo(userIdentifier)); }
public void UpdateOrCreate_WithInactiveVotingCandidate_ThrowsException_OnUpdate() { // Arrange var votingCandidate = new VotingCandidate { IsActive = false }; var userIdentifier = Guid.NewGuid(); _voteRepository.GetByUserIdentifierOrDefaultAsync(userIdentifier).Returns(Task.FromResult(new Vote())); // Act & Assert Assert.ThrowsAsync <ValidationException>(() => _voteService.UpdateOrCreateAsync(votingCandidate, userIdentifier)); }
public void Map_MapsAllProperties() { // Arrange var votingCandidate = new VotingCandidate(); var song = new Song(); var displayOrder = 22; // Act votingCandidate.Map(song, displayOrder); // Assert Assert.That(votingCandidate.SongId, Is.EqualTo(song.Id)); Assert.That(votingCandidate.Song, Is.EqualTo(song)); Assert.That(votingCandidate.DisplayOrder, Is.EqualTo(displayOrder)); Assert.That(votingCandidate.Votes, Is.Not.Null); }
public async Task UpdateOrCreate_WithUserVote_DoesNotCreateNewVote() { // Arrange var votingCandidate = new VotingCandidate(); var userIdentifier = Guid.NewGuid(); _voteRepository.GetByUserIdentifierOrDefaultAsync(userIdentifier).Returns(Task.FromResult(new Vote())); // Act var vote = await _voteService.UpdateOrCreateAsync(votingCandidate, userIdentifier); // Assert Assert.That(vote.VotingCandidateId, Is.EqualTo(votingCandidate.Id)); Assert.That(vote.VotingCandidate, Is.EqualTo(votingCandidate)); Assert.That(vote.UserIdentifier, Is.EqualTo(userIdentifier)); _voteRepository.Received(0).Create(); _voteRepository.Received(0).Add(vote); }