public void CreatePassesToRepo()
		{
			var service = GetService();
			var eventDef = new EventDefinition();
			service.Create(eventDef);
			_eventDefRepo.Verify(x => x.Create(eventDef), Times.Once());
		}
		public void GetReturnsFromRepo()
		{
			var service = GetService();
			var def = new EventDefinition {EventDefinitionID = "whatevs", PointValue = 2, Description = "stuff"};
			_eventDefRepo.Setup(x => x.Get(def.EventDefinitionID)).Returns(def);
			var result = service.GetEventDefinition(def.EventDefinitionID);
			Assert.AreSame(def, result);
		}
Ejemplo n.º 3
0
		public void EnqueueDoesWhatItSaysItShould()
		{
			var calc = GetCalc();
			var user = new User(1, DateTime.MinValue);
			var eventDef = new EventDefinition {EventDefinitionID = "blah"};
			calc.QueueCalculation(user, eventDef);
			_awardCalcRepo.Verify(x => x.Enqueue(eventDef.EventDefinitionID, user.UserID), Times.Once());
		}
Ejemplo n.º 4
0
		public void ProcessManualEvent(string feedMessage, User user, int pointValue)
		{
			var timeStamp = DateTime.UtcNow;
			var eventDefinition = new EventDefinition { EventDefinitionID = "Manual", PointValue = pointValue };
			var ledgerEntry = new PointLedgerEntry { UserID = user.UserID, EventDefinitionID = eventDefinition.EventDefinitionID, Points = eventDefinition.PointValue, TimeStamp = timeStamp };
			_pointLedgerRepository.RecordEntry(ledgerEntry);
			_profileService.UpdatePointTotal(user);
			_feedService.PublishToFeed(user, feedMessage, eventDefinition.PointValue, timeStamp);
		}
Ejemplo n.º 5
0
		public void ProcessEventDoesNotPublishToFeedServiceForActivityWhenEventDefSaysNo()
		{
			var user = new User(123, DateTime.MinValue);
			var eventDef = new EventDefinition { EventDefinitionID = "blah", PointValue = 42, IsPublishedToFeed = false };
			const string message = "msg";
			var publisher = GetPublisher();
			_eventDefService.Setup(x => x.GetEventDefinition(eventDef.EventDefinitionID)).Returns(eventDef);
			publisher.ProcessEvent(message, user, eventDef.EventDefinitionID, false);
			_feedService.Verify(x => x.PublishToActivityFeed(message), Times.Never());
		}
		public void Create(EventDefinition eventDefinition)
		{
			_sqlObjectFactory.GetConnection().Using(connection =>
				connection.Command("INSERT INTO pf_EventDefinition (EventDefinitionID, Description, PointValue, IsPublishedToFeed) VALUES (@EventDefinitionID, @Description, @PointValue, @IsPublishedToFeed)")
				.AddParameter("@EventDefinitionID", eventDefinition.EventDefinitionID)
				.AddParameter("@Description", eventDefinition.Description.NullToEmpty())
				.AddParameter("@PointValue", eventDefinition.PointValue)
				.AddParameter("@IsPublishedToFeed", eventDefinition.IsPublishedToFeed)
				.ExecuteNonQuery());
		}
		public EventDefinition Get(string eventDefinitionID)
		{
			EventDefinition eventDef = null;
			_sqlObjectFactory.GetConnection().Using(connection =>
				connection.Command("SELECT EventDefinitionID, Description, PointValue, IsPublishedToFeed FROM pf_EventDefinition WHERE EventDefinitionID = @EventDefinitionID")
				.AddParameter("@EventDefinitionID", eventDefinitionID)
				.ExecuteReader()
				.ReadOne(r => eventDef = new EventDefinition { EventDefinitionID = r.GetString(0), Description = r.GetString(1), PointValue = r.GetInt32(2), IsPublishedToFeed = r.GetBoolean(3) }));
			return eventDef;
		}
Ejemplo n.º 8
0
		public void ProcessEventPublishesToFeedService()
		{
			var user = new User(123, DateTime.MinValue);
			var eventDef = new EventDefinition { EventDefinitionID = "blah", PointValue = 42, IsPublishedToFeed = true };
			const string message = "msg";
			var publisher = GetPublisher();
			_eventDefService.Setup(x => x.GetEventDefinition(eventDef.EventDefinitionID)).Returns(eventDef);
			publisher.ProcessEvent(message, user, eventDef.EventDefinitionID, false);
			_feedService.Verify(x => x.PublishToFeed(user, message, eventDef.PointValue, It.IsAny<DateTime>()), Times.Once());
		}
Ejemplo n.º 9
0
		public void ProcessLogsAndDoesNothingWithNullUser()
		{
			var calc = GetCalc();
			var eventDef = new EventDefinition {EventDefinitionID = "oi"};
			_eventDefService.Setup(x => x.GetEventDefinition(It.IsAny<string>())).Returns(eventDef);
			_userRepo.Setup(x => x.GetUser(It.IsAny<int>())).Returns((User)null);
			_awardCalcRepo.Setup(x => x.Dequeue()).Returns(new KeyValuePair<string, int>(eventDef.EventDefinitionID, 123));
			calc.ProcessOneCalculation();
			_errorLog.Verify(x => x.Log(It.IsAny<Exception>(), ErrorSeverity.Warning), Times.Once());
			_userAwardService.Verify(x => x.IssueAward(It.IsAny<User>(), It.IsAny<AwardDefinition>()), Times.Never());
		}
Ejemplo n.º 10
0
		public void ProcessNeverCallsIssueIfAwardedAndSingleAward()
		{
			var calc = GetCalc();
			var eventDef = new EventDefinition {EventDefinitionID = "oi"};
			var user = new User(1, DateTime.MinValue);
			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());
		}
Ejemplo n.º 11
0
		public void ProcessEventPublishesToLedger()
		{
			var user = new User(123, DateTime.MinValue);
			var eventDef = new EventDefinition {EventDefinitionID = "blah", PointValue = 42};
			const string message = "msg";
			var publisher = GetPublisher();
			_eventDefService.Setup(x => x.GetEventDefinition(eventDef.EventDefinitionID)).Returns(eventDef);
			var entry = new PointLedgerEntry();
			_pointLedgerRepo.Setup(x => x.RecordEntry(It.IsAny<PointLedgerEntry>())).Callback<PointLedgerEntry>(x => entry = x);
			publisher.ProcessEvent(message, user, eventDef.EventDefinitionID, false);
			Assert.AreEqual(user.UserID, entry.UserID);
			Assert.AreEqual(eventDef.EventDefinitionID, entry.EventDefinitionID);
			Assert.AreEqual(eventDef.PointValue, entry.Points);
		}
Ejemplo n.º 12
0
		public void Create(EventDefinition eventDefinition)
		{
			_eventDefinitionRepository.Create(eventDefinition);
		}
Ejemplo n.º 13
0
		public void ProcessNeverCallsIfEventCountNotHighEnough()
		{
			var calc = GetCalc();
			var eventDef = new EventDefinition { EventDefinitionID = "oi" };
			var user = new User(1, DateTime.MinValue);
			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(4);
			calc.ProcessOneCalculation();
			_userAwardService.Verify(x => x.IssueAward(It.IsAny<User>(), It.IsAny<AwardDefinition>()), Times.Never());
		}
Ejemplo n.º 14
0
		public void AddEventCallsAdd()
		{
			var controller = GetController();
			var eventDef = new EventDefinition();
			controller.AddEvent(eventDef);
			_eventDefService.Verify(x => x.Create(eventDef), Times.Once());
		}
Ejemplo n.º 15
0
		public void QueueCalculation(User user, EventDefinition eventDefinition)
		{
			_awardCalcRepository.Enqueue(eventDefinition.EventDefinitionID, user.UserID);
		}
Ejemplo n.º 16
0
 public async Task Create(EventDefinition eventDefinition)
 {
     await _eventDefinitionRepository.Create(eventDefinition);
 }
Ejemplo n.º 17
0
		public ActionResult AddEvent(EventDefinition eventDefinition)
		{
			_eventDefinitionService.Create(eventDefinition);
			return RedirectToAction("EventDefinitions");
		}
Ejemplo n.º 18
0
		public void ProcessEventCallsCalculator()
		{
			var user = new User(123, DateTime.MinValue);
			var eventDef = new EventDefinition { EventDefinitionID = "blah", PointValue = 42 };
			var publisher = GetPublisher();
			_eventDefService.Setup(x => x.GetEventDefinition(eventDef.EventDefinitionID)).Returns(eventDef);
			publisher.ProcessEvent("msg", user, eventDef.EventDefinitionID, false);
			_awardCalc.Verify(x => x.QueueCalculation(user, eventDef), Times.Once());
		}
Ejemplo n.º 19
0
 public void Create(EventDefinition eventDefinition)
 {
     _eventDefinitionRepository.Create(eventDefinition);
 }
Ejemplo n.º 20
0
		public void ProcessEventUpdatesProfilePointTotal()
		{
			var user = new User(123, DateTime.MinValue);
			var eventDef = new EventDefinition { EventDefinitionID = "blah", PointValue = 42 };
			var publisher = GetPublisher();
			_eventDefService.Setup(x => x.GetEventDefinition(eventDef.EventDefinitionID)).Returns(eventDef);
			publisher.ProcessEvent("msg", user, eventDef.EventDefinitionID, false);
			_profileService.Verify(x => x.UpdatePointTotal(user), Times.Once());
		}
Ejemplo n.º 21
0
 public void QueueCalculation(User user, EventDefinition eventDefinition)
 {
     _awardCalcRepository.Enqueue(eventDefinition.EventDefinitionID, user.UserID);
 }