コード例 #1
0
        protected async Task<Goal> CreateTestGoal()
        {
            var session = await Login();

            using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) })
            {
                client.AcceptJson().AddSessionHeader(session.Id.ToString());
                var goal = new Goal
                {
                    Concern = new ConcernMatrix { Coordinates = new Matrix { X = 1, Y = 1 }, Category = 0 },
                    RewardResource =
                        new RewardResourceMatrix { Coordinates = new Matrix { X = 2, Y = 2 }, Category = 0 },
                    Feedback = new GoalFeedback { Threshold = 0, Target = 0, Direction = 0 },
                    Description = "Created for test cases"
                };
                var goalResponse = await client.PostAsJsonAsync("/api/goals", goal);
                Assert.Equal(HttpStatusCode.Created, goalResponse.StatusCode);

                var created = await goalResponse.Content.ReadAsJsonAsync<Goal>();

                return created;
            }
        }
コード例 #2
0
        public async Task<IActionResult> AddActivityGoal([FromRoute] Guid id, [FromBody] ActivityGoalForm form)
        {
            if (!ModelState.IsValid)
            {
                return HttpResponseHelper.BadRequest(ModelState);
            }

            var activity = await _context.Activities.Where(a => a.Id.Equals(id)).FirstOrDefaultAsync();
            if (activity == null)
            {
                return HttpResponseHelper.NotFound("No such Activity found.");
            }

            var goal = new Goal
            {
                Description = form.Description,
                Concern = new ConcernMatrix { Coordinates = new Matrix { X = 0, Y = 0 } },
                RewardResource = new RewardResourceMatrix { Coordinates = new Matrix { X = 0, Y = 0 } },
                Feedback = new GoalFeedback()
            };

            _context.Entry(activity).State = EntityState.Modified;

            if (activity.Goals?.Count > 0)
            {
                activity.Goals.Add(goal);
            }
            else
            {
                activity.Goals = new List<Goal> { goal };
            }

            var error = await SaveChangesAsync();
            if (error != null)
            {
                return error;
            }

            return Ok(activity);
        }
コード例 #3
0
        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.");
            }
        }
コード例 #4
0
        public async Task DeleteGoalInvalidGoal()
        {
            var session = await Login();

            using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) })
            {
                client.AcceptJson().AddSessionHeader(session.Id.ToString());

                // Update Goal with Invalid Id
                var invalidId = Guid.NewGuid();
                var goalForm = new Goal { Description = "updated" };
                var goalResponse = await client.DeleteAsync($"/api/goals/{invalidId}");
                Assert.Equal(HttpStatusCode.NotFound, goalResponse.StatusCode);

                var content = await goalResponse.Content.ReadAsJsonAsync<ApiError>();
                Assert.Equal($"No Goal found.", content.Error);
            }
        }
コード例 #5
0
        public async Task CreateGoalInvalidRewardResource()
        {
            var newGoal = await CreateTestGoal();
            var session = await Login();
            var invalidId = Guid.NewGuid();

            using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) })
            {
                client.AcceptJson().AddSessionHeader(session.Id.ToString());

                var newerGoal = new Goal
                {
                    ConcernId = invalidId,
                    RewardResourceId = newGoal.RewardResourceId,
                    FeedbackId = newGoal.FeedbackId
                };

                var goalResponse = await client.PostAsJsonAsync("/api/goals", newerGoal);
                Assert.Equal(HttpStatusCode.NotFound, goalResponse.StatusCode);

                var content = await goalResponse.Content.ReadAsJsonAsync<ApiError>();
                Assert.Equal($"No Concern found for the passed ID", content.Error);
            }
        }
コード例 #6
0
        public async Task CreateGoal()
        {
            var session = await Login();

            using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) })
            {
                client.AcceptJson().AddSessionHeader(session.Id.ToString());

                var newGoal = new Goal
                {
                    Concern = new ConcernMatrix { Coordinates = new Matrix { X = 3, Y = 3 }, Category = 0 },
                    RewardResource =
                        new RewardResourceMatrix { Coordinates = new Matrix { X = 4, Y = 4 }, Category = 0 },
                    Feedback = new GoalFeedback { Threshold = 0, Target = 0, Direction = 0 },
                    Description = "Test case creation"
                };

                var goalResponse = await client.PostAsJsonAsync("/api/goals", newGoal);
                Assert.Equal(HttpStatusCode.Created, goalResponse.StatusCode);

                var goal = await goalResponse.Content.ReadAsJsonAsync<Goal>();
                Assert.Equal(3, goal.Concern.Coordinates.X);
                Assert.Equal(4, goal.RewardResource.Coordinates.Y);
            }
        }
コード例 #7
0
        public async Task UpdateGoalValid()
        {
            var newGoal = await CreateTestGoal();
            var session = await Login();

            using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) })
            {
                client.AcceptJson().AddSessionHeader(session.Id.ToString());

                // Update Goal with Valid Id
                var goalForm = new Goal { Description = "updated" };
                var goalUpdateResponse = await client.PutAsJsonAsync($"/api/goals/{newGoal.Id}", goalForm);
                Assert.Equal(HttpStatusCode.OK, goalUpdateResponse.StatusCode);

                var content = await goalUpdateResponse.Content.ReadAsJsonAsync<Goal>();
                Assert.Equal(newGoal.Id, content.Id);
                Assert.Equal("updated", content.Description);
            }
        }
コード例 #8
0
        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.");
            }
        }