Beispiel #1
0
        public async Task DeleteBusiness_IsSuccessful()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var businessToDelete = new NodeDto
            {
                Id   = 1,
                Type = "Business"
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var result = await _treeService.DeleteNodeAsync(businessToDelete);

            var actualTree = await _treeService.GetTreeAsync();

            Assert.True(result.Succeeded);
            Assert.Equal(5, actualTree.Count);
        }
Beispiel #2
0
        public async Task DeleteNode_WrongNodeType_IsFailed()
        {
            _treeService = GetTreeService();

            var dataToSetupDB = GetNodes();

            var nodeToDelete = new NodeDto
            {
                Id   = 1,
                Type = "Home"
            };

            foreach (var node in dataToSetupDB)
            {
                var dbSetupResult = await _treeService.CreateNodeAsync(node);

                Assert.True(dbSetupResult.Succeeded);
            }

            var actualResult = await _treeService.DeleteNodeAsync(nodeToDelete);

            var expectResult = new ServiceResult($"Not found such type as: {nodeToDelete.Type}");

            var actualTree = await _treeService.GetTreeAsync();

            Assert.Equal(12, actualTree.Count);
            Assert.Equal(expectResult.Succeeded, actualResult.Succeeded);
            Assert.Equal(expectResult.Error, actualResult.Error);
        }
Beispiel #3
0
        public async Task <ActionResult> DeleteNode([FromBody] NodeToDeleteModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ResponseModel(400, "Invalid value was entered! Please, redisplay form.")));
            }

            var nodeDto = _mapper.Map <NodeDto>(model);

            var result = await _treeService.DeleteNodeAsync(nodeDto);

            return(result.Succeeded
                ? Ok(new ResponseModel(200, "Completed.", "Node deleted."))
                : (ActionResult)BadRequest(new ResponseModel(400, "Failed.", result.Error)));
        }