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 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 IActionResult Create([FromBody] CreateChargeStationCommand command)
        {
            if (command == null)
            {
                return(BadRequest());
            }

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

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

            var chargeStation = result.Content as ChargeStation;

            return(Created($"{HttpContext.Request.GetUri()}/{chargeStation.Id}", result));
        }
        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();
        }