public async Task Should_SaveDetails_WhenRegistering()
        {
            var newPath = Create(_path, Layout.FullWidth);

            await _pathService.Register(newPath);

            var existingPath = await _pathService.Get(newPath.Path);

            Assert.IsNotNull(existingPath);
            Assert.AreEqual(newPath.Path, existingPath.Path);
            Assert.AreEqual(newPath.Layout, existingPath.Layout);
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "paths/{path}")] HttpRequest req,
            string path)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrWhiteSpace(path))
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.UnableToLocatePathInQueryString);
                return(new BadRequestResult());
            }

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get path {path}");
            var pathModel = await _pathService.Get(path);

            if (pathModel == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PathDoesNotExist);
                return(new NoContentResult());
            }

            _loggerHelper.LogMethodExit(_logger);

            return(new OkObjectResult(pathModel));
        }
Exemple #3
0
        public async Task CallingGet_CallsSearchOnDocumentStorage()
        {
            var pathModels = GetPathModels();

            documentStorage.Setup(x => x.Search(It.IsAny <Expression <Func <PathModel, bool> > >())).ReturnsAsync(pathModels);

            await pathService.Get(path);

            documentStorage.Verify(x => x.Search(It.IsAny <Expression <Func <PathModel, bool> > >()), Times.Once());
        }
Exemple #4
0
        public async Task Should_Delete_ExistingPath()
        {
            var newPath = Create(_path, Layout.FullWidth);
            await _pathService.Register(newPath);

            await _pathService.Delete(newPath.Path);

            var existingPath = await _pathService.Get(newPath.Path);

            Assert.IsNull(existingPath);
        }
Exemple #5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "paths/{path}")] HttpRequest req,
            string path)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrEmpty(path))
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.UnableToLocatePathInQueryString);
                return(new BadRequestResult());
            }

            var body = await req.GetBodyAsync <PathModel>();

            if (body == null || body.Value == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PayloadMalformed);
                return(new BadRequestResult());
            }

            if (!body.IsValid)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.ValidationFailed);
                return(new BadRequestObjectResult(body.ValidationResults));
            }

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get path for {path}");
            var currentPath = await _pathService.Get(path);

            if (currentPath == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PathDoesNotExist);
                return(new NoContentResult());
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get update path for {path}");
                await _pathService.Update(body.Value);

                _loggerHelper.LogMethodExit(_logger);
                return(new OkResult());
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new UnprocessableEntityObjectResult(ex));
            }
        }
        public async Task Should_UpdateDetails()
        {
            var newPath = Create(_path, Layout.FullWidth);

            await _pathService.Register(newPath);

            var existingPath = await _pathService.Get(newPath.Path);

            existingPath.TopNavigationText = "TopNavigationText";
            await _pathService.Update(existingPath);

            var modifiedPath = await _pathService.Get(newPath.Path);

            Assert.IsNotNull(existingPath);
            Assert.AreEqual(existingPath.Path, modifiedPath.Path);
            Assert.AreEqual(existingPath.Layout, modifiedPath.Layout);
            Assert.AreEqual(existingPath.TopNavigationText, modifiedPath.TopNavigationText);
        }
Exemple #7
0
        public ActionResult Get(int id)
        {
            var result = _pathService.Get(id);

            return(Ok(result));
        }
Exemple #8
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "paths/{path}")] HttpRequest req,
            string path)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrWhiteSpace(path))
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.UnableToLocatePathInQueryString);
                return(new BadRequestResult());
            }

            JsonPatchDocument <PathModel> pathPatch = null;

            try
            {
                var requestBody = await req.ReadAsStringAsync();

                pathPatch = JsonConvert.DeserializeObject <JsonPatchDocument <PathModel> >(requestBody);
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new BadRequestResult());
            }

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get path {path}'");
            var currentPath = await _pathService.Get(path);

            if (currentPath == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PathDoesNotExist);
                return(new NoContentResult());
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to apply patch to {path}");
                pathPatch.ApplyTo(currentPath);
                var validationResults = currentPath.Validate(new ValidationContext(currentPath));

                if (validationResults.Any())
                {
                    _loggerHelper.LogInformationMessage(_logger, correlationId, Message.ValidationFailed);
                    return(new BadRequestObjectResult(validationResults));
                }
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new BadRequestResult());
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to update path {path}");
                await _pathService.Update(currentPath);

                _loggerHelper.LogMethodExit(_logger);
                return(new OkObjectResult(currentPath));
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new UnprocessableEntityObjectResult(ex));
            }
        }