public void DoAction() { var user = this.GetLogin(); var testAccount = new Core.Models.Account(user.AccountId); var testDefinition = new Core.Models.Definitions.Definition(276); var testPositionI = new Core.Models.PositionI(this.TestPosition()); var dictParam = new System.Collections.Generic.Dictionary <string, object>(); dictParam[Core.Controllers.Actions.CreateUnit.CREATE_POSITION] = testPositionI; dictParam[Core.Controllers.Actions.CreateUnit.CREATION_TYPE] = (long)testDefinition.SubType; var testAction = new Core.Models.Action(testAccount, Core.Models.Action.ActionType.CreateBuilding, dictParam); var testActions = new Core.Models.Action[] { testAction, }; var testActionRequest = new Core.Connections.DoActionsRequest( user.SessionID, this.TestPosition(), testActions); var testJson = JsonConvert.SerializeObject(testActionRequest); var testPackage = new Packet(); testPackage.Content = testJson; testPackage.MethodType = MethodType.DoActions; var testStream = this.GetStream(); testPackage.Send(testStream); var data = JsonConvert.DeserializeObject <Core.Connections.Response>(Packet.Receive(testStream).Content); Assert.AreEqual(Core.Connections.Response.ReponseStatus.OK, data.Status); }
public void DoAction() { var user = this.GetLogin(); var testAccount = new Core.Models.Account(user.AccountId); var testDefinition = new Core.Models.Definitions.Definition(276); var testPositionI = new Core.Models.PositionI(this.TestPosition()); var dictParam = new System.Collections.Generic.Dictionary<string, object>(); dictParam[Core.Controllers.Actions.CreateUnit.CREATE_POSITION] = testPositionI; dictParam[Core.Controllers.Actions.CreateUnit.CREATION_TYPE] = (long)testDefinition.SubType; var testAction = new Core.Models.Action(testAccount, Core.Models.Action.ActionType.CreateBuilding, dictParam); var testActions = new Core.Models.Action[] { testAction, }; var testActionRequest = new Core.Connections.DoActionsRequest( user.SessionID, this.TestPosition(), testActions); var testJson = JsonConvert.SerializeObject(testActionRequest); var testPackage = new Packet(); testPackage.Content = testJson; testPackage.MethodType = MethodType.DoActions; var testStream = this.GetStream(); testPackage.Send(testStream); var data = JsonConvert.DeserializeObject<Core.Connections.Response>(Packet.Receive(testStream).Content); Assert.AreEqual(Core.Connections.Response.ReponseStatus.OK, data.Status); }
/// <summary> /// Sends the actions to the server. /// </summary> /// <returns>True if the response is ok, otherwise false.</returns> /// <param name="currentGamePosition">Current game position.</param> /// <param name="actions">Actions which should be executed.</param> public async Task<bool> DoActionsAsync(Core.Models.Position currentGamePosition, Core.Models.Action[] actions) { var request = new Core.Connections.DoActionsRequest(m_sessionID, currentGamePosition, actions); var json = JsonConvert.SerializeObject(request); var jsonFromServer = await TcpConnection.Connector.SendAsync(Core.Connection.MethodType.DoActions, json); var entitiesResponse = JsonConvert.DeserializeObject<Core.Connections.Response>(jsonFromServer); if (entitiesResponse.Status == Core.Connections.Response.ReponseStatus.OK) { return true; } return false; }