示例#1
0
        public void ProcessClaimTweet()
        {
            //Arrange
            repo.Campaigns.InsertOnSubmit(new Campaign {CampaignID = 1, Name = "testCampaign", Value = 1});
            repo.SubmitChanges();
            int campaignId = repo.Campaigns.Where(c => c.Name == "testCampaign").FirstOrDefault().CampaignID;
            repo.Tokens.InsertOnSubmit(new Token {AllowedRedemptions = 1, CampaignID = campaignId, Code = "testToken"});
            repo.SubmitChanges();

            var claim = new ClaimTweet();
            claim.Token = "testToken";
            var benadderson = repo.Users.Where(u => u.Username == "benadderson").FirstOrDefault();

            //Act

            processor.ProcessTweet(benadderson, claim);
            repo.SubmitChanges();

            var storedRedemption = repo.Redemptions.Where(r => r.Username == "benadderson").FirstOrDefault();

            //Assert
            Assert.NotNull(storedRedemption);
            Assert.True(storedRedemption.Token.Campaign.Name == "testCampaign");
            Assert.True(storedRedemption.Token.Code == "testToken");
        }
示例#2
0
        public void ProcessTweet(User user, ClaimTweet tweet)
        {
            // The following line would throw an exception if multiple results for the same token,
            // but this is taken care of by a unique constraint in the DB
            Token token = _repo
                .Tokens
                .Where(t => t.Code == tweet.Token)
                .SingleOrDefault();

            if (token != null)
            {
                // Only process if they haven't yet redeemed this token
                // and the total number of redemptions hasn't exceeded the limit
                if (_repo.Redemptions.Where(r => r.User == user && r.TokenID == token.TokenID).Count() == 0
                    && _repo.Redemptions.Where(r => r.TokenID == token.TokenID).Count() < token.AllowedRedemptions)
                {
                    _repo.Redemptions.InsertOnSubmit(new Redemption
                                                         {
                                                             Created = DateTime.Now,
                                                             Username = user.Username,
                                                             TokenID = token.TokenID
                                                         });

                    CreditPoints(user, token.Campaign.Value, "Token: " + token.Code);
                }
            }
        }