예제 #1
0
        public virtual void AddVote(int projectId, string userId, string socialName)
        {
            socialName = socialName.ToLower();

            if (socialName != "facebook" &&
                socialName != "draugiem")
            {
                throw new InvalidSocialMediaException();
            }

            if (repo.HasUserVotedToday(userId, projectId, socialName))
            {
                throw new UserAlreadyVotedException();
            }

            var vote = new Vote
            {
                UserId         = userId,
                ProjectId      = projectId,
                VotingDateTime = DateTime.Now,
                SocialName     = socialName
            };

            repo.Add(vote);
        }
예제 #2
0
        public void When_create_campaign_and_and_projects_in_campaign_and_add_some_votes_then_return_back_count_of_projects_and_count_of_project_votes()
        {
            var campaign = new CampaignRepoTests().CreateCampaign();
            var project1 = CreateProject(campaign.Id);
            var project2 = CreateProject(campaign.Id);
            var project3 = CreateProject(campaign.Id);

            var voteRepo = new VoteRepo(GetDbOptions());

            voteRepo.Add(new Vote()
            {
                UserId         = "ppppffpfp",
                VotingDateTime = DateTime.Today.AddDays(-5),
                SocialName     = "facebook",
                ProjectId      = project1.Id
            });

            voteRepo.Add(new Vote()
            {
                UserId         = "ppppfp",
                VotingDateTime = DateTime.Today.AddDays(-15),
                SocialName     = "facebook",
                ProjectId      = project2.Id
            });

            voteRepo.Add(new Vote()
            {
                UserId         = "pppd",
                VotingDateTime = DateTime.Today.AddDays(-3),
                SocialName     = "facebook",
                ProjectId      = project2.Id
            });

            var report = repo.GetProjectsReport(campaign.Id);

            Assert.Equal(3, report.Count);
            Assert.Equal(project1.Id, report[0].Project.Id);
            Assert.Equal(project2.Id, report[1].Project.Id);
            Assert.Equal(project3.Id, report[2].Project.Id);

            Assert.Equal(1, report[0].Votes);
            Assert.Equal(2, report[1].Votes);
            Assert.Equal(0, report[2].Votes);
        }
예제 #3
0
        public Vote CreateVote(bool isAddedToDb = true)
        {
            var userId = Guid.NewGuid().ToString();

            var project = new ProjectRepoTests().CreateProject();

            var vote = new Vote
            {
                UserId         = userId,
                ProjectId      = project.Id,
                VotingDateTime = DateTime.Now,
                SocialName     = "facebook"
            };

            if (isAddedToDb)
            {
                repo.Add(vote);
            }

            return(vote);
        }