public void When_DeleteGroup_Expect_GroupDeletion()
        {
            var errorMessage = string.Empty;
            var guid         = Guid.NewGuid().ToString();
            var newGroup     = new CreateGroupCommand()
            {
                Group = new Group()
                {
                    Name = guid, CurrentCapacity = 100M
                }
            };
            var actionResult = _groupController.Create(newGroup);

            var createdGroup = ActionResultParser.ParseCreatedResult <Group>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            if (createdGroup.Id == 0)
            {
                Assert.Fail();
            }

            actionResult = _groupController.Delete(createdGroup.Id);

            var deletedGroup = ActionResultParser.ParseObjectResult <Group>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            Assert.AreEqual(createdGroup.Id, deletedGroup.Id);
        }
        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 void When_DeleteChargeStation_Expect_ChargeStationDeletion()
        {
            var errorMessage = string.Empty;

            var createdGroup = CreateGroup();

            var guid = Guid.NewGuid().ToString();
            var newChargeStationCommand = new CreateChargeStationCommand()
            {
                ChargeStation = new ChargeStation()
                {
                    Name = guid, GroupId = createdGroup.Id
                }
            };

            var actionResult = _chargeStationController.Create(newChargeStationCommand);

            var createdChargeStation = ActionResultParser.ParseCreatedResult <ChargeStation>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            actionResult = _chargeStationController.Delete(createdChargeStation.Id);

            var deletedChargeStation = ActionResultParser.ParseObjectResult <ChargeStation>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            Assert.AreEqual(createdChargeStation.Id, deletedChargeStation.Id);

            DeleteGroup(createdGroup);
        }
        public void When_CreateChargeStation_Expect_ChargeStationCreation()
        {
            var errorMessage = string.Empty;

            var createdGroup = CreateGroup();

            var guid = Guid.NewGuid().ToString();
            var newChargeStationCommand = new CreateChargeStationCommand()
            {
                ChargeStation = new ChargeStation()
                {
                    Name = guid, GroupId = createdGroup.Id
                }
            };

            var actionResult = _chargeStationController.Create(newChargeStationCommand);

            var createdChargeStation = ActionResultParser.ParseCreatedResult <ChargeStation>(actionResult, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                Assert.Fail();
            }

            Assert.AreNotEqual(0, createdChargeStation.Id);

            DeleteGroup(createdGroup);
        }
        private Group CreateGroup()
        {
            var errorMessage    = string.Empty;
            var guid            = Guid.NewGuid().ToString();
            var newGroupCommand = new CreateGroupCommand()
            {
                Group = new Group()
                {
                    Name = guid, CurrentCapacity = 100M
                }
            };

            var actionResult = _groupController.Create(newGroupCommand);

            return(ActionResultParser.ParseCreatedResult <Group>(actionResult, out errorMessage));
        }
        private ChargeStation CreateChargeStation(Group group)
        {
            var errorMessage            = string.Empty;
            var guid                    = Guid.NewGuid().ToString();
            var newChargeStationCommand = new CreateChargeStationCommand()
            {
                ChargeStation = new ChargeStation()
                {
                    Name = guid, GroupId = group.Id
                }
            };

            var actionResult = _chargeStationController.Create(newChargeStationCommand);

            return(ActionResultParser.ParseCreatedResult <ChargeStation>(actionResult, out errorMessage));
        }
        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 void When_UpdateGroupName_Expect_GroupUpdate()
        {
            var errorMessage    = string.Empty;
            var guid            = Guid.NewGuid().ToString();
            var newGroupCommand = new CreateGroupCommand()
            {
                Group = new Group()
                {
                    Name = guid, CurrentCapacity = 100M
                }
            };
            var actionResult = _groupController.Create(newGroupCommand);

            var createdGroup = ActionResultParser.ParseCreatedResult <Group>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            if (createdGroup.Id == 0)
            {
                Assert.Fail();
            }

            var newGuid            = Guid.NewGuid().ToString();
            var groupUpdateCommand = new UpdateGroupCommand()
            {
                Group = new Group()
                {
                    Id = createdGroup.Id, CurrentCapacity = createdGroup.CurrentCapacity, Name = newGuid
                }
            };

            actionResult = _groupController.Update(groupUpdateCommand);

            var updatedGroup = ActionResultParser.ParseOkObjectResult <Group>(actionResult, out errorMessage);

            CheckErrorMessage(errorMessage);

            Assert.AreEqual(newGuid, updatedGroup.Name);

            DeleteGroup(updatedGroup);
        }
        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));
        }
        public void When_CreateChargeStationWithoutGroup_Expect_ErrorMessage()
        {
            var errorMessage = string.Empty;

            var guid = Guid.NewGuid().ToString();
            var newChargeStationCommand = new CreateChargeStationCommand()
            {
                ChargeStation = new ChargeStation()
                {
                    Name = guid
                }
            };

            var actionResult = _chargeStationController.Create(newChargeStationCommand);

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

            if (errorMessage.Contains("Parent Group not found"))
            {
                Assert.Pass();
            }

            Assert.Fail();
        }