public void Given_NotExistingRedirect_Controller_TriesToUpdateAndThrowsExceptionRedirectNotFound()
        {
            var restController = RedirectRuleController()
                                 .WithRandomExistingRules()
                                 .Create();

            var redirectDto = new RedirectRuleDto(Guid.NewGuid(), "/NonExistentOldPath", "/randomNewUrl",
                                                  RedirectType.Temporary);

            Assert.Throws <KeyNotFoundException>(() => restController.Put(redirectDto));
        }
        public void Given_ExistingRedirects_Controller_CreatesNewRedirect()
        {
            var restController = RedirectRuleController()
                                 .WithRandomExistingRules()
                                 .Create();

            var redirectDto = new RedirectRuleDto("randomOldPath", "randomNewPath");

            var newRedirect      = restController.Post(redirectDto).GetEntityFromActionResult();
            var expectedRedirect = restController.Get(newRedirect.Id.Value).GetEntityFromActionResult();

            Assert.NotNull(expectedRedirect);
        }
        public ActionResult Put(RedirectRuleDto dto)
        {
            if (!ViewData.ModelState.IsValid)
            {
                return(null);
            }

            var updatedRedirectRule = _redirectRuleMapper.DtoToModel(dto);

            updatedRedirectRule = _redirectRuleRepository.Update(updatedRedirectRule);

            var updatedRedirectRuleDto = _redirectRuleMapper.ModelToDto(updatedRedirectRule);

            return(Rest(updatedRedirectRuleDto));
        }
Пример #4
0
        private static RedirectRule DtoToModelDelegate(RedirectRuleDto source)
        {
            var destination = new RedirectRule();

            destination.Id               = source.Id;
            destination.OldPattern       = UrlPath.ExtractRelativePath(source.OldPattern);
            destination.NewPattern       = UrlPath.ExtractRelativePath(source.NewPattern);
            destination.RedirectType     = source.RedirectType;
            destination.RedirectRuleType = source.RedirectRuleType;
            destination.IsActive         = source.IsActive;
            destination.Notes            = source.Notes;
            destination.ContentId        = source.ContentId;
            destination.Priority         = (source.Priority.HasValue && source.Priority > 0) ? source.Priority.Value : Configuration.Configuration.DefaultRedirectRulePriority;

            return(destination);
        }
        public ActionResult Post(RedirectRuleDto dto)
        {
            if (!ViewData.ModelState.IsValid)
            {
                return(null);
            }

            var newRedirectRule = _redirectRuleMapper.DtoToModel(dto);

            newRedirectRule.FromManual();

            newRedirectRule = _redirectRuleRepository.Add(newRedirectRule);

            var newRedirectRuleDto = _redirectRuleMapper.ModelToDto(newRedirectRule);

            return(Rest(newRedirectRuleDto));
        }
Пример #6
0
        private static RedirectRuleDto ModelToDtoDelegate(RedirectRule source)
        {
            var destination = new RedirectRuleDto();

            destination.Id               = source.Id.ExternalId;
            destination.OldPattern       = source.OldPattern;
            destination.NewPattern       = source.NewPattern;
            destination.ContentId        = source.ContentId;
            destination.RedirectType     = source.RedirectType;
            destination.RedirectRuleType = source.RedirectRuleType;
            destination.RedirectOrigin   = source.RedirectOrigin;
            destination.IsActive         = source.IsActive;
            destination.Notes            = source.Notes;
            destination.CreatedOn        = DateTime.SpecifyKind(source.CreatedOn, DateTimeKind.Utc);
            destination.CreatedBy        = source.CreatedBy;
            destination.Priority         = source.Priority;

            return(destination);
        }
        public void Given_ExistingRedirects_Controller_ReturnsAllRedirects()
        {
            var rule1         = RandomDataGenerator.CreateRandomRedirectRule();
            var rule2         = RandomDataGenerator.CreateRandomRedirectRule();
            var existingRules = new HashSet <RedirectRule>
            {
                rule1,
                rule2
            };
            var dto1 = new RedirectRuleDto();
            var dto2 = new RedirectRuleDto();

            var restController = RedirectRuleController()
                                 .WithExplicitExistingRules(existingRules)
                                 .WithMapper(r => r == rule1 ? dto1 : r == rule2 ? dto2 : null)
                                 .WithHttpResponseHeaders()
                                 .Create();
            var resolvedRules = restController
                                .Get()
                                .GetEntitiesFromActionResult();

            Assert.Equal(new[] { dto1, dto2 }, resolvedRules);
        }
        public RedirectRule DtoToModel(RedirectRuleDto source)
        {
            var destination = DtoToModelDelegate(source);

            return(destination);
        }