Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
 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);
                 }
             }
         }
     }
 }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
    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";
    }
Esempio n. 6
0
        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();
                    }
                }
            }
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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());
        }