public static GoalTriggers LoadTestData( this GoalTriggers goalTriggers, Guid realmRefId, Goal goal, Actions actions, NetTopologySuite.Geometries.MultiPolygon insideOf, NetTopologySuite.Geometries.MultiPolygon outsideOf, List <string> tags) { var rnd = new Random(); for (int i = 0; i < rnd.Next(1, 10); i++) { var simpleName = $"Goal Trigger [{i}]"; var goalTrigger = new GoalTrigger() { RealmRefId = realmRefId, GoalRefId = goal.EntityRefId, SimpleName = simpleName, Priority = i, ReleaseOn = DateTimeOffset.UtcNow.AddDays(-365), ExpireOn = DateTimeOffset.MaxValue, Tags = tags, RollingPeriodActionFilter = TimeSpan.FromDays(-30), }; goalTrigger.NameTranslations.Add( new StringTranslation() { Locale = "en-Us", LocalName = simpleName } ); goalTrigger.Steps.Add( new TriggerStep() { ExecutionOrder = i, PeriodRecurrence = new PeriodRecurrence() { PeriodMinuteBeginOn = Convert.ToInt32(TimeSpan.FromMinutes(0).TotalMinutes), PeriodTimeSpan = TimeSpan.FromSeconds((24 * 60 * 60) - 1), PeriodPattern = new RecurrencePattern(FrequencyType.Daily, interval: 1) { Until = DateTime.MaxValue }.ToString() }, ActionOccurrenceRules = new ActionOccurrenceRules() { new ActionOccurrenceRule() { ActionRefId = actions[0].EntityRefId, OperationType = Core.Enums.OperationRuleType.And, TenseType = Core.Enums.TenseRuleType.Did, CompareType = Core.Enums.CompareRuleType.GreaterOrEqual, Count = 1, PeriodRecurrence = new PeriodRecurrence() { PeriodMinuteBeginOn = Convert.ToInt32(TimeSpan.FromMinutes(0).TotalMinutes), PeriodTimeSpan = TimeSpan.FromSeconds((24 * 60 * 60) - 1), PeriodPattern = new RecurrencePattern(FrequencyType.Daily, interval: 1) { Until = DateTime.MaxValue }.ToString() }, InsideOf = insideOf, OutsideOf = outsideOf } } } );; goalTriggers.Add(goalTrigger); } return(goalTriggers); }
public void SingleActionAwardInsideOfGeoFenceRuleSucceeds() { var actionId = Guid.NewGuid().ToString("N"); var realmRefId = Guid.NewGuid(); var player = new Player() { RealmRefId = realmRefId, }; player.Tags.Add("Fuu"); var actions = new Actions() { new Common.Action() { RealmRefId = realmRefId, ReleasedOn = DateTimeOffset.UtcNow.AddSeconds(-60), ActionId = actionId, } }; var sr = new List <SmartContext <ActionRequest> >() { new SmartContext <ActionRequest>() { Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest() { ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddDays(-10) } }, new SmartContext <ActionRequest>() { Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest() { ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddHours(-36) } }, new SmartContext <ActionRequest>() { Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest() { ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddHours(-24) } }, new SmartContext <ActionRequest>() { Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest() { ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddHours(-8) } }, new SmartContext <ActionRequest>() { Latitude = 33.753746, Longitude = -84.386330, Data = new ActionRequest() { ActionId = actionId, OccurredOn = DateTimeOffset.UtcNow.AddMinutes(-1) } } }; NetTopologySuite.Geometries.MultiPolygon insideOf = null; var jsonSerializer = NetTopologySuite.IO.GeoJsonSerializer.Create(); using (StreamReader file = File.OpenText(@"GeorgiaGeoJsonData.json")) using (JsonTextReader reader = new JsonTextReader(file)) { insideOf = jsonSerializer.Deserialize <NetTopologySuite.Geometries.MultiPolygon>(reader); } var coins = new Coins().LoadTestData(realmRefId); var awards = new Awards().LoadTestData(coins); var goal = new Goal().LoadTestData(realmRefId, awards); var goalTriggers = new GoalTriggers().LoadTestData(realmRefId, goal, actions, insideOf, null, null);; foreach (var goalTrigger in goalTriggers) { var events = new PlayerActionEvents(); events.AddRange( sr.Select(e => new PlayerActionEvent() { OccurredAt = new NetTopologySuite.Geometries.Point(e.Longitude, e.Latitude) }.Map(e.Data, actions) ) ); var qualifyingActionRequests = goalTrigger.ValidateSteps(events); Assert.IsTrue(qualifyingActionRequests.Count > 0); } // the action is "read an ad" // step 1 read an ad on tuesday // step 2 read an ad on thursday // convert requests to Events }