public void ProcessIssuesAwardWhenConditionsEqualOrGreater() { var calc = GetCalc(); var eventDef = new EventDefinition { EventDefinitionID = "oi" }; var user = new User { UserID = 1 }; var awardDef = new AwardDefinition { AwardDefinitionID = "sweet", IsSingleTimeAward = true }; var conditions = new List <AwardCondition> { new AwardCondition { AwardDefinitionID = awardDef.AwardDefinitionID, EventDefinitionID = "qwerty", EventCount = 3 }, new AwardCondition { AwardDefinitionID = awardDef.AwardDefinitionID, EventDefinitionID = "asdfgh", EventCount = 5 } }; _awardCalcRepo.Setup(x => x.Dequeue()).Returns(new KeyValuePair <string, int>(eventDef.EventDefinitionID, user.UserID)); _eventDefService.Setup(x => x.GetEventDefinition(It.IsAny <string>())).Returns(eventDef); _userRepo.Setup(x => x.GetUser(It.IsAny <int>())).Returns(user); _awardDefService.Setup(x => x.GetByEventDefinitionID(eventDef.EventDefinitionID)).Returns(new List <AwardDefinition> { awardDef }); _userAwardService.Setup(x => x.IsAwarded(user, awardDef)).Returns(false); _awardDefService.Setup(x => x.GetConditions(awardDef.AwardDefinitionID)).Returns(conditions); _pointLedgerRepo.Setup(x => x.GetEntryCount(user.UserID, conditions[0].EventDefinitionID)).Returns(10); _pointLedgerRepo.Setup(x => x.GetEntryCount(user.UserID, conditions[1].EventDefinitionID)).Returns(5); calc.ProcessOneCalculation(); _userAwardService.Verify(x => x.IssueAward(It.IsAny <User>(), It.IsAny <AwardDefinition>()), Times.Once()); }
public void AddAwardCallsAdd() { var controller = GetController(); var awardDef = new AwardDefinition(); controller.AddAward(awardDef); _awardDefService.Verify(x => x.Create(awardDef), Times.Once()); }
public AwardDefinition Get(string awardDefinitionID) { AwardDefinition awardDefinition = null; _sqlObjectFactory.GetConnection().Using(connection => awardDefinition = connection.QuerySingleOrDefault <AwardDefinition>("SELECT AwardDefinitionID, Title, Description, IsSingleTimeAward FROM pf_AwardDefinition WHERE AwardDefinitionID = @AwardDefinitionID", new { AwardDefinitionID = awardDefinitionID })); return(awardDefinition); }
public void CreateMapsObjectToRepo() { var awardDef = new AwardDefinition { AwardDefinitionID = "blah", Title = "title", Description = "desc", IsSingleTimeAward = true }; var service = GetService(); service.Create(awardDef); _awardDefRepo.Verify(x => x.Create(awardDef.AwardDefinitionID, awardDef.Title, awardDef.Description, awardDef.IsSingleTimeAward), Times.Once()); }
public void SaveConditionsDeletesOldOnes() { var awardDef = new AwardDefinition { AwardDefinitionID = "awarddef" }; var service = GetService(); service.SaveConditions(awardDef, new List <AwardCondition>()); _awardConditionRepo.Verify(x => x.DeleteConditions(awardDef.AwardDefinitionID), Times.Once()); }
public void IssueMapsFieldsToRepoCall() { var user = new User(123, DateTime.MinValue); var awardDef = new AwardDefinition { AwardDefinitionID = "blah", Description = "desc", Title = "title", IsSingleTimeAward = true }; var service = GetService(); service.IssueAward(user, awardDef); _userAwardRepo.Verify(x => x.IssueAward(user.UserID, awardDef.AwardDefinitionID, awardDef.Title, awardDef.Description, It.IsAny <DateTime>()), Times.Once()); }
public void AwardGetsFromRepo() { var controller = GetController(); var awardDef = new AwardDefinition { AwardDefinitionID = "qwerty" }; _awardDefService.Setup(x => x.Get(awardDef.AwardDefinitionID)).Returns(awardDef); _eventDefService.Setup(x => x.GetAll()).Returns(new List <EventDefinition>()); var result = controller.Award(awardDef.AwardDefinitionID); Assert.AreSame(awardDef, result.Model); }
public void IsAwardedMapsAndReturnsRightValue() { var user = new User(123, DateTime.MinValue); var awardDef = new AwardDefinition { AwardDefinitionID = "blah" }; var service = GetService(); _userAwardRepo.Setup(x => x.IsAwarded(user.UserID, awardDef.AwardDefinitionID)).Returns(true); var result = service.IsAwarded(user, awardDef); Assert.IsTrue(result); }
public async Task IsAwardedMapsAndReturnsRightValue() { var user = new User { UserID = 123 }; var awardDef = new AwardDefinition { AwardDefinitionID = "blah" }; var service = GetService(); _userAwardRepo.Setup(x => x.IsAwarded(user.UserID, awardDef.AwardDefinitionID)).ReturnsAsync(true); var result = await service.IsAwarded(user, awardDef); Assert.True(result); }
public void AwardGetsConditions() { var controller = GetController(); var awardDef = new AwardDefinition { AwardDefinitionID = "qwerty" }; _awardDefService.Setup(x => x.Get(awardDef.AwardDefinitionID)).Returns(awardDef); _eventDefService.Setup(x => x.GetAll()).Returns(new List <EventDefinition>()); var conditions = new List <AwardCondition>(); _awardDefService.Setup(x => x.GetConditions(awardDef.AwardDefinitionID)).Returns(conditions); var result = controller.Award(awardDef.AwardDefinitionID); Assert.AreSame(conditions, result.ViewBag.Conditions); }
/// <summary> /// Construct a shoot. /// </summary> /// <param name="ball">The ball to shoot.</param> /// <param name="position">The position shoot to in the strip.</param> /// <param name="awardDefinition">The award of this shoot.</param> public Shoot(string ball, int position, AwardDefinition awardDefinition) { if (ball == null) { throw new ArgumentNullException("ball"); } if (awardDefinition == null) { throw new ArgumentNullException("awardDefinition"); } Ball = ball; Position = position; AwardDefinition = awardDefinition; }
public AwardDefinition Get(string awardDefinitionID) { AwardDefinition awardDefinition = null; _sqlObjectFactory.GetConnection().Using(connection => connection.Command("SELECT AwardDefinitionID, Title, Description, IsSingleTimeAward FROM pf_AwardDefinition WHERE AwardDefinitionID = @AwardDefinitionID") .AddParameter("@AwardDefinitionID", awardDefinitionID) .ExecuteReader() .ReadOne(r => awardDefinition = new AwardDefinition { AwardDefinitionID = r.GetString(0), Title = r.GetString(1), Description = r.GetString(2), IsSingleTimeAward = r.GetBoolean(3) })); return(awardDefinition); }
public void SaveConditionsSetsAllAwardDefIDs() { var awardDef = new AwardDefinition { AwardDefinitionID = "awarddef" }; var list = new List <AwardCondition> { new AwardCondition { AwardDefinitionID = "bad" }, new AwardCondition { AwardDefinitionID = "toobad" } }; var savingList = new List <AwardCondition>(); var service = GetService(); _awardConditionRepo.Setup(x => x.SaveConditions(It.IsAny <List <AwardCondition> >())).Callback <List <AwardCondition> >(x => savingList = x); service.SaveConditions(awardDef, list); Assert.AreEqual(savingList[0].AwardDefinitionID, awardDef.AwardDefinitionID); Assert.AreEqual(savingList[1].AwardDefinitionID, awardDef.AwardDefinitionID); }
public void ProcessNeverCallsIssueIfAwardedAndSingleAward() { var calc = GetCalc(); var eventDef = new EventDefinition { EventDefinitionID = "oi" }; var user = new User(); var awardDef = new AwardDefinition { AwardDefinitionID = "sweet", IsSingleTimeAward = true }; _awardCalcRepo.Setup(x => x.Dequeue()).Returns(new KeyValuePair <string, int>(eventDef.EventDefinitionID, user.UserID)); _eventDefService.Setup(x => x.GetEventDefinition(It.IsAny <string>())).Returns(eventDef); _userRepo.Setup(x => x.GetUser(It.IsAny <int>())).Returns(user); _awardDefService.Setup(x => x.GetByEventDefinitionID(eventDef.EventDefinitionID)).Returns(new List <AwardDefinition> { awardDef }); _userAwardService.Setup(x => x.IsAwarded(user, awardDef)).Returns(true); calc.ProcessOneCalculation(); _userAwardService.Verify(x => x.IssueAward(It.IsAny <User>(), It.IsAny <AwardDefinition>()), Times.Never()); }
public async Task ProcessNeverCallsIfEventCountNotHighEnough() { var calc = GetCalc(); var eventDef = new EventDefinition { EventDefinitionID = "oi" }; var user = new User { UserID = 1 }; var awardDef = new AwardDefinition { AwardDefinitionID = "sweet", IsSingleTimeAward = true }; var conditions = new List <AwardCondition> { new AwardCondition { AwardDefinitionID = awardDef.AwardDefinitionID, EventDefinitionID = "qwerty", EventCount = 3 }, new AwardCondition { AwardDefinitionID = awardDef.AwardDefinitionID, EventDefinitionID = "asdfgh", EventCount = 5 } }; _awardCalcRepo.Setup(x => x.Dequeue()).ReturnsAsync(new KeyValuePair <string, int>(eventDef.EventDefinitionID, user.UserID)); _eventDefService.Setup(x => x.GetEventDefinition(It.IsAny <string>())).ReturnsAsync(eventDef); _userRepo.Setup(x => x.GetUser(It.IsAny <int>())).ReturnsAsync(user); _awardDefService.Setup(x => x.GetByEventDefinitionID(eventDef.EventDefinitionID)).ReturnsAsync(new List <AwardDefinition> { awardDef }); _userAwardService.Setup(x => x.IsAwarded(user, awardDef)).ReturnsAsync(false); _awardDefService.Setup(x => x.GetConditions(awardDef.AwardDefinitionID)).ReturnsAsync(conditions); _pointLedgerRepo.Setup(x => x.GetEntryCount(user.UserID, conditions[0].EventDefinitionID)).ReturnsAsync(10); _pointLedgerRepo.Setup(x => x.GetEntryCount(user.UserID, conditions[1].EventDefinitionID)).ReturnsAsync(4); await calc.ProcessCalculation(eventDef.EventDefinitionID, user.UserID); _userAwardService.Verify(x => x.IssueAward(It.IsAny <User>(), It.IsAny <AwardDefinition>()), Times.Never()); }
public async Task <ActionResult> CreateAward([FromBody] AwardDefinition newAward) { await _awardDefinitionService.Create(newAward); return(Ok()); }
public ActionResult AddAward(AwardDefinition awardDefinition) { _awardDefinitionService.Create(awardDefinition); return(RedirectToAction("Award", new { id = awardDefinition.AwardDefinitionID })); }
public ActionResult CreateAward([FromBody] AwardDefinition newAward) { _awardDefinitionService.Create(newAward); return(Ok()); }