Removes some code duplication by using parameterized test
Add some debugging to unit test to figure out what's wrong with it
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user