// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System;
using System.Web.Mvc;
using Microsoft.Web.UnitTestUtil;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace Microsoft.Web.Mvc.Test
{
public class CssExtensionsTests
{
[Fact]
public void CssWithoutFileThrowsArgumentNullException()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Assert
Assert.ThrowsArgumentNullOrEmpty(() => html.Css(null), "file");
}
[Fact]
public void CssWithRootedPathRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("~/Correct/Path.css");
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithRelativePathRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("../../Correct/Path.css");
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithRelativeCurrentPathRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("/Correct/Path.css");
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithContentRelativePathRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("Correct/Path.css");
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithNullMediaTypeRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("Correct/Path.css", null);
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithEmptyMediaTypeRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("Correct/Path.css", String.Empty);
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithMediaTypeRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("Correct/Path.css", "Print");
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithUrlRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("http://ajax.Correct.com/Path.js");
// Assert
Assert.Equal("", result.ToHtmlString());
}
[Fact]
public void CssWithSecureUrlRendersProperElement()
{
// Arrange
HtmlHelper html = MvcHelper.GetHtmlHelperWithPath(new ViewDataDictionary());
// Act
MvcHtmlString result = html.Css("https://ajax.Correct.com/Path.js");
// Assert
Assert.Equal("", result.ToHtmlString());
}
}
}