public void IsPageMethod_ThrowsForNullMethodSymbol() { Assert.Throws <ArgumentNullException>(() => { var isControllerAction = PagesFacts.IsPageMethod(null); }); }
private static INamedTypeSymbol GetPageModel(RazorPageItem razorPage, Compilation compilation, Dictionary <string, List <string> > usingsByDirectory) { if (razorPage.Model == null) { return(null); } // First try to get the page model based on the usings in this file var explicitUsings = PagesFacts.ExtractUsings(razorPage); var pageModel = FindPageModel(compilation, razorPage.Model, explicitUsings); if (pageModel != null) { return(pageModel); } // Walk up the path and try to get the page model based on usings in the implicitly included files foreach (var path in EnumerateUpPath(razorPage.AdditionalText.Path)) { if (usingsByDirectory.TryGetValue(path, out var usings)) { pageModel = FindPageModel(compilation, razorPage.Model, usings); if (pageModel != null) { return(pageModel); } } } // Last try to get the page model based on what is in @model without a using return(FindPageModel(compilation, razorPage.Model, new List <string> { "" }));
public void IsRazorPage_ReturnsFalse() { var file = new InMemoryAdditionalText("", ""); // Act var result = PagesFacts.IsRazorPage(file); // Assert result.Should().BeFalse(); }
public void ExtractUsings_ReturnsEmpty_WhenNoUsings() { var file = new InMemoryAdditionalText("", ""); var pageData = new RazorPageItem(file); // Act var result = PagesFacts.ExtractUsings(pageData); // Assert result.Should().BeEmpty(); }
public void IsImplicitlyIncludedFile(string path, bool expected) { var file = new InMemoryAdditionalText(path, ""); var pageData = new RazorPageItem(file); // Act var result = PagesFacts.IsImplicitlyIncludedFile(pageData); // Assert result.Should().Be(expected); }
private void IsPageMethodReturnsTrue(Type type, string methodName) { var compilation = GetIsPageMethodCompilation(); var typeSymbol = compilation.GetTypeByMetadataName(type.FullName); var method = (IMethodSymbol)typeSymbol.GetMembers(methodName).First(); // Act var isControllerAction = PagesFacts.IsPageMethod(method); // Assert Assert.True(isControllerAction); }
public void ExtractUsings_ReturnsUsings() { var file = new InMemoryAdditionalText("", @"@using System @using System.Text"); var pageData = new RazorPageItem(file); // Act var result = PagesFacts.ExtractUsings(pageData); // Assert result.Should().BeEquivalentTo(new[] { "System", "System.Text", }); }