public async Task AddActivityGoal() { var session = await Login(); var currentSeed = Guid.NewGuid(); using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) }) { client.AcceptJson().AddSessionHeader(session.Id); var form = new Activity { Name = $"Name.{currentSeed}", Description = $"Description.{currentSeed}" }; // Add Activity with valid data var activityResponse = await client.PostAsJsonAsync($"/api/activities", form); Assert.Equal(HttpStatusCode.Created, activityResponse.StatusCode); var activity = await activityResponse.Content.ReadAsJsonAsync<Activity>(); Assert.Equal($"Name.{currentSeed}", activity.Name); var goalForm = new ActivityGoalForm { Description = $"Description.{currentSeed}" }; activityResponse = await client.PutAsJsonAsync($"/api/activities/{activity.Id}/goal", goalForm); Assert.Equal(HttpStatusCode.OK, activityResponse.StatusCode); activity = await activityResponse.Content.ReadAsJsonAsync<Activity>(); Assert.Equal(1, activity.Goals.Count); } }
protected static async Task SeedGoals(SocialGamificationAssetContext _context, bool isAsync = false) { if (!_context.ActorGoal.Any()) { var mayur = await _context.Players.Where(a => a.Username.Equals("mayur")).FirstOrDefaultAsync(); var goal = new Goal { Concern = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, RewardResource = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, Feedback = new GoalFeedback { Threshold = 0, Target = 0, Direction = 0 }, Description = "Test" }; var attributeType = new AttributeType { Name = "testAttribute", DefaultValue = 0f, Type = 0 }; var activity = new Activity { Name = "Testing" }; IList<ActorGoal> goals = new List<ActorGoal> { new ActorGoal { Actor = mayur, Goal = goal, Status = 0, ConcernOutcome = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, RewardResourceOutcome = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 }, Category = 0 }, Activity = activity, Role = new Role { Name = "Testing", Goal = goal, Activity = activity } } }; _context.ActorGoal.AddRange(goals); IList<Reward> rewards = new List<Reward> { new Reward { AttributeType = attributeType, TypeReward = RewardType.Store, Value = 1.5f, Status = 0, Goal = goal }, new Reward { AttributeType = attributeType, Value = 3.5f, Status = 0, Goal = goal, TypeReward = RewardType.Modify, ActionRelation = new ActionRelation { Action = new Action { Verb = "testVerb", Activity = activity, Goal = goal }, Relationship = 0, ConcernChange = new Matrix { X = 0, Y = 0 }, RewardResourceChange = new Matrix { X = 0, Y = 0 } } } }; _context.Rewards.AddRange(rewards); await SaveChanges(_context, isAsync); Debug.WriteLine("Goals & related Seeded."); } }