Beispiel #1
0
        public ActionResult List(ShortUrlListCommand command)
        {
            int urlPerPage            = settings.UrlPerPage;
            ShortUrlListResult result = shortUrlService.FindByUser(command.UserName, PageCalculator.StartIndex(command.Page, urlPerPage), urlPerPage);

            object model = new PagedListViewModel <ShortUrlDTO>(result.ShortUrls, command.Page ?? 1, urlPerPage, result.Total);

            return(this.AdaptiveView(result.RuleViolations, model));
        }
        public ShortUrlListResultTests()
        {
            var alias = new Alias {
                Name = "dtntshtt", ShortUrl = new ShortUrl {
                    Title = "Daily .NET News", Url = "http://dotnetshoutout.com"
                }
            };

            dto = new ShortUrlDTO(alias, 3, "http://shrinkr.com/1", "http://shrinkr.com/Preview/1");

            var pagedResult = new PagedResult <ShortUrlDTO>(new List <ShortUrlDTO> {
                dto
            }, 1);

            result = new ShortUrlListResult(pagedResult);
        }
Beispiel #3
0
        public void List_should_use_short_url_service_to_find_url_list_by_user()
        {
            controller.MockHttpContext("/", "~/List", "GET");

            var alias = new Alias {
                ShortUrl = new ShortUrl()
            };
            var pagedResult = new PagedResult <ShortUrlDTO>(new List <ShortUrlDTO> {
                new ShortUrlDTO(alias, 3, "http://url.com", "http://url.com")
            }, 10);
            var urlResult = new ShortUrlListResult(pagedResult);

            settings.UrlPerPage = 1;
            shortUrlService.Setup(svc => svc.FindByUser(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(urlResult).Verifiable();

            controller.List(new ShortUrlListCommand());

            shortUrlService.VerifyAll();
        }
Beispiel #4
0
        public void List_should_return_adaptive_view_result()
        {
            controller.MockHttpContext("/", "~/List", "GET");

            var alias = new Alias {
                ShortUrl = new ShortUrl()
            };
            var pagedResult = new PagedResult <ShortUrlDTO>(new List <ShortUrlDTO> {
                new ShortUrlDTO(alias, 3, "http://url.com", "http://url.com")
            }, 1);
            var urlResult = new ShortUrlListResult(pagedResult);

            settings.UrlPerPage = 1;

            shortUrlService.Setup(svc => svc.FindByUser(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(urlResult);

            var view = controller.List(new ShortUrlListCommand());

            Assert.IsType(typeof(AdaptiveViewResult), view);
        }
Beispiel #5
0
        public void List_should_add_violation_rules_to_model_errors()
        {
            controller.MockHttpContext("/", "~/List", "GET");

            var alias = new Alias {
                ShortUrl = new ShortUrl()
            };
            var pagedResult = new PagedResult <ShortUrlDTO>(new List <ShortUrlDTO> {
                new ShortUrlDTO(alias, 3, "http://url.com", "http://url.com")
            }, 10);
            var urlResult = new ShortUrlListResult(pagedResult);

            settings.UrlPerPage = 1;
            urlResult.RuleViolations.Add(new RuleViolation("someParam", "Error Message"));

            shortUrlService.Setup(svc => svc.FindByUser(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns(urlResult);

            var view = (AdaptiveViewResult)controller.List(new ShortUrlListCommand {
                Page = 1
            });

            Assert.Equal(1, view.ViewData.ModelState.Count);
        }