public async Task ShouldReturnAllNodesWithSpecifiedNameWhenGetNodesCalled() { //Given const string hostname = "node1"; var desc = new NodeDescription(); desc.Hostname = hostname; _swarmClient.GetNodes().Returns(x => { return(Task.FromResult <IEnumerable <NodeListResponse> >(new [] { _any.Create <NodeListResponse>(), _any.Build <NodeListResponse>().With(t => t.Description, desc).Create() })); }); var nodeService = new NodeService(_swarmClient, _loggerFactory); var nodeController = new NodeController(nodeService); //When var response = await nodeController.GetNode(hostname, SwarmRole.Unknown); var jsonResult = response as JsonResult; var value = jsonResult?.Value as IEnumerable <NodeListResponse>; //Then Assert.NotNull(jsonResult); Assert.NotNull(value); Assert.Equal(200, jsonResult.StatusCode); Assert.Equal(1, value.Count()); }
public async Task ShouldReturnAllManagerNodesInfoWhenGetNodesCalled() { //Given var spec = new NodeUpdateParameters(); spec.Role = "manager"; _swarmClient.GetNodes().Returns(x => { return(Task.FromResult <IEnumerable <NodeListResponse> >(new [] { _any.Create <NodeListResponse>(), _any.Build <NodeListResponse>().With(t => t.Spec, spec).Create() })); }); var nodeService = new NodeService(_swarmClient, _loggerFactory); var nodeController = new NodeController(nodeService); //When var response = await nodeController.GetNode(null, SwarmRole.Manager); var jsonResult = response as JsonResult; var value = jsonResult?.Value as IEnumerable <NodeListResponse>; //Then Assert.NotNull(jsonResult); Assert.NotNull(value); Assert.Equal(200, jsonResult.StatusCode); Assert.Equal(1, value.Count()); }
public void CmdSelectNode(NetworkIdentity networkId) { if (NetManager.HasGameStarted()) { NodeController controller = networkId.GetComponent <NodeController>(); if (controller.GetNode() != null) { if (NodeReferences.InteractableNodeTypes.Contains(controller.GetNode().GetNodeType())) { if (controller.GetOwner() == netIdentity) { selectedNodes.Add(controller); TargetSelectNode(networkId); } } } } }
public void CmdBuildNode(NetworkIdentity networkIdentity, int componentId) { NodeController nodeController = networkIdentity.GetComponent <NodeController>(); if (nodeController.GetNode().GetController().GetComponentId() != 0 || nodeController.GetNode().GetNodeType() != Components.ComponentData[componentId].FoundationRequirement) { return; } if (nodeController.GetEnergy() > Components.ComponentData[componentId].BuildCost) { int newEnergyLevel = nodeController.GetEnergy() - Components.ComponentData[componentId].BuildCost; ((BaseNode)nodeController.GetNode()).SetComponentData(componentId); nodeController.SetEnergy(newEnergyLevel); // nodeController.EnableHChevrons(); // nodeController.EnableVChevrons(); } }
void UpdateCursorShape(int nodeID) { SelectedNodeID = nodeID; selectedNode = NodeController.GetNode(nodeID); if (CursorGO != null) { Destroy(CursorGO); } CursorGO = Instantiate(selectedNode.BuildPreviewCollider); CursorGO.AddComponent <Cursor>(); CursorGO.SetActive(false); CursorGO.name = "CURSOR"; }
public void CmdMoveEnergy(NetworkIdentity destination, int amount, bool deselect) { if (NetManager.HasGameStarted()) { NodeController dest = destination.GetComponent <NodeController>(); if (dest.GetNode() != null && selectedNodes.Count > 0) { if (NodeReferences.InteractableNodeTypes.Contains(dest.GetNode().GetNodeType())) { foreach (var source in selectedNodes) { source.SendEnergy(amount, dest); } } if (deselect) { UnselectNodes(); TargetUnselectNodes(); } } } }
public async Task ShouldReturnInternalServerErrorWhenGetNodesCalledAndErrorOccour() { //Given _swarmClient.When(x => { x.GetNodes(); }).Do(_ => { throw new Exception(); }); var nodeService = new NodeService(_swarmClient, _loggerFactory); var nodeController = new NodeController(nodeService); //When var response = await nodeController.GetNode(null, SwarmRole.Unknown); var result = response as ContentResult; //Then Assert.NotNull(result); Assert.Equal(500, result.StatusCode); }
public async Task ShouldReturnAllNodesInfoWhenGetNodesCalled() { //Given _swarmClient.GetNodes().Returns(x => { return(Task.FromResult <IEnumerable <NodeListResponse> >(new [] { _any.Create <NodeListResponse>(), _any.Create <NodeListResponse>() })); }); var nodeService = new NodeService(_swarmClient, _loggerFactory); var nodeController = new NodeController(nodeService); //When var response = await nodeController.GetNode(null, SwarmRole.Unknown); var jsonResult = response as JsonResult; var value = jsonResult?.Value as IEnumerable <NodeListResponse>; //Then Assert.NotNull(jsonResult); Assert.NotNull(value); Assert.Equal(200, jsonResult.StatusCode); Assert.Equal(2, value.Count()); }