public void CreateVotingPoll_PersistsCreatedPoll()
        {
            var poll = new VotingPoll();

            _mockFactory.Setup(x => x.Create(_request)).Returns(poll);

            _interactor.CreateVotingPoll(_request);

            _mockPersistance.Verify(x => x.SaveVotingPoll(poll));
        }
        public void DisplaysPollStatitstics()
        {
            var pollId   = 1;
            var counter1 = new Counter {
                Name = "One", Count = 2
            };
            var counter2 = new Counter {
                Name = "Two", Count = 1
            };

            var counterStats1 = new CounterStatistics {
                Name = "One", Count = 2, Percent = 60
            };
            var counterStats2 = new CounterStatistics {
                Name = "Two", Count = 1, Percent = 40
            };
            var counterStats = new List <CounterStatistics> {
                counterStats1, counterStats2
            };

            var poll = new VotingPoll
            {
                Title       = "title",
                Description = "desc",
                Counters    = new List <Counter> {
                    counter1, counter2
                }
            };

            _mockPersistance.Setup(x => x.GetPoll(pollId)).Returns(poll);
            _mockCounterManager.Setup(x => x.GetStatistics(poll.Counters)).Returns(counterStats);

            var interactor = new StatisticsInteractor(
                _mockPersistance.Object,
                _mockCounterManager.Object);

            var pollStatistics = interactor.GetStatistics(pollId);

            Assert.Equal(poll.Title, pollStatistics.Title);
            Assert.Equal(poll.Description, pollStatistics.Description);

            var stats1 = pollStatistics.Counters[0];

            Assert.Equal(counterStats1.Name, stats1.Name);
            Assert.Equal(counterStats1.Count, stats1.Count);
            Assert.Equal(counterStats1.Percent, stats1.Percent);

            var stats2 = pollStatistics.Counters[1];

            Assert.Equal(counterStats2.Name, stats2.Name);
            Assert.Equal(counterStats2.Count, stats2.Count);
            Assert.Equal(counterStats2.Percent, stats2.Percent);

            _mockCounterManager.Verify(x => x.ResolveExcess(counterStats), Times.Once);
        }
Пример #3
0
        public void GetPoll_ReturnsSavedPollWithCounters_AndVotesAsCount()
        {
            var poll = new VotingPoll
            {
                Title       = "title",
                Description = "desc",
                Counters    = new List <Counter> {
                    new Counter {
                        Name = "One"
                    },
                    new Counter {
                        Name = "Two"
                    }
                }
            };

            using (var ctx = DbContextFactory.Create(nameof(GetPoll_ReturnsSavedPollWithCounters_AndVotesAsCount)))
            {
                ctx.VotingPolls.Add(poll);
                ctx.Votes.Add(new Vote {
                    UserId = "a", CounterId = 1
                });
                ctx.Votes.Add(new Vote {
                    UserId = "b", CounterId = 1
                });
                ctx.Votes.Add(new Vote {
                    UserId = "c", CounterId = 2
                });
                ctx.SaveChanges();
            }

            using (var ctx = DbContextFactory.Create(nameof(GetPoll_ReturnsSavedPollWithCounters_AndVotesAsCount)))
            {
                var savedPoll = new VotingSystemPersistance(ctx).GetPoll(1);

                Equal(poll.Title, savedPoll.Title);
                Equal(poll.Description, savedPoll.Description);
                Equal(poll.Counters.Count(), savedPoll.Counters.Count());

                var counter1 = savedPoll.Counters[0];
                Equal(1, counter1.Id);
                Equal("One", counter1.Name);
                Equal(2, counter1.Count);

                var counter2 = savedPoll.Counters[1];
                Equal(2, counter2.Id);
                Equal("Two", counter2.Name);
                Equal(1, counter2.Count);
            }
        }
Пример #4
0
        public void SavesVotingPollToDatabase()
        {
            var poll = new VotingPoll {
                Title = "New VotingPoll"
            };

            using (var ctx = DbContextFactory.Create(nameof(SavesVotingPollToDatabase)))
            {
                ctx.VotingPolls.Add(poll);
                ctx.SaveChanges();
            }

            using (var ctx = DbContextFactory.Create(nameof(SavesVotingPollToDatabase)))
            {
                var savedPoll = ctx.VotingPolls.Single();
                Assert.Equal(poll.Title, savedPoll.Title);
            }
        }
        public void PersistsVotingPoll()
        {
            var poll = new VotingPoll
            {
                Title       = "title",
                Description = "desc",
                Counters    = new List <Counter>
                {
                    new Counter {
                        Name = "One"
                    },
                    new Counter {
                        Name = "Two"
                    }
                }
            };

            using (var ctx = DbContextFactory.Create(nameof(PersistsVotingPoll)))
            {
                IVotingSystemPersistance persistance = new VotingSystemPersistance(ctx);
                persistance.SaveVotingPoll(poll);
            }

            using (var ctx = DbContextFactory.Create(nameof(PersistsVotingPoll)))
            {
                var savePoll = ctx.VotingPolls
                               .Include(x => x.Counters)
                               .Single();

                Assert.Equal(poll.Title, savePoll.Title);
                Assert.Equal(poll.Description, savePoll.Description);
                Assert.Equal(poll.Counters.Count(), savePoll.Counters.Count());

                foreach (var name in poll.Counters.Select(x => x.Name))
                {
                    Assert.Contains(name, savePoll.Counters.Select(x => x.Name));
                }
            }
        }
Пример #6
0
        public void DisplaysPollStatistics()
        {
            var pollId = 1;
            var poll   = new VotingPoll
            {
                Title       = "title",
                Description = "desc",
                Counters    = new List <Counter>
                {
                    new Counter {
                        Name = "One"
                    },
                    new Counter {
                        Name = "Two"
                    }
                }
            };

            _mockPersistance.Setup(x => x.GetPoll(pollId)).Returns(poll);

            var interactor = new StatisticsInteractor(_mockPersistance.Object);

            var pollStatistics = interactor.GetStatistics(pollId);
        }
 public void SaveVotingPoll(VotingPoll votingPoll)
 {
     _ctx.VotingPolls.Add(votingPoll);
     _ctx.SaveChanges();
 }