public void GetToken() { var responseContent = new StringBuilder(); responseContent.AppendLine("<html>"); responseContent.AppendLine("<body>"); responseContent.AppendLine("<form>"); responseContent.AppendLine("<input name=\"__RequestVerificationToken\" type=\"hidden\" value=\"ThisIsATestToken\"/>"); responseContent.AppendLine("</form>"); responseContent.AppendLine("</body>"); responseContent.AppendLine("</html>"); var response = new HttpClientProxyResponse { StatusCode = HttpStatusCode.OK, Contents = responseContent.ToString() }; var client = new Mock <IHttpClientProxy>(); client.Setup(x => x.SendAsync(It.IsAny <HttpClientProxyRequest>())) .Returns(Task.FromResult(response)); var sut = new AntiForgeryAction(client.Object); var result = sut.GetToken(""); Assert.Equal("ThisIsATestToken", result); }
public void GetTokenWithNoNameThrowsArguementException() { var client = new Mock <IHttpClientProxy>(); var sut = new AntiForgeryAction(client.Object); var ex = Assert.Throws <ArgumentNullException>(() => sut.GetToken(null) ); Assert.Contains("relativePath", ex.Message); }