Ejemplo 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);
        }
Ejemplo n.º 2
0
 public SiteMapTests()
 {
     context       = MvcHelperFactory.CreateViewContext();
     authorization = Substitute.For <IAuthorization>();
     siteMap       = new SiteMap(CreateSiteMap(), authorization);
     route         = context.RouteData.Values;
 }
Ejemplo n.º 3
0
        public MvcGridExtensionsTests()
        {
            Grid <AllTypesView> grid   = new(Array.Empty <AllTypesView>());
            IHtmlHelper         helper = MvcHelperFactory.CreateHtmlHelper();

            html    = new HtmlGrid <AllTypesView>(helper, grid);
            columns = new GridColumns <AllTypesView>(grid);
            context = html.Grid.ViewContext !;
        }
Ejemplo n.º 4
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?));
 }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
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}");
            });
        }
Ejemplo n.º 7
0
        public void Process_Url(String? url, String newUrl)
        {
            TagHelperContent content = new DefaultTagHelperContent();
            IUrlHelperFactory factory = MvcHelperFactory.CreateUrlHelperFactory(null);
            MvcLookupTagHelper helper = new(Substitute.For<IHtmlGenerator>(), factory);
            TagHelperContext context = new(new TagHelperAttributeList(), new Dictionary<Object, Object>(), "test");
            TagHelperOutput output = new("div", new TagHelperAttributeList(), (_, _) => Task.FromResult(content));

            helper.Url = url;
            helper.Handler = "Handling";

            helper.Process(context, output);

            String? expected = newUrl;
            String? actual = helper.Url;

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 8
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);
        }
    }
Ejemplo n.º 9
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);
            }
        }