public async Task UpdateRewardByValidAction() { var session = await Login(); var newAction = await CreateTestAction("Verb test" + Guid.NewGuid()); using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) }) { client.AcceptJson().AddSessionHeader(session.Id.ToString()); var newAT = new AttributeType { Name = "testAttribute", DefaultValue = 0f, Type = 0 }; var atResponse = await client.PostAsJsonAsync("/api/attributes/types", newAT); Assert.Equal(HttpStatusCode.Created, atResponse.StatusCode); var attribute = await atResponse.Content.ReadAsJsonAsync<AttributeType>(); var newAR = new ActionRelation { ActionId = newAction.Id, Relationship = 0, ConcernChange = new Matrix { X = 0, Y = 0 }, RewardResourceChange = new Matrix { X = 0, Y = 0 } }; var arResponse = await client.PostAsJsonAsync("/api/actions/relations", newAR); Assert.Equal(HttpStatusCode.Created, arResponse.StatusCode); var arReturn = await arResponse.Content.ReadAsJsonAsync<ActionRelation>(); Assert.IsType(typeof(ActionRelation), arReturn); var newReward = new Reward { AttributeTypeId = attribute.Id, TypeReward = RewardType.Store, Value = 1.5f, Status = 0, GoalId = newAction.GoalId }; var rewardResponse = await client.PostAsJsonAsync("/api/rewards", newReward); Assert.Equal(HttpStatusCode.Created, rewardResponse.StatusCode); var newReward2 = new Reward { AttributeTypeId = attribute.Id, TypeReward = RewardType.Modify, Value = 1f, Status = 0, GoalId = newAction.GoalId, ActionRelationId = arReturn.Id }; var rewardResponse2 = await client.PostAsJsonAsync("/api/rewards", newReward2); Assert.Equal(HttpStatusCode.Created, rewardResponse2.StatusCode); var actionForm = new Action { Verb = newAction.Verb }; var actionResponse = await client.PostAsJsonAsync("/api/actions/send", actionForm); Assert.Equal(HttpStatusCode.OK, actionResponse.StatusCode); var rewardReturn = await actionResponse.Content.ReadAsJsonAsync<Reward>(); Assert.IsType(typeof(Reward), rewardReturn); } }
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."); } }