// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Text; using Microsoft.PowerToys.PreviewHandler.Svg.Utilities; using Microsoft.PowerToys.STATestExtension; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace SvgPreviewHandlerUnitTests { [STATestClass] public class SvgPreviewHandlerHelperTests { [TestMethod] public void CheckBlockedElementsShouldReturnTrueIfABlockedElementIsPresent() { // Arrange var svgBuilder = new StringBuilder(); svgBuilder.AppendLine(""); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine(""); bool foundFilteredElement; // Act foundFilteredElement = SvgPreviewHandlerHelper.CheckBlockedElements(svgBuilder.ToString()); // Assert Assert.IsTrue(foundFilteredElement); } [TestMethod] public void CheckBlockedElementsShouldReturnTrueIfBlockedElementsIsPresentInNestedLevel() { // Arrange var svgBuilder = new StringBuilder(); svgBuilder.AppendLine(""); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine("\t\t"); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine(""); bool foundFilteredElement; // Act foundFilteredElement = SvgPreviewHandlerHelper.CheckBlockedElements(svgBuilder.ToString()); // Assert Assert.IsTrue(foundFilteredElement); } [TestMethod] public void CheckBlockedElementsShouldReturnTrueIfMultipleBlockedElementsArePresent() { // Arrange var svgBuilder = new StringBuilder(); svgBuilder.AppendLine(""); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine(""); bool foundFilteredElement; // Act foundFilteredElement = SvgPreviewHandlerHelper.CheckBlockedElements(svgBuilder.ToString()); // Assert Assert.IsTrue(foundFilteredElement); } [TestMethod] public void CheckBlockedElementsShouldReturnFalseIfNoBlockedElementsArePresent() { // Arrange var svgBuilder = new StringBuilder(); svgBuilder.AppendLine(""); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine("\t"); svgBuilder.AppendLine(""); bool foundFilteredElement; // Act foundFilteredElement = SvgPreviewHandlerHelper.CheckBlockedElements(svgBuilder.ToString()); // Assert Assert.IsFalse(foundFilteredElement); } [DataTestMethod] [DataRow("")] [DataRow(" ")] [DataRow(null)] public void CheckBlockedElementsShouldReturnFalseIfSvgDataIsNullOrWhiteSpaces(string svgData) { // Arrange bool foundFilteredElement; // Act foundFilteredElement = SvgPreviewHandlerHelper.CheckBlockedElements(svgData); // Assert Assert.IsFalse(foundFilteredElement); } } }