public static MvcHtmlString GetAntiForgeryToken(this HtmlHelper helper, Uri url) { var logger = Log.Logger; var serializer = new ApprovedDomainSerializer(); var check = new StaticDomainCheck(logger, serializer); var tokenizer = new AntiforgeryTokenizer(helper); string currentDomain = GetDomainName(url); var generator = new AntiforgeryTokenGenerator(check, tokenizer, currentDomain); return generator.GetAntiForgeryToken(); }
public void Test(string currentDomain, string expectedToken) { var logger = new FakeLogger(); var serializer = new FakeDomainSerializer(); var check = new StaticDomainCheck(logger, serializer); var tokenizer = new FakeTokenizer(); var generator = new AntiforgeryTokenGenerator(check, tokenizer, currentDomain); var result = generator.GetAntiForgeryToken(); var expected = new MvcHtmlString(expectedToken); Assert.Equal(expected.ToString(), result.ToString()); }