public void GetVoterTurnout_WithNoVotes_ReturnsZeroTurnout()
        {
            // Arrange
            var couchDbMock = new Mock<ICouchDBService>();
            couchDbMock.Setup(c => c.FindByLevel<User>(It.Is<Level>(l => l == Level.A))).Returns(new[]
            {
                new User { Username = "******", Level = Level.A },
                new User { Username = "******", Level = Level.A },
                new User { Username = "******", Level = Level.A }
            });

            // Act
            var votingService = new VotingService(couchDbMock.Object);
            var turnouts = votingService.GetVoterTurnout();

            // Assert
            Assert.AreEqual(0, turnouts[Level.A]);
        }
        public void GetVoterTurnout_WithMatchingUsersAndVotes_CalculatesCorrectTurnout()
        {
            // Arrange - create 5 distinct users, both A and AC, out of which one user from each level has
            // voted (which should give a turnout of 33.3% for A and 50% for AC).
            var couchDbMock = new Mock<ICouchDBService>();
            couchDbMock.Setup(c => c.FindByLevel<User>(It.Is<Level>(l => l == Level.A))).Returns(new[]
            {
                new User { Username = "******", Level = Level.A },
                new User { Username = "******", Level = Level.A },
                new User { Username = "******", Level = Level.A }
            });
            couchDbMock.Setup(c => c.FindByUsername<Vote>(It.Is<string>(n => n == "*****@*****.**"))).Returns(new[]
            {
                new Vote { Username = "******" },
                new Vote { Username = "******" },
                new Vote { Username = "******" }
            });

            couchDbMock.Setup(c => c.FindByLevel<User>(It.Is<Level>(l => l == Level.AC))).Returns(new[]
            {
                new User { Username = "******", Level = Level.AC },
                new User { Username = "******", Level = Level.AC }
            });
            couchDbMock.Setup(c => c.FindByUsername<Vote>(It.Is<string>(n => n == "*****@*****.**"))).Returns(new[]
            {
                new Vote { Username = "******" },
                new Vote { Username = "******" },
                new Vote { Username = "******" }
            });

            // Act
            var votingService = new VotingService(couchDbMock.Object);
            var turnouts = votingService.GetVoterTurnout();

            // Assert
            Assert.AreEqual(33.3, turnouts[Level.A]);
            Assert.AreEqual(50.0, turnouts[Level.AC]);
        }
        public void GetVoterTurnout_WithNoMatchingUsers_ReturnsEmptyResult()
        {
            // Arrange
            var couchDbMock = new Mock<ICouchDBService>();
            couchDbMock.Setup(c => c.FindByLevel<User>(It.IsAny<Level>())).Returns(new List<User>());

            // Act
            var votingService = new VotingService(couchDbMock.Object);
            var turnouts = votingService.GetVoterTurnout();

            // Assert
            Assert.AreEqual(0, turnouts.Keys.Count);
        }