public void HtmlLocalizer_HtmlWithArguments_ReturnsLocalizedHtml( string format, object[] arguments, string expectedText) { // Arrange var localizedString = new LocalizedString("Hello", format); var stringLocalizer = new Mock <IStringLocalizer>(); stringLocalizer.Setup(s => s["Hello"]).Returns(localizedString); var htmlLocalizer = new HtmlLocalizer(stringLocalizer.Object); // Act var localizedHtmlString = htmlLocalizer.GetHtml("Hello", arguments); // Assert Assert.NotNull(localizedHtmlString); Assert.Equal(format, localizedHtmlString.Value); using (var writer = new StringWriter()) { localizedHtmlString.WriteTo(writer, new HtmlTestEncoder()); Assert.Equal(expectedText, writer.ToString()); } }
public void HtmlLocalizer_Html_ReturnsLocalizedHtmlString() { // Arrange var stringLocalizer = new TestStringLocalizer(); var htmlLocalizer = new HtmlLocalizer(stringLocalizer); // Act var actualLocalizedHtmlString = htmlLocalizer.GetHtml("John"); // Assert Assert.Equal("Hello John", actualLocalizedHtmlString.Value); }
public void HtmlLocalizer_HtmlWithInvalidResourceString_ContentThrowsException(string format) { // Arrange var localizedString = new LocalizedString("Hello", format); var stringLocalizer = new Mock <IStringLocalizer>(); stringLocalizer.Setup(s => s["Hello"]).Returns(localizedString); var htmlLocalizer = new HtmlLocalizer(stringLocalizer.Object); var content = htmlLocalizer.GetHtml("Hello", new object[] { }); // Act var exception = Assert.Throws <FormatException>( () => content.WriteTo(TextWriter.Null, new HtmlTestEncoder())); // Assert Assert.NotNull(exception); Assert.Equal("Input string was not in a correct format.", exception.Message); }
public void HtmlLocalizer_HtmlWithInvalidResourceString_ContentThrowsException(string format) { // Arrange var localizedString = new LocalizedString("Hello", format); var stringLocalizer = new Mock<IStringLocalizer>(); stringLocalizer.Setup(s => s["Hello"]).Returns(localizedString); var htmlLocalizer = new HtmlLocalizer(stringLocalizer.Object); var content = htmlLocalizer.GetHtml("Hello", new object[] { }); // Act var exception = Assert.Throws<FormatException>( () => content.WriteTo(TextWriter.Null, new HtmlTestEncoder())); // Assert Assert.NotNull(exception); Assert.Equal("Input string was not in a correct format.", exception.Message); }
public void HtmlLocalizer_HtmlWithArguments_ReturnsLocalizedHtml( string format, object[] arguments, string expectedText) { // Arrange var localizedString = new LocalizedString("Hello", format); var stringLocalizer = new Mock<IStringLocalizer>(); stringLocalizer.Setup(s => s["Hello"]).Returns(localizedString); var htmlLocalizer = new HtmlLocalizer(stringLocalizer.Object); // Act var localizedHtmlString = htmlLocalizer.GetHtml("Hello", arguments); // Assert Assert.NotNull(localizedHtmlString); Assert.Equal(format, localizedHtmlString.Value); using (var writer = new StringWriter()) { localizedHtmlString.WriteTo(writer, new HtmlTestEncoder()); Assert.Equal(expectedText, writer.ToString()); } }