Exemplo n.º 1
0
        public async Task Invoke_Error(String path, String renderedPath)
        {
            ILanguages languages = new Languages("en-GB", new[] { new Language {
                                                                      Abbreviation = "en-GB"
                                                                  } });
            ILogger <ErrorResponseMiddleware> logger = Substitute.For <ILogger <ErrorResponseMiddleware> >();
            HttpContext actual = MvcHelperFactory.CreateViewContext().HttpContext;

            actual.Request.RouteValues.Add("test", "test");
            actual.Request.Path = path;
            Boolean asserted = false;

            await new ErrorResponseMiddleware(actual =>
            {
                if (actual.Request.Path != renderedPath)
                {
                    throw new Exception();
                }

                asserted = true;

                return(Task.CompletedTask);
            }, languages, logger).Invoke(actual);

            Assert.True(asserted);
            Assert.Empty(actual.Request.RouteValues);
            Assert.Equal(renderedPath, actual.Request.Path);
            Assert.Equal(HttpMethods.Get, actual.Request.Method);
        }
Exemplo n.º 2
0
 public SiteMapTests()
 {
     context       = MvcHelperFactory.CreateViewContext();
     authorization = Substitute.For <IAuthorization>();
     siteMap       = new SiteMap(CreateSiteMap(), authorization);
     route         = context.RouteData.Values;
 }
Exemplo n.º 3
0
 public TruncatedAttributeTests()
 {
     values                = new RouteValueDictionary();
     attribute             = new TruncatedAttribute();
     context               = new DefaultModelBindingContext();
     context.ModelState    = new ModelStateDictionary();
     context.ModelName     = "TruncatedDateTimeParameter";
     context.ActionContext = MvcHelperFactory.CreateViewContext();
     context.ValueProvider = new RouteValueProvider(BindingSource.Path, values);
     context.ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(typeof(DateTime?));
 }
Exemplo n.º 4
0
        public AuthorizeTagHelperTests()
        {
            authorization = Substitute.For <IAuthorization>();
            TagHelperContent content = new DefaultTagHelperContent();

            helper = new AuthorizeTagHelper(authorization)
            {
                ViewContext = MvcHelperFactory.CreateViewContext()
            };
            context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <Object, Object>(), "test");
            output  = new TagHelperOutput("authorize", new TagHelperAttributeList(), (_, _) => Task.FromResult(content));
        }
Exemplo n.º 5
0
        public SiteMapNodeTests()
        {
            helper = Substitute.For <IUrlHelper>();
            ViewContext context = MvcHelperFactory.CreateViewContext();

            helper.ActionContext.Returns(context);
            helper.Action(Arg.Any <UrlActionContext>()).Returns(info =>
            {
                UrlActionContext context   = info.Arg <UrlActionContext>();
                RouteValueDictionary route = new(info.Arg <UrlActionContext>().Values);
                String query = String.Join("&", route.Where(pair => pair.Key != "area").Select(pair => $"{pair.Key}={pair.Value}"));

                return($"{route["area"]}/{context.Controller}/{context.Action}?{query}");
            });
        }
Exemplo n.º 6
0
        public async Task BindModelAsync_DoesNotTrimValue()
        {
            DefaultModelBindingContext context = new()
            {
                ModelName     = "Test",
                ModelState    = new ModelStateDictionary(),
                ActionContext = MvcHelperFactory.CreateViewContext(),
                ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(typeof(String)),
                ValueProvider = new RouteValueProvider(BindingSource.Path, new RouteValueDictionary(new { Test = " Value  " }))
            };

            await new NotTrimmedAttribute().BindModelAsync(context);

            ModelBindingResult expected = ModelBindingResult.Success(" Value  ");
            ModelBindingResult actual   = context.Result;

            Assert.Equal(expected, actual);
        }
    }
Exemplo n.º 7
0
        public AppStyleTagHelperTests()
        {
            host = Substitute.For <IWebHostEnvironment>();
            TagHelperContent  content     = new DefaultTagHelperContent();
            ViewContext       viewContext = MvcHelperFactory.CreateViewContext();
            IUrlHelperFactory factory     = MvcHelperFactory.CreateUrlHelperFactory(viewContext);

            context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <Object, Object>(), "test");
            output  = new TagHelperOutput("link", new TagHelperAttributeList(), (_, _) => Task.FromResult(content));

            host.WebRootPath.Returns(Directory.GetCurrentDirectory());
            helper             = new AppStyleTagHelper(host, factory);
            helper.ViewContext = viewContext;
            helper.Action      = "Test";

            if (Directory.Exists("css"))
            {
                Directory.Delete("css", true);
            }
        }