public async Task CreateActorGoal() { var session = await Login(); var role = await CreateTestRole(); using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) }) { client.AcceptJson().AddSessionHeader(session.Id.ToString()); var newerGoal = new ActorGoal { ActorId = session.PlayerId, GoalId = role.Goal.Id, Status = 0, ConcernOutcomeId = role.Goal.ConcernId, RewardResourceOutcomeId = role.Goal.RewardResourceId, ActivityId = role.ActivityId, RoleId = role.Id }; var goalResponse = await client.PostAsJsonAsync("/api/goals/actors", newerGoal); Assert.Equal(HttpStatusCode.Created, goalResponse.StatusCode); var actorgoal = await goalResponse.Content.ReadAsJsonAsync <ActorGoal>(); Assert.Equal(1, actorgoal.Goal.Concern.Coordinates.X); Assert.Equal(role.Description, actorgoal.Role.Description); Assert.Equal(role.Goal.Description, actorgoal.Goal.Description); } }
public async Task CreateActorGoalInvalidActor() { var session = await Login(); var invalidId = Guid.NewGuid(); var role = await CreateTestRole(); using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) }) { client.AcceptJson().AddSessionHeader(session.Id.ToString()); var newerGoal = new ActorGoal { ActorId = invalidId, GoalId = role.Goal.Id, Status = 0, ConcernOutcomeId = role.Goal.ConcernId, RewardResourceOutcomeId = role.Goal.RewardResourceId, ActivityId = role.ActivityId, RoleId = role.Id }; var goalResponse = await client.PostAsJsonAsync("/api/goals/actors", newerGoal); Assert.Equal(HttpStatusCode.NotFound, goalResponse.StatusCode); var content = await goalResponse.Content.ReadAsJsonAsync <ApiError>(); Assert.Equal($"No Actor found for the passed ID", content.Error); } }
public async Task GetActorGoalValidGoal() { var session = await Login(); var role = await CreateTestRole(); using (var client = new HttpClient { BaseAddress = new Uri(ServerUrl) }) { client.AcceptJson().AddSessionHeader(session.Id.ToString()); var newerGoal = new ActorGoal { ActorId = session.PlayerId, GoalId = role.Goal.Id, Status = 0, ConcernOutcomeId = role.Goal.ConcernId, RewardResourceOutcomeId = role.Goal.RewardResourceId, ActivityId = role.ActivityId, RoleId = role.Id }; var actorgoalResponse = await client.PostAsJsonAsync("/api/goals/actors", newerGoal); Assert.Equal(HttpStatusCode.Created, actorgoalResponse.StatusCode); var goalsResponse = await client.GetAsync($"/api/goals/{role.Goal.Id}/actor"); Assert.Equal(HttpStatusCode.OK, goalsResponse.StatusCode); var goalGet = await goalsResponse.Content.ReadAsJsonAsync <ActorGoal>(); Assert.IsType(typeof(ActorGoal), goalGet); } }
public async Task <IActionResult> CreateActorGoal([FromBody] ActorGoal goal) { if (!ModelState.IsValid) { return(HttpResponseHelper.BadRequest(ModelState)); } if (goal.ActivityId == Guid.Empty) { return(HttpResponseHelper.NotFound("No Activity found")); } var activitytest = await _context.Activities.FindAsync(goal.ActivityId); if (activitytest == null) { return(HttpResponseHelper.NotFound("No Activity found for the passed ID")); } if (goal.ActorId == Guid.Empty) { return(HttpResponseHelper.NotFound("No Actor found")); } var actortest = await _context.Players.FindAsync(goal.ActorId); if (actortest == null) { return(HttpResponseHelper.NotFound("No Actor found for the passed ID")); } if (goal.ConcernOutcomeId == Guid.Empty) { return(HttpResponseHelper.NotFound("No ConcernOutcome found")); } var concerntest = await _context.ConcernMatrix.FindAsync(goal.ConcernOutcomeId); if (concerntest == null) { return(HttpResponseHelper.NotFound("No ConcernOutcome found for the passed ID")); } if (goal.GoalId == Guid.Empty) { return(HttpResponseHelper.NotFound("No Goal found")); } var goaltest = await _context.Goals.FindAsync(goal.GoalId); if (goaltest == null) { return(HttpResponseHelper.NotFound("No Goal found for the passed ID")); } if (goal.RewardResourceOutcomeId == Guid.Empty) { return(HttpResponseHelper.NotFound("No RewardResourceOutcome found")); } var rrtest = await _context.RewardResourceMatrix.FindAsync(goal.RewardResourceOutcomeId); if (rrtest == null) { return(HttpResponseHelper.NotFound("No RewardResourceOutcome found for the passed ID")); } if (goal.RoleId == Guid.Empty) { return(HttpResponseHelper.NotFound("No Role found")); } var roletest = await _context.Roles.FindAsync(goal.RoleId); if (roletest == null) { return(HttpResponseHelper.NotFound("No Role found for the passed ID")); } _context.ActorGoal.Add(goal); var error = await SaveChangesAsync(); if (error != null) { return(error); } return(CreatedAtRoute("GetActorGoal", new { id = goal.GoalId }, goal)); }