public override sealed async Task <BotResponse> ProcessMessageAsync(BotRequest request) { // check if there is a state object to load State = !string.IsNullOrEmpty(request.Bot?.InternalState) ? LambdaSerializer.Deserialize <TState>(request.Bot.InternalState) : new TState(); LogInfo($"Starting State:\n{LambdaSerializer.Serialize(State)}"); // dispatch to specific method based on request command BotResponse response; switch (request.Command) { case BotCommand.GetBuild: // bot configuration request response = new BotResponse { BotBuild = await GetBuildAsync() }; break; case BotCommand.GetAction: // bot action request try { // capture request fields for easy access GameSession = request.Session; Bot = request.Bot; GameClient = new LambdaRobotsGameClient(GameSession.ApiUrl, Bot.Id, HttpClient); // initialize a default empty action _action = new GetActionResponse(); // get bot action await GetActionAsync(); // generate response _action.BotState = LambdaSerializer.Serialize(State); response = new BotResponse { BotAction = _action, }; } finally { Bot = null; GameClient = null; } break; default: // unrecognized request throw new ApplicationException($"unexpected request: '{request.Command}'"); } // log response and return LogInfo($"Final State:\n{LambdaSerializer.Serialize(State)}"); return(response); }
/// <summary> /// Gets a Action by ActionId. /// </summary> /// <param name="ActionId">Id of a Action</param> /// <returns>Action Details</returns> public HttpResponseMessage GetAction(int actionId) { GetActionResponse response = actionService.GetAction(new GetActionRequest() { Id = actionId }); return(Request.BuildResponse(response)); }
private void ApplyBotAction(BotInfo bot, GetActionResponse action) { var now = _provider.UtcNow; var secondsSinceUpdate = (float)(now - bot.LastStatusUpdate).TotalSeconds; bot.LastStatusUpdate = now; // reduce reload time if any is active if (bot.ReloadCoolDown > 0) { bot.ReloadCoolDown = MathF.Max(0.0f, bot.ReloadCoolDown - secondsSinceUpdate); } // check if any actions need to be applied if (action is null) { // bot didn't respond with an action; consider it dead bot.Status = BotStatus.Dead; bot.TimeOfDeathGameTurn = GameSession.CurrentGameTurn; AddMessage($"{bot.Name} (R{bot.Index}) was disqualified by lack of action"); return; } // update bot state bot.InternalState = action.BotState; // update speed and heading bot.TargetSpeed = GameMath.MinMax(0.0f, action.Speed ?? bot.TargetSpeed, bot.MaxSpeed); bot.TargetHeading = GameMath.NormalizeAngle(action.Heading ?? bot.TargetHeading); // fire missile if requested and possible if ((action.FireMissileHeading.HasValue || action.FireMissileDistance.HasValue) && (bot.ReloadCoolDown == 0.0f)) { // update bot state ++bot.TotalMissileFiredCount; bot.ReloadCoolDown = bot.MissileReloadCooldown; // add missile var missile = new MissileInfo { Id = $"{bot.Id}:M{bot.TotalMissileFiredCount}", BotId = bot.Id, Status = MissileStatus.Flying, X = bot.X, Y = bot.Y, Speed = bot.MissileVelocity, Heading = GameMath.NormalizeAngle(action.FireMissileHeading ?? bot.Heading), Range = GameMath.MinMax(0.0f, action.FireMissileDistance ?? bot.MissileRange, bot.MissileRange), DirectHitDamageBonus = bot.MissileDirectHitDamageBonus, NearHitDamageBonus = bot.MissileNearHitDamageBonus, FarHitDamageBonus = bot.MissileFarHitDamageBonus }; GameSession.Missiles.Add(missile); } }
public void GetActions_RunTimeException_ExceptionDetails() { mockActionRepository.Setup(cr => cr.FindBy(It.IsAny <int>(), It.IsAny <int>())).Throws(new InvalidOperationException()); GetActionResponse response = actionService.GetAction(new GetActionRequest() { Id = ACTION_ID }); mockRepository.VerifyAll(); Assert.AreEqual(typeof(InvalidOperationException), response.Exception.GetType()); Assert.AreNotEqual(null, response.Exception); }
public ConveyancingMatter MapFromActionstepTypes( GetActionResponse actionResponse, ListActionParticipantsResponse participantsResponse, ListDataCollectionRecordValuesResponse dataCollectionsResponse) { if (actionResponse is null) { throw new ArgumentNullException(nameof(actionResponse)); } var wCAConveyancingMatter = new ConveyancingMatter(); var action = actionResponse.Action; wCAConveyancingMatter.Id = action.Id; wCAConveyancingMatter.Name = action.Name; wCAConveyancingMatter.ActionType = actionResponse.ActionTypeName; wCAConveyancingMatter.FileReference = action.Reference; wCAConveyancingMatter.Conveyancers.AddRange(GetParticipants(participantsResponse, "Conveyancer")); wCAConveyancingMatter.Buyers.AddRange(GetParticipants(participantsResponse, "Buyer")); wCAConveyancingMatter.IncomingBanks.AddRange(GetParticipants(participantsResponse, "Bank_Incoming")); wCAConveyancingMatter.OthersideSolicitor.AddRange(GetParticipants(participantsResponse, "Otherside_Solicitor")); wCAConveyancingMatter.OthersideSolicitorPrimaryContact.AddRange(GetParticipants(participantsResponse, "Otherside_Solicitor_Primary_Contact")); wCAConveyancingMatter.PropertyDetails = new PropertyDetails { TitleReference = dataCollectionsResponse?["property", "titleref"], LotNo = dataCollectionsResponse["property", "lotno"] }; ConveyancingType conveyancingType; var isConveyancingTypeParseSuccess = Enum.TryParse <ConveyancingType>(dataCollectionsResponse["convdet", "ConveyType"], out conveyancingType); if (!isConveyancingTypeParseSuccess) { conveyancingType = ConveyancingType.None; } wCAConveyancingMatter.ConveyancingType = conveyancingType; var stringSettlementDate = dataCollectionsResponse["keydates", "smtdateonly"]; if (!String.IsNullOrEmpty(stringSettlementDate)) { var pattern = LocalDatePattern.Create("yyyy-MM-dd", CultureInfo.InvariantCulture); wCAConveyancingMatter.SettlementDate = pattern.Parse(stringSettlementDate).Value; } wCAConveyancingMatter.SettlementBookingTime = dataCollectionsResponse["convdet", "smttime"]; return(wCAConveyancingMatter); }
public IActionResult GetAction(string id) { GetActionResponse response = new GetActionResponse { StatusCode = (int)HttpStatusCode.OK, Message = HttpStatusCode.OK.ToString(), Payload = new { id } }; return(Ok(response)); }
public void GetAction_ValidRequest_Succeed() { var mockActions = ActionMockData.GetMockActions(mockRepository, 10).ToList(); mockActionRepository.Setup(cr => cr.FindBy(It.IsAny <int>(), It.IsAny <int>())).Returns(mockActions[0]); GetActionResponse response = actionService.GetAction(new GetActionRequest() { Id = ACTION_ID, ContactId = CONTACT_ID }); ActionViewModel action = response.ActionViewModel; mockRepository.VerifyAll(); Assert.AreEqual(0, action.ActionId); Assert.AreEqual(null, response.Exception); } //Problem with automapper if we use strict mock
void ShouldMapFromValidActionstepTypes() { // Given var actionstepToWCAMapper = new ActionstepToWCAMapper(); var actionResponse = new GetActionResponse { Action = new ActionstepAction { Id = 123, Name = "Test matter name" } }; var participantsResponse = new ListActionParticipantsResponse(); participantsResponse.ActionParticipants.AddRange(new List <ActionParticipant> { new ActionParticipant { Id = "aabb", }, new ActionParticipant { Id = "ccdd", } }); var dataCollectionsResponse = new ListDataCollectionRecordValuesResponse { DataCollectionRecordValues = new List <DataCollectionRecordValue> { new DataCollectionRecordValue { Id = "dc-id1", StringValue = "dc-val1" } } }; // When var wcaMatter = actionstepToWCAMapper.MapFromActionstepTypes(actionResponse, participantsResponse, dataCollectionsResponse); // Then Assert.Equal(actionResponse.Action.Id, wcaMatter.Id); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetActionResponse response = new GetActionResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("action", targetDepth)) { var unmarshaller = ActionUnmarshaller.Instance; response.Action = unmarshaller.Unmarshall(context); continue; } } return(response); }