public void TestThat_Leaderboard_LimitsTheNumberOfSessions()
        {
            var dataProvider = new DataProviderBuilder().WithLeaderboard(new[] { new SessionLeaderBoardEntry() }).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            controller.Leaderboard(123);

            dataProvider.Received().GetLeaderBoard(123, Arg.Any <bool>());
        }
        public void TestThat_GetSessionsVotedForByKnownUser_ObtainsTheSessionsForTheSpecifiedUser()
        {
            var dataProvider = new DataProviderBuilder().Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            controller.GetSessionsVotedForByKnownUser(1234);

            dataProvider.Received().GetVotedForSessions(1234);
        }
        public void TestThat_Leaderboard_ForbidsDuplicateSpeakers()
        {
            var dataProvider = new DataProviderBuilder().WithLeaderboard(new[] { new SessionLeaderBoardEntry() }).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            controller.Leaderboard(123, false);

            dataProvider.Received().GetLeaderBoard(Arg.Any <int>(), false);
        }
        public void TestThat_AnonymousUserVotes_GetsItsDataFromTheDataProvider()
        {
            var dataProvider = new DataProviderBuilder().Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            controller.AnonymousUserVotes();

            dataProvider.Received().GetAnonymousUserVotes();
        }
        public void TestThat_VotesForIPAddress_SetsTheVotesObtainedFromTheDataProviderOnTheModel()
        {
            var votes        = new[] { new CookieVoteModel(), new CookieVoteModel() };
            var dataProvider = new DataProviderBuilder().WithVotesForIPAddresses(votes).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.VotesForIPAddress("1.2.3.4").GetViewModel <VotesForIpAddressViewModel>();

            CollectionAssert.AreEquivalent(votes, model.DistinctVotes);
        }
        public void TestThat_IPAddresses_SetsTheSessionsObtainedFromTheDataProviderOnTheModel()
        {
            var votes        = new[] { new VotesForIPAddressModel(), new VotesForIPAddressModel() };
            var dataProvider = new DataProviderBuilder().WithVotesForDistinctIPAddresses(votes).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.IPAddresses().GetViewModel <IPAddressStatsViewModel>();

            CollectionAssert.AreEquivalent(votes, model.IPAddresses);
        }
        public void TestThat_GetSessionsVotedForByAnonymousUser_ObtainsTheSessionsForTheSpecifiedCookieId()
        {
            var dataProvider = new DataProviderBuilder().Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();
            var cookieId     = Guid.NewGuid();

            controller.GetSessionsVotedForByAnonymousUser(cookieId);

            dataProvider.Received().GetVotedForSessions(cookieId);
        }
        public void TestThat_Leaderboard_SetsTheSessionsObtainedFromTheDataProviderOnTheModel()
        {
            var sessions     = new[] { new SessionLeaderBoardEntry(), new SessionLeaderBoardEntry() };
            var dataProvider = new DataProviderBuilder().WithLeaderboard(sessions).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.Leaderboard().GetViewModel <LeaderboardViewModel>();

            CollectionAssert.AreEquivalent(sessions, model.Sessions);
        }
        public void TestThat_VotesForIPAddress_SetsTheIPAddressOnTheModel()
        {
            var votes        = new[] { new CookieVoteModel(), new CookieVoteModel() };
            var dataProvider = new DataProviderBuilder().WithVotesForIPAddresses(votes).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.VotesForIPAddress("1.2.3.4").GetViewModel <VotesForIpAddressViewModel>();

            Assert.That(model.IPAddress, Is.EqualTo("1.2.3.4"));
        }
        public void TestThat_VotersPerIPAddress_SetsTheVotersObtainedFromTheDataProviderOnTheModel()
        {
            var voters       = new[] { new IPAddressVoterModel(), new IPAddressVoterModel() };
            var dataProvider = new DataProviderBuilder().WithVotersForIPAddresses(voters).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.VotersPerIPAddress().GetViewModel <VotersPerIPAddressViewModel>();

            CollectionAssert.AreEquivalent(voters, model.IPAddressVoters);
        }
        public void TestThat_Index_DoesNotCalculateTheNumberOfDaysOfVotingPassedGreaterThanTheTotalNumberOfAllowableVotingDays()
        {
            var dataProvider = new DataProviderBuilder()
                               .WithNumberOfDaysSinceVotingOpened(25)
                               .WithNumberOfDaysOfVoting(10)
                               .Build();
            var controller = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.Index().GetViewModel <VotingStatsViewModel>();

            Assert.That(model.NumberOfDaysOfVotingPassed, Is.EqualTo(10));
        }
        public void TestThat_Index_DoesNotCalculateGreaterThanOneHunderdPercent_ForTheDurationThroughTheVotingPeriod()
        {
            var dataProvider = new DataProviderBuilder()
                               .WithNumberOfDaysSinceVotingOpened(25)
                               .WithNumberOfDaysOfVoting(10)
                               .Build();
            var controller = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.Index().GetViewModel <VotingStatsViewModel>();

            Assert.That(model.VotingCompletePercentage, Is.EqualTo(100));
        }
        public void TestThat_Index_CalculatesTheCorrectPercentage_ForTheDurationThroughTheVotingPeriod(
            int numberOfDaysSinceVotingOpened, int numberOfDaysVoting, int expectedPercentageCompletion)
        {
            var dataProvider = new DataProviderBuilder()
                               .WithNumberOfDaysSinceVotingOpened(numberOfDaysSinceVotingOpened)
                               .WithNumberOfDaysOfVoting(numberOfDaysVoting)
                               .Build();
            var controller = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.Index().GetViewModel <VotingStatsViewModel>();

            Assert.That(model.VotingCompletePercentage, Is.EqualTo(expectedPercentageCompletion));
        }
        public void TestThat_NumberOfUsersWhoHaveCastXVotes_UsesTheDataObtainedFromTheDataProvider_ToCreateTheChartData()
        {
            var voteCounts         = new[] { new NumberOfUsersWithVotesModel() };
            var dataProvider       = new DataProviderBuilder().WithNumberOfVotesCastCounts(voteCounts).Build();
            var chartDataConverter = new ChartDataConverterBuilder().Build();
            var controller         = new VotingControllerBuilder().WithDataProvider(dataProvider)
                                     .WithChartDataConverter(chartDataConverter)
                                     .Build();

            controller.NumberOfUsersWhoHaveCastXVotes();

            chartDataConverter.Received().ToChartData(voteCounts);
        }
        public void TestThat_Leaderboard_SetsTheHighestOccuringNumberOfVotesOnTheModel()
        {
            var sessions = new[] { new SessionLeaderBoardEntry {
                                       NumberOfVotes = 2
                                   }, new SessionLeaderBoardEntry {
                                       NumberOfVotes = 4
                                   } };
            var dataProvider = new DataProviderBuilder().WithLeaderboard(sessions).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.Leaderboard().GetViewModel <LeaderboardViewModel>();

            Assert.That(model.HighestVoteCount, Is.EqualTo(4));
        }
        public void TestThat_IPAddresses_SetsTheHighestOccuringNumberOfVotesOnTheModel()
        {
            var votes = new[] { new VotesForIPAddressModel {
                                    NumberOfVotes = 2
                                }, new VotesForIPAddressModel {
                                    NumberOfVotes = 4
                                } };
            var dataProvider = new DataProviderBuilder().WithVotesForDistinctIPAddresses(votes).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.IPAddresses().GetViewModel <IPAddressStatsViewModel>();

            Assert.That(model.HighestVoteCount, Is.EqualTo(4));
        }
        public void TestThat_VotesPerDay_UsesTheDataObtainedFromTheDataProvider_ToCreateTheChartData()
        {
            var votes              = new[] { new DayOfWeekVoteModel() };
            var dataProvider       = new DataProviderBuilder().WithVotesPerDay(votes).Build();
            var chartDataConverter = new ChartDataConverterBuilder().Build();
            var controller         = new VotingControllerBuilder()
                                     .WithDataProvider(dataProvider)
                                     .WithChartDataConverter(chartDataConverter)
                                     .Build();

            controller.VotesPerDay();

            chartDataConverter.Received().ToChartData(votes);
        }
        public void TestThat_VotesPerHour_UsesTheDataObtainedFromTheDataProvider_ToCreateTheChartData()
        {
            var votes              = new[] { new DateTimeVoteModel() };
            var dataProvider       = new DataProviderBuilder().WithVotesPerHour(votes).Build();
            var chartDataConverter = new ChartDataConverterBuilder().Build();
            var controller         = new VotingControllerBuilder()
                                     .WithDataProvider(dataProvider)
                                     .WithChartDataConverter(chartDataConverter)
                                     .Build();

            controller.VotesPerHour();

            chartDataConverter.Received().ToChartData(votes, Arg.Any <Func <DateTimeVoteModel, long> >());
        }
        public void TestThat_VotesForIPAddress_SetsTheHighestOccuringNumberOfVotesOnTheModel()
        {
            var votes = new[] { new CookieVoteModel {
                                    NumberOfVotes = 2
                                }, new CookieVoteModel {
                                    NumberOfVotes = 4
                                } };
            var dataProvider = new DataProviderBuilder().WithVotesForIPAddresses(votes).Build();
            var controller   = new VotingControllerBuilder().WithDataProvider(dataProvider).Build();

            var model = controller.VotesForIPAddress("1.2.3.4").GetViewModel <VotesForIpAddressViewModel>();

            Assert.That(model.HighestNumberOfVotes, Is.EqualTo(4));
        }