Esempio n. 1
0
        public async Task TestDeleteValidModelShouldReturnTrue()
        {
            var model = new NodeDeletePostModel()
            {
                NodeId = 1
            };

            var result = await controller.Delete(model);

            var jsonResult = result as JsonResult;

            var deleted = jsonResult?.Value as bool?;

            Assert.IsTrue(deleted);
        }
Esempio n. 2
0
        public async Task TestDeleteInvalidModelShouldReturnErrorMessage()
        {
            controller.ModelState.AddModelError("test", "test");

            var model = new NodeDeletePostModel()
            {
                NodeId = -1
            };

            var result = await controller.Delete(model);

            var badRequestResult = result as BadRequestObjectResult;

            Assert.IsNotNull(badRequestResult);
            Assert.AreEqual(400, badRequestResult.StatusCode);
            Assert.AreEqual("Invalid request.", badRequestResult.Value as string);
        }
Esempio n. 3
0
        public async Task <IActionResult> Delete([FromBody] NodeDeletePostModel model)
        {
            if (model == null || ModelState.IsValid == false)
            {
                return(BadRequest("Invalid request."));
            }

            try
            {
                var result = await deleteNode.ExecuteAsync(model.NodeId);

                return(new JsonResult(result));
            }
            catch (Exception e)
            {
                return(BadRequest("Failed to delete settlement"));
            }
        }