public void When_DeleteConnector_Expect_ConnectorDeletion()
        {
            var errorMessage         = string.Empty;
            var createdGroup         = CreateGroup();
            var createdChargeStation = CreateChargeStation(createdGroup);

            var createConnectorCommand = new CreateOrUpdateConnectorCommand()
            {
                Connector = new Connector()
                {
                    MaxCurrent = 50, ChargeStationId = createdChargeStation.Id
                }
            };

            var actionResult = _connectorController.Create(createConnectorCommand);

            var createdConnector = ActionResultParser.ParseCreatedResult <Connector>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            actionResult = _connectorController.Delete(createdConnector.Id);

            var deletedConnector = ActionResultParser.ParseObjectResult <Connector>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            Assert.AreEqual(createdConnector.Id, deletedConnector.Id);

            DeleteGroup(createdGroup);
        }
        public IActionResult Update([FromBody] CreateOrUpdateConnectorCommand command)
        {
            if (command == null)
            {
                return(BadRequest());
            }

            var result = _mediator.Send(command).Result;

            if (!string.IsNullOrEmpty(result.ErrorMessage))
            {
                return(StatusCode(200, result));
            }

            return(Ok(result));
        }
        public void When_SecondConnectorUpdateExceedsGroupCapacity_Expect_SuggestedConnectorRemovals()
        {
            var errorMessage         = string.Empty;
            var createdGroup         = CreateGroup();
            var createdChargeStation = CreateChargeStation(createdGroup);

            var createConnectorCommand = new CreateOrUpdateConnectorCommand()
            {
                Connector = new Connector()
                {
                    MaxCurrent = 60, ChargeStationId = createdChargeStation.Id
                }
            };
            var actionResult      = _connectorController.Create(createConnectorCommand);
            var createdConnector1 = ActionResultParser.ParseCreatedResult <Connector>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            createConnectorCommand = new CreateOrUpdateConnectorCommand()
            {
                Connector = new Connector()
                {
                    MaxCurrent = 30, ChargeStationId = createdChargeStation.Id
                }
            };
            actionResult = _connectorController.Create(createConnectorCommand);
            _            = ActionResultParser.ParseCreatedResult <Connector>(actionResult, out errorMessage);
            CheckErrorMessage(errorMessage);

            createConnectorCommand.Connector.MaxCurrent = 50;
            actionResult = _connectorController.Update(createConnectorCommand);

            var createdResult            = actionResult as ObjectResult;
            var createdResponse          = createdResult.Value as Response;
            var createdConnector2Message = createdResponse.ErrorMessage;

            if (string.IsNullOrEmpty(createdResponse.ErrorMessage))
            {
                DeleteGroup(createdGroup);
                Assert.Fail();
            }

            Assert.IsTrue(createdConnector2Message.Contains(createdConnector1.Id.ToString()));
            DeleteGroup(createdGroup);
        }
        public IActionResult Create([FromBody] CreateOrUpdateConnectorCommand command)
        {
            if (command == null)
            {
                return(BadRequest());
            }

            var result = _mediator.Send(command).Result;

            if (!string.IsNullOrEmpty(result.ErrorMessage))
            {
                return(StatusCode(200, result));
            }

            var connector = result.Content as Connector;

            return(Created($"{HttpContext.Request.GetUri()}/{connector.Id}", result));
        }
        public void When_CreateConnectorThatExceedsGroupCapacity_Expect_Error()
        {
            var errorMessage         = string.Empty;
            var createdGroup         = CreateGroup();
            var createdChargeStation = CreateChargeStation(createdGroup);

            var createConnectorCommand = new CreateOrUpdateConnectorCommand()
            {
                Connector = new Connector()
                {
                    MaxCurrent = 101, ChargeStationId = createdChargeStation.Id
                }
            };

            var actionResult = _connectorController.Create(createConnectorCommand);

            DeleteGroup(createdGroup);

            _ = ActionResultParser.ParseObjectResult <Connector>(actionResult, out errorMessage);

            Assert.IsTrue(!string.IsNullOrEmpty(errorMessage));
        }