From 07d91ce9acb488ac519ec25fc79a9aa7987f508d Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Sun, 21 May 2017 11:34:21 +0200 Subject: [PATCH] Removes some code duplication by using parameterized test Add some debugging to unit test to figure out what's wrong with it --- .../UmbracoSettings/ContentElementTests.cs | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs b/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs index 5ad7f9cc51..b41b0d2683 100644 --- a/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs +++ b/src/Umbraco.Tests/Configurations/UmbracoSettings/ContentElementTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using NUnit.Framework; using Umbraco.Core; @@ -183,15 +184,28 @@ namespace Umbraco.Tests.Configurations.UmbracoSettings public void AllowedUploadFiles() { Assert.IsTrue(SettingsSection.Content.AllowedUploadFiles.All(x => "jpg,gif,png".Split(',').Contains(x))); - } - + } + [Test] - public void IsFileAllowedForUpload_WithWhitelist() + [TestCase("png", true)] + [TestCase("jpg", true)] + [TestCase("gif", true)] + [TestCase("bmp", false)] + [TestCase("php", false)] + [TestCase("ashx", false)] + [TestCase("config", false)] + public void IsFileAllowedForUpload_WithWhitelist(string extension, bool expected) { - Assert.IsTrue(SettingsSection.Content.IsFileAllowedForUpload("png")); - // TODO: why does this fail on the build server but not locally? - //Assert.IsFalse(SettingsSection.Content.IsFileAllowedForUpload("bmp")); - Assert.IsFalse(SettingsSection.Content.IsFileAllowedForUpload("php")); + Debug.WriteLine("AllowedUploadFiles: {0}", SettingsSection.Content.AllowedUploadFiles); + Debug.WriteLine("DisallowedUploadFiles: {0}", SettingsSection.Content.DisallowedUploadFiles); + + var allowedContainsExtension = SettingsSection.Content.AllowedUploadFiles.Any(x => x.InvariantEquals(extension)); + var disallowedContainsExtension = SettingsSection.Content.DisallowedUploadFiles.Any(x => x.InvariantEquals(extension)); + + Debug.WriteLine("AllowedContainsBmp: {0}", allowedContainsExtension); + Debug.WriteLine("DisallowedContainsBmp: {0}", disallowedContainsExtension); + + Assert.AreEqual(SettingsSection.Content.IsFileAllowedForUpload(extension), expected); } } }