public void VotingCandidateIsActiveInitially()
        {
            // Arrange
            var votingCandidate = new VotingCandidate();

            // Assert
            Assert.That(votingCandidate.IsActive, Is.True);
        }
예제 #2
0
        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());
        }
예제 #3
0
        public void Validate_WithActiveVotingCandidate_DoesNotThrowException()
        {
            // Arrange
            var vote            = new Vote();
            var votingCandidate = new VotingCandidate();

            vote.VotingCandidate = votingCandidate;

            // Act
            vote.Validate();

            // Assert
            Assert.Pass();
        }
예제 #4
0
        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);
        }
예제 #5
0
        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));
        }
예제 #6
0
        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);
        }
예제 #8
0
        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);
        }