NetCore: Further unit test migration (#9269)
* Migrated ContentExtensionsTests. * Migrated PropertyCollectionTests. * Migrated AbstractFileSystemTests and PhysicalFileSystem tests. * Migrated SiteDomainHelper tests. * Migrated DistributedCacheTests. * Migrated AppCacheTests and derived test classes. Amended HttpRequestApp underlying dictionary type to match that available in .NET Core HttpContext Items collection. * Fixed namespace Signed-off-by: Bjarke Berg <mail@bergmania.dk> Co-authored-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
@@ -41,7 +41,7 @@ namespace Umbraco.Core.Cache
|
||||
public virtual IEnumerable<object> SearchByKey(string keyStartsWith)
|
||||
{
|
||||
var plen = CacheItemPrefix.Length + 1;
|
||||
IEnumerable<DictionaryEntry> entries;
|
||||
IEnumerable<KeyValuePair<object, object>> entries;
|
||||
try
|
||||
{
|
||||
EnterReadLock();
|
||||
@@ -65,7 +65,7 @@ namespace Umbraco.Core.Cache
|
||||
const string prefix = CacheItemPrefix + "-";
|
||||
var compiled = new Regex(regex, RegexOptions.Compiled);
|
||||
var plen = prefix.Length;
|
||||
IEnumerable<DictionaryEntry> entries;
|
||||
IEnumerable<KeyValuePair<object, object>> entries;
|
||||
try
|
||||
{
|
||||
EnterReadLock();
|
||||
@@ -249,7 +249,7 @@ namespace Umbraco.Core.Cache
|
||||
// manipulate the underlying cache entries
|
||||
// these *must* be called from within the appropriate locks
|
||||
// and use the full prefixed cache keys
|
||||
protected abstract IEnumerable<DictionaryEntry> GetDictionaryEntries();
|
||||
protected abstract IEnumerable<KeyValuePair<object, object>> GetDictionaryEntries();
|
||||
protected abstract void RemoveEntry(string key);
|
||||
protected abstract object GetEntry(string key);
|
||||
|
||||
|
||||
@@ -115,13 +115,13 @@ namespace Umbraco.Core.Cache
|
||||
|
||||
#region Entries
|
||||
|
||||
protected override IEnumerable<DictionaryEntry> GetDictionaryEntries()
|
||||
protected override IEnumerable<KeyValuePair<object, object>> GetDictionaryEntries()
|
||||
{
|
||||
const string prefix = CacheItemPrefix + "-";
|
||||
|
||||
if (!TryGetContextItems(out var items)) return Enumerable.Empty<DictionaryEntry>();
|
||||
if (!TryGetContextItems(out var items)) return Enumerable.Empty<KeyValuePair<object, object>>();
|
||||
|
||||
return items.Cast<DictionaryEntry>()
|
||||
return items.Cast<KeyValuePair<object, object>>()
|
||||
.Where(x => x.Key is string s && s.StartsWith(prefix));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Umbraco.Core.Composing;
|
||||
|
||||
namespace Umbraco.Core.Cache
|
||||
{
|
||||
@@ -17,19 +16,23 @@ namespace Umbraco.Core.Cache
|
||||
/// </remarks>
|
||||
public class HttpRequestAppCache : FastDictionaryAppCacheBase, IRequestCache
|
||||
{
|
||||
private static object _syncRoot = new object(); // Using this for locking as the SyncRoot property is not available to us
|
||||
// on the provided collection provided from .NET Core's HttpContext.Items dictionary,
|
||||
// as it doesn't implement ICollection where SyncRoot is defined.
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HttpRequestAppCache"/> class with a context, for unit tests!
|
||||
/// </summary>
|
||||
public HttpRequestAppCache(Func<IDictionary> requestItems) : base()
|
||||
public HttpRequestAppCache(Func<IDictionary<object, object>> requestItems) : base()
|
||||
{
|
||||
ContextItems = requestItems;
|
||||
}
|
||||
|
||||
private Func<IDictionary> ContextItems { get; }
|
||||
private Func<IDictionary<object, object>> ContextItems { get; }
|
||||
|
||||
public bool IsAvailable => TryGetContextItems(out _);
|
||||
|
||||
private bool TryGetContextItems(out IDictionary items)
|
||||
private bool TryGetContextItems(out IDictionary<object, object> items)
|
||||
{
|
||||
items = ContextItems?.Invoke();
|
||||
return items != null;
|
||||
@@ -115,13 +118,13 @@ namespace Umbraco.Core.Cache
|
||||
|
||||
#region Entries
|
||||
|
||||
protected override IEnumerable<DictionaryEntry> GetDictionaryEntries()
|
||||
protected override IEnumerable<KeyValuePair<object, object>> GetDictionaryEntries()
|
||||
{
|
||||
const string prefix = CacheItemPrefix + "-";
|
||||
|
||||
if (!TryGetContextItems(out var items)) return Enumerable.Empty<DictionaryEntry>();
|
||||
if (!TryGetContextItems(out var items)) return Enumerable.Empty<KeyValuePair<object, object>>();
|
||||
|
||||
return items.Cast<DictionaryEntry>()
|
||||
return items.Cast<KeyValuePair<object, object>>()
|
||||
.Where(x => x.Key is string s && s.StartsWith(prefix));
|
||||
}
|
||||
|
||||
@@ -154,7 +157,7 @@ namespace Umbraco.Core.Cache
|
||||
// ContextItems - which is locked, so this should be safe
|
||||
|
||||
var entered = false;
|
||||
Monitor.Enter(items.SyncRoot, ref entered);
|
||||
Monitor.Enter(_syncRoot, ref entered);
|
||||
items[ContextItemsLockKey] = entered;
|
||||
}
|
||||
|
||||
@@ -166,7 +169,7 @@ namespace Umbraco.Core.Cache
|
||||
|
||||
var entered = (bool?)items[ContextItemsLockKey] ?? false;
|
||||
if (entered)
|
||||
Monitor.Exit(items.SyncRoot);
|
||||
Monitor.Exit(_syncRoot);
|
||||
items.Remove(ContextItemsLockKey);
|
||||
}
|
||||
|
||||
@@ -179,7 +182,7 @@ namespace Umbraco.Core.Cache
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (DictionaryEntry item in items)
|
||||
foreach (var item in items)
|
||||
{
|
||||
yield return new KeyValuePair<string, object>(item.Key.ToString(), item.Value);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.UI;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
|
||||
namespace Umbraco.Tests.Cache
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache
|
||||
{
|
||||
public abstract class AppCacheTests
|
||||
{
|
||||
internal abstract IAppCache AppCache { get; }
|
||||
|
||||
protected abstract int GetTotalItemCount { get; }
|
||||
|
||||
[SetUp]
|
||||
@@ -66,10 +66,10 @@ namespace Umbraco.Tests.Cache
|
||||
try
|
||||
{
|
||||
result = AppCache.Get("Blah", () =>
|
||||
{
|
||||
counter++;
|
||||
throw new Exception("Do not cache this");
|
||||
});
|
||||
{
|
||||
counter++;
|
||||
throw new Exception("Do not cache this");
|
||||
});
|
||||
}
|
||||
catch (Exception){}
|
||||
|
||||
@@ -85,16 +85,16 @@ namespace Umbraco.Tests.Cache
|
||||
object result;
|
||||
|
||||
result = AppCache.Get("Blah", () =>
|
||||
{
|
||||
counter++;
|
||||
return "";
|
||||
});
|
||||
{
|
||||
counter++;
|
||||
return "";
|
||||
});
|
||||
|
||||
result = AppCache.Get("Blah", () =>
|
||||
{
|
||||
counter++;
|
||||
return "";
|
||||
});
|
||||
{
|
||||
counter++;
|
||||
return "";
|
||||
});
|
||||
|
||||
Assert.AreEqual(1, counter);
|
||||
|
||||
@@ -257,5 +257,9 @@ namespace Umbraco.Tests.Cache
|
||||
private class MacroCacheContent
|
||||
{
|
||||
}
|
||||
|
||||
private class LiteralControl
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,14 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Collections;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
using Umbraco.Tests.Common;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.Cache;
|
||||
|
||||
namespace Umbraco.Tests.Cache
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache
|
||||
{
|
||||
[TestFixture]
|
||||
public class DeepCloneAppCacheTests : RuntimeAppCacheTests
|
||||
@@ -41,12 +33,14 @@ namespace Umbraco.Tests.Cache
|
||||
[Test]
|
||||
public void Clones_List()
|
||||
{
|
||||
var original = new DeepCloneableList<TestClone>(ListCloneBehavior.Always);
|
||||
original.Add(new TestClone());
|
||||
original.Add(new TestClone());
|
||||
original.Add(new TestClone());
|
||||
var original = new DeepCloneableList<TestClone>(ListCloneBehavior.Always)
|
||||
{
|
||||
new TestClone(),
|
||||
new TestClone(),
|
||||
new TestClone()
|
||||
};
|
||||
|
||||
var val = _provider.GetCacheItem<DeepCloneableList<TestClone>>("test", () => original);
|
||||
var val = _provider.GetCacheItem("test", () => original);
|
||||
|
||||
Assert.AreEqual(original.Count, val.Count);
|
||||
foreach (var item in val)
|
||||
@@ -64,7 +58,7 @@ namespace Umbraco.Tests.Cache
|
||||
};
|
||||
Assert.IsTrue(original.IsDirty());
|
||||
|
||||
var val = _provider.GetCacheItem<TestClass>("test", () => original);
|
||||
var val = _provider.GetCacheItem("test", () => original);
|
||||
|
||||
Assert.AreNotEqual(original.CloneId, val.CloneId);
|
||||
Assert.IsFalse(val.IsDirty());
|
||||
@@ -0,0 +1,21 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache
|
||||
{
|
||||
[TestFixture]
|
||||
public class DictionaryAppCacheTests : AppCacheTests
|
||||
{
|
||||
private DictionaryAppCache _appCache;
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
_appCache = new DictionaryAppCache();
|
||||
}
|
||||
|
||||
internal override IAppCache AppCache => _appCache;
|
||||
|
||||
protected override int GetTotalItemCount => _appCache.Count;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Core.Sync;
|
||||
|
||||
namespace Umbraco.Tests.Cache.DistributedCache
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache.DistributedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that calls to DistributedCache methods carry through to the IServerMessenger correctly
|
||||
@@ -14,7 +13,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
[TestFixture]
|
||||
public class DistributedCacheTests
|
||||
{
|
||||
private Umbraco.Web.Cache.DistributedCache _distributedCache;
|
||||
private global::Umbraco.Web.Cache.DistributedCache _distributedCache;
|
||||
|
||||
private IServerRegistrar ServerRegistrar { get; set; }
|
||||
private TestServerMessenger ServerMessenger { get; set; }
|
||||
@@ -30,13 +29,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
new TestCacheRefresher()
|
||||
});
|
||||
|
||||
_distributedCache = new Umbraco.Web.Cache.DistributedCache(ServerMessenger, cacheRefresherCollection);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Teardown()
|
||||
{
|
||||
Current.Reset();
|
||||
_distributedCache = new global::Umbraco.Web.Cache.DistributedCache(ServerMessenger, cacheRefresherCollection);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -46,6 +39,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
_distributedCache.Refresh(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"), i);
|
||||
}
|
||||
|
||||
Assert.AreEqual(10, ServerMessenger.IntIdsRefreshed.Count);
|
||||
}
|
||||
|
||||
@@ -59,6 +53,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
x => x.Id,
|
||||
new TestObjectWithId{Id = i});
|
||||
}
|
||||
|
||||
Assert.AreEqual(10, ServerMessenger.IntIdsRefreshed.Count);
|
||||
}
|
||||
|
||||
@@ -69,6 +64,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
_distributedCache.Refresh(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"), Guid.NewGuid());
|
||||
}
|
||||
|
||||
Assert.AreEqual(11, ServerMessenger.GuidIdsRefreshed.Count);
|
||||
}
|
||||
|
||||
@@ -79,6 +75,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
_distributedCache.Remove(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"), i);
|
||||
}
|
||||
|
||||
Assert.AreEqual(12, ServerMessenger.IntIdsRemoved.Count);
|
||||
}
|
||||
|
||||
@@ -89,10 +86,11 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
_distributedCache.RefreshAll(Guid.Parse("E0F452CB-DCB2-4E84-B5A5-4F01744C5C73"));
|
||||
}
|
||||
|
||||
Assert.AreEqual(13, ServerMessenger.CountOfFullRefreshes);
|
||||
}
|
||||
|
||||
#region internal test classes
|
||||
#region Internal test classes
|
||||
|
||||
internal class TestObjectWithId
|
||||
{
|
||||
@@ -107,17 +105,13 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
|
||||
public string Name => "Test Cache Refresher";
|
||||
|
||||
public void RefreshAll()
|
||||
{ }
|
||||
public void RefreshAll() { }
|
||||
|
||||
public void Refresh(int id)
|
||||
{ }
|
||||
public void Refresh(int id) { }
|
||||
|
||||
public void Remove(int id)
|
||||
{ }
|
||||
public void Remove(int id) { }
|
||||
|
||||
public void Refresh(Guid id)
|
||||
{ }
|
||||
public void Refresh(Guid id) { }
|
||||
}
|
||||
|
||||
internal class TestServerMessenger : IServerMessenger
|
||||
@@ -192,7 +186,6 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TestServerAddress : IServerAddress
|
||||
@@ -201,6 +194,7 @@ namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
ServerAddress = address;
|
||||
}
|
||||
|
||||
public string ServerAddress { get; private set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache
|
||||
{
|
||||
[TestFixture]
|
||||
public class HttpRequestAppCacheTests : AppCacheTests
|
||||
{
|
||||
private HttpRequestAppCache _appCache;
|
||||
private HttpContext _httpContext;
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
_httpContext = new DefaultHttpContext();;
|
||||
_appCache = new HttpRequestAppCache(() => _httpContext.Items);
|
||||
}
|
||||
|
||||
internal override IAppCache AppCache => _appCache;
|
||||
|
||||
protected override int GetTotalItemCount => _httpContext.Items.Count;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Cache
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache
|
||||
{
|
||||
[TestFixture]
|
||||
public class ObjectAppCacheTests : RuntimeAppCacheTests
|
||||
@@ -3,7 +3,7 @@ using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
|
||||
namespace Umbraco.Tests.Cache
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Cache
|
||||
{
|
||||
public abstract class RuntimeAppCacheTests : AppCacheTests
|
||||
{
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -7,7 +6,7 @@ using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.IO;
|
||||
|
||||
namespace Umbraco.Tests.IO
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.IO
|
||||
{
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
@@ -179,7 +178,7 @@ namespace Umbraco.Tests.IO
|
||||
|
||||
protected Stream CreateStream(string contents = null)
|
||||
{
|
||||
if(string.IsNullOrEmpty(contents))
|
||||
if (string.IsNullOrEmpty(contents))
|
||||
contents = "test";
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes(contents);
|
||||
@@ -8,8 +8,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
|
||||
namespace Umbraco.Tests.IO
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.IO
|
||||
{
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
@@ -36,6 +35,7 @@ namespace Umbraco.Tests.IO
|
||||
{
|
||||
File.Delete(f);
|
||||
}
|
||||
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
|
||||
@@ -67,8 +67,8 @@ namespace Umbraco.Tests.IO
|
||||
|
||||
Assert.Throws<PathTooLongException>(() =>
|
||||
{
|
||||
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo")))
|
||||
_fileSystem.AddFile(path + "f3.txt", ms);
|
||||
using var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"));
|
||||
_fileSystem.AddFile(path + "f3.txt", ms);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Runtime.Serialization;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
|
||||
namespace Umbraco.Tests.Models.Collections
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Models.Collections
|
||||
{
|
||||
public abstract class Item : IEntity, ICanBeDirty
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Umbraco.Tests.Models.Collections
|
||||
{
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Models.Collections
|
||||
{
|
||||
public class OrderItem : Item
|
||||
{
|
||||
public readonly int PartNumber;
|
||||
@@ -13,10 +13,10 @@ namespace Umbraco.Tests.Models.Collections
|
||||
public OrderItem(int partNumber, string description,
|
||||
int quantity, double unitPrice)
|
||||
{
|
||||
this.PartNumber = partNumber;
|
||||
this.Description = description;
|
||||
this.Quantity = quantity;
|
||||
this.UnitPrice = unitPrice;
|
||||
PartNumber = partNumber;
|
||||
Description = description;
|
||||
Quantity = quantity;
|
||||
UnitPrice = unitPrice;
|
||||
}
|
||||
|
||||
public int Quantity
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Models.Collections
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format(
|
||||
return string.Format(
|
||||
"{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}",
|
||||
PartNumber, _quantity, Description, UnitPrice,
|
||||
UnitPrice * _quantity);
|
||||
@@ -3,22 +3,22 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Models.Collections
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Models.Collections
|
||||
{
|
||||
[TestFixture]
|
||||
public class PropertyCollectionTests : UmbracoTestBase
|
||||
public class PropertyCollectionTests
|
||||
{
|
||||
[Test]
|
||||
public void Property_Adds_Case_Insensitive_Compare()
|
||||
{
|
||||
var collection = new PropertyCollection();
|
||||
|
||||
collection.Add(new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "test")));
|
||||
collection.Add(new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "Test")));
|
||||
var collection = new PropertyCollection
|
||||
{
|
||||
new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "test")),
|
||||
new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "Test"))
|
||||
};
|
||||
|
||||
Assert.AreEqual(1, collection.Count);
|
||||
}
|
||||
@@ -26,9 +26,10 @@ namespace Umbraco.Tests.Models.Collections
|
||||
[Test]
|
||||
public void Property_Contains_Case_Insensitive_Compare()
|
||||
{
|
||||
var collection = new PropertyCollection();
|
||||
|
||||
collection.Add(new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "test")));
|
||||
var collection = new PropertyCollection
|
||||
{
|
||||
new Property(new PropertyType(TestHelper.ShortStringHelper, "propEditor", ValueStorageType.Nvarchar, "test"))
|
||||
};
|
||||
|
||||
Assert.IsTrue(collection.Contains("Test"));
|
||||
}
|
||||
@@ -79,7 +80,7 @@ namespace Umbraco.Tests.Models.Collections
|
||||
[Test]
|
||||
public void PropertyGroups_Collection_FirstOrDefault_Returns_Null()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
|
||||
Assert.That(contentType.PropertyGroups, Is.Not.Null);
|
||||
Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Content")) == null, Is.False);
|
||||
@@ -2,9 +2,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Umbraco.Tests.Models.Collections
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Models.Collections
|
||||
{
|
||||
public class SimpleOrder : KeyedCollection<int, OrderItem>, INotifyCollectionChanged
|
||||
{
|
||||
@@ -73,10 +72,7 @@ namespace Umbraco.Tests.Models.Collections
|
||||
|
||||
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
|
||||
{
|
||||
if (CollectionChanged != null)
|
||||
{
|
||||
CollectionChanged(this, args);
|
||||
}
|
||||
CollectionChanged?.Invoke(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +1,24 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing.CompositionExtensions;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class ContentExtensionsTests : UmbracoTestBase
|
||||
public class ContentExtensionsTests
|
||||
{
|
||||
private IContentTypeService _contentTypeService;
|
||||
|
||||
protected override void Compose()
|
||||
{
|
||||
base.Compose();
|
||||
|
||||
Composition.ComposeFileSystems();
|
||||
|
||||
Composition.Register(_ => Mock.Of<IDataTypeService>());
|
||||
|
||||
// all this is required so we can validate properties...
|
||||
var editor = new TextboxPropertyEditor(NullLoggerFactory.Instance, Mock.Of<IDataTypeService>(), Mock.Of<ILocalizationService>(), IOHelper, ShortStringHelper, LocalizedTextService) { Alias = "test" };
|
||||
Composition.Register(_ => new DataEditorCollection(new[] { editor }));
|
||||
Composition.Register<PropertyEditorCollection>();
|
||||
var dataType = Mock.Of<IDataType>();
|
||||
Mock.Get(dataType).Setup(x => x.Configuration).Returns(() => new object());
|
||||
var dataTypeService = Mock.Of<IDataTypeService>();
|
||||
Mock.Get(dataTypeService)
|
||||
.Setup(x => x.GetDataType(It.IsAny<int>()))
|
||||
.Returns(() => dataType);
|
||||
|
||||
_contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var mediaTypeService = Mock.Of<IMediaTypeService>();
|
||||
var memberTypeService = Mock.Of<IMemberTypeService>();
|
||||
Composition.Register(_ => ServiceContext.CreatePartial(dataTypeService: dataTypeService, contentTypeBaseServiceProvider: new ContentTypeBaseServiceProvider(_contentTypeService, mediaTypeService, memberTypeService)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DirtyProperty_Reset_Clears_SavedPublishedState()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
|
||||
content.PublishedState = PublishedState.Publishing;
|
||||
Assert.IsFalse(content.Published);
|
||||
@@ -64,10 +30,11 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void DirtyProperty_OnlyIfActuallyChanged_Content()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
|
||||
// if you assign a content property with its value it is not dirty
|
||||
// if you assign it with another value then back, it is dirty
|
||||
@@ -88,10 +55,11 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void DirtyProperty_OnlyIfActuallyChanged_User()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var prop = content.Properties.First();
|
||||
|
||||
// if you assign a user property with its value it is not dirty
|
||||
@@ -114,10 +82,11 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void DirtyProperty_UpdateDate()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var prop = content.Properties.First();
|
||||
|
||||
content.ResetDirtyProperties(false);
|
||||
@@ -139,10 +108,11 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void DirtyProperty_WasDirty_ContentProperty()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
content.ResetDirtyProperties(false);
|
||||
Assert.IsFalse(content.IsDirty());
|
||||
Assert.IsFalse(content.WasDirty());
|
||||
@@ -168,10 +138,11 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void DirtyProperty_WasDirty_ContentSortOrder()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
content.ResetDirtyProperties(false);
|
||||
Assert.IsFalse(content.IsDirty());
|
||||
Assert.IsFalse(content.WasDirty());
|
||||
@@ -197,10 +168,11 @@ namespace Umbraco.Tests.Models
|
||||
[Test]
|
||||
public void DirtyProperty_WasDirty_UserProperty()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateTextPageContentType();
|
||||
Mock.Get(_contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
var contentTypeService = Mock.Of<IContentTypeService>();
|
||||
var contentType = ContentTypeBuilder.CreateTextPageContentType();
|
||||
Mock.Get(contentTypeService).As<IContentTypeBaseService>().Setup(x => x.Get(It.IsAny<int>())).Returns(contentType);
|
||||
|
||||
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var content = ContentBuilder.CreateTextpageContent(contentType, "Textpage", -1);
|
||||
var prop = content.Properties.First();
|
||||
content.ResetDirtyProperties(false);
|
||||
Assert.IsFalse(content.IsDirty());
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Core.Routing
|
||||
{
|
||||
[TestFixture]
|
||||
public class SiteDomainHelperTests
|
||||
@@ -21,8 +21,8 @@ namespace Umbraco.Tests.Routing
|
||||
SiteDomainHelper.Clear(); // assuming this works!
|
||||
}
|
||||
|
||||
private static CultureInfo CultureFr = CultureInfo.GetCultureInfo("fr-fr");
|
||||
private static CultureInfo CultureUk = CultureInfo.GetCultureInfo("en-uk");
|
||||
private static CultureInfo _cultureFr = CultureInfo.GetCultureInfo("fr-fr");
|
||||
private static CultureInfo _cultureGb = CultureInfo.GetCultureInfo("en-gb");
|
||||
|
||||
[Test]
|
||||
public void AddSites()
|
||||
@@ -191,38 +191,38 @@ namespace Umbraco.Tests.Routing
|
||||
var current = new Uri("https://www.domain1.com/foo/bar");
|
||||
var domainAndUris = DomainAndUris(current, new[]
|
||||
{
|
||||
new Domain(1, "domain2.com", -1, CultureFr, false),
|
||||
new Domain(1, "domain1.com", -1, CultureUk, false),
|
||||
new Domain(1, "domain2.com", -1, _cultureFr, false),
|
||||
new Domain(1, "domain1.com", -1, _cultureGb, false),
|
||||
});
|
||||
var output = helper.MapDomain(domainAndUris, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
var output = helper.MapDomain(domainAndUris, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("https://domain1.com/", output);
|
||||
|
||||
// will pick it all right
|
||||
current = new Uri("https://domain1.com/foo/bar");
|
||||
domainAndUris = DomainAndUris(current, new[]
|
||||
{
|
||||
new Domain(1, "https://domain1.com", -1, CultureFr, false),
|
||||
new Domain(1, "https://domain2.com", -1, CultureUk, false)
|
||||
new Domain(1, "https://domain1.com", -1, _cultureFr, false),
|
||||
new Domain(1, "https://domain2.com", -1, _cultureGb, false)
|
||||
});
|
||||
output = helper.MapDomain(domainAndUris, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
output = helper.MapDomain(domainAndUris, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("https://domain1.com/", output);
|
||||
|
||||
current = new Uri("https://domain1.com/foo/bar");
|
||||
domainAndUris = DomainAndUris(current, new[]
|
||||
{
|
||||
new Domain(1, "https://domain1.com", -1, CultureFr, false),
|
||||
new Domain(1, "https://domain4.com", -1, CultureUk, false)
|
||||
new Domain(1, "https://domain1.com", -1, _cultureFr, false),
|
||||
new Domain(1, "https://domain4.com", -1, _cultureGb, false)
|
||||
});
|
||||
output = helper.MapDomain(domainAndUris, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
output = helper.MapDomain(domainAndUris, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("https://domain1.com/", output);
|
||||
|
||||
current = new Uri("https://domain4.com/foo/bar");
|
||||
domainAndUris = DomainAndUris(current, new[]
|
||||
{
|
||||
new Domain(1, "https://domain1.com", -1, CultureFr, false),
|
||||
new Domain(1, "https://domain4.com", -1, CultureUk, false)
|
||||
new Domain(1, "https://domain1.com", -1, _cultureFr, false),
|
||||
new Domain(1, "https://domain4.com", -1, _cultureGb, false)
|
||||
});
|
||||
output = helper.MapDomain(domainAndUris, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
output = helper.MapDomain(domainAndUris, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("https://domain4.com/", output);
|
||||
}
|
||||
|
||||
@@ -234,9 +234,6 @@ namespace Umbraco.Tests.Routing
|
||||
SiteDomainHelper.AddSite("site3", "domain3.com", "domain3.net", "domain3.org");
|
||||
SiteDomainHelper.AddSite("site4", "domain4.com", "domain4.net", "domain4.org");
|
||||
|
||||
//SiteDomainHelper.BindSites("site1", "site3");
|
||||
//SiteDomainHelper.BindSites("site2", "site4");
|
||||
|
||||
// map methods are not static because we can override them
|
||||
var helper = new SiteDomainHelper();
|
||||
|
||||
@@ -246,9 +243,9 @@ namespace Umbraco.Tests.Routing
|
||||
var current = new Uri("http://domain1.com/foo/bar");
|
||||
var output = helper.MapDomain(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain1.com", -1, CultureFr, false), current),
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, CultureUk, false), current),
|
||||
}, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
new DomainAndUri(new Domain(1, "domain1.com", -1, _cultureFr, false), current),
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, _cultureGb, false), current),
|
||||
}, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("http://domain1.com/", output);
|
||||
|
||||
// current is a site1 uri, domains do not contain current
|
||||
@@ -257,9 +254,9 @@ namespace Umbraco.Tests.Routing
|
||||
current = new Uri("http://domain1.com/foo/bar");
|
||||
output = helper.MapDomain(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, CultureFr, false), current),
|
||||
new DomainAndUri(new Domain(1, "domain2.net", -1, CultureUk, false), current)
|
||||
}, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, _cultureFr, false), current),
|
||||
new DomainAndUri(new Domain(1, "domain2.net", -1, _cultureGb, false), current)
|
||||
}, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("http://domain1.net/", output);
|
||||
|
||||
// current is a site1 uri, domains do not contain current
|
||||
@@ -269,9 +266,9 @@ namespace Umbraco.Tests.Routing
|
||||
current = new Uri("http://domain1.com/foo/bar");
|
||||
output = helper.MapDomain(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain2.net", -1, CultureFr, false), current),
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, CultureUk, false), current)
|
||||
}, current, CultureFr.Name, CultureFr.Name).Uri.ToString();
|
||||
new DomainAndUri(new Domain(1, "domain2.net", -1, _cultureFr, false), current),
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, _cultureGb, false), current)
|
||||
}, current, _cultureFr.Name, _cultureFr.Name).Uri.ToString();
|
||||
Assert.AreEqual("http://domain1.net/", output);
|
||||
}
|
||||
|
||||
@@ -296,12 +293,12 @@ namespace Umbraco.Tests.Routing
|
||||
var current = new Uri("http://domain1.com/foo/bar");
|
||||
var output = helper.MapDomains(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain1.com", -1, CultureFr, false), current), // no: current + what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, CultureUk, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, CultureFr.Name, CultureFr.Name).ToArray();
|
||||
new DomainAndUri(new Domain(1, "domain1.com", -1, _cultureFr, false), current), // no: current + what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, _cultureGb, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, _cultureFr.Name, _cultureFr.Name).ToArray();
|
||||
|
||||
Assert.AreEqual(1, output.Count());
|
||||
Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());
|
||||
@@ -311,12 +308,12 @@ namespace Umbraco.Tests.Routing
|
||||
current = new Uri("http://domain1.com/foo/bar");
|
||||
output = helper.MapDomains(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, CultureFr, false), current), // no: what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, CultureUk, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, CultureFr.Name, CultureFr.Name).ToArray();
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, _cultureFr, false), current), // no: what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, _cultureGb, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, _cultureFr.Name, _cultureFr.Name).ToArray();
|
||||
|
||||
Assert.AreEqual(1, output.Count());
|
||||
Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());
|
||||
@@ -329,13 +326,13 @@ namespace Umbraco.Tests.Routing
|
||||
current = new Uri("http://domain1.com/foo/bar");
|
||||
output = helper.MapDomains(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain1.com", -1, CultureFr, false), current), // no: current + what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, CultureUk, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain3.org", -1, CultureUk, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, CultureUk, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, CultureFr.Name, CultureFr.Name).ToArray();
|
||||
new DomainAndUri(new Domain(1, "domain1.com", -1, _cultureFr, false), current), // no: current + what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, _cultureGb, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain3.org", -1, _cultureGb, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, _cultureGb, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, _cultureFr.Name, _cultureFr.Name).ToArray();
|
||||
|
||||
Assert.AreEqual(3, output.Count());
|
||||
Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());
|
||||
@@ -347,28 +344,18 @@ namespace Umbraco.Tests.Routing
|
||||
current = new Uri("http://domain1.com/foo/bar");
|
||||
output = helper.MapDomains(new[]
|
||||
{
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, CultureFr, false), current), // no: what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, CultureUk, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain3.org", -1, CultureUk, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, CultureUk, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, CultureUk, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, CultureFr.Name, CultureFr.Name).ToArray();
|
||||
new DomainAndUri(new Domain(1, "domain1.net", -1, _cultureFr, false), current), // no: what MapDomain would pick
|
||||
new DomainAndUri(new Domain(1, "domain2.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain3.com", -1, _cultureGb, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain3.org", -1, _cultureGb, false), current), // yes: bound site
|
||||
new DomainAndUri(new Domain(1, "domain4.com", -1, _cultureGb, false), current), // no: not same site
|
||||
new DomainAndUri(new Domain(1, "domain1.org", -1, _cultureGb, false), current), // yes: same site (though bogus setup)
|
||||
}, current, true, _cultureFr.Name, _cultureFr.Name).ToArray();
|
||||
|
||||
Assert.AreEqual(3, output.Count());
|
||||
Assert.Contains("http://domain1.org/", output.Select(d => d.Uri.ToString()).ToArray());
|
||||
Assert.Contains("http://domain3.com/", output.Select(d => d.Uri.ToString()).ToArray());
|
||||
Assert.Contains("http://domain3.org/", output.Select(d => d.Uri.ToString()).ToArray());
|
||||
}
|
||||
|
||||
//class MockDomain : Domain
|
||||
//{
|
||||
// private static readonly FieldInfo NameField = typeof (Domain).GetField("_name", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
// public MockDomain(string name)
|
||||
// {
|
||||
// NameField.SetValue(this, name);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
|
||||
namespace Umbraco.Tests.Cache
|
||||
{
|
||||
[TestFixture]
|
||||
public class HttpRequestAppCacheTests : AppCacheTests
|
||||
{
|
||||
private HttpRequestAppCache _appCache;
|
||||
private FakeHttpContextFactory _ctx;
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
_ctx = new FakeHttpContextFactory("http://localhost/test");
|
||||
_appCache = new HttpRequestAppCache(() => _ctx.HttpContext.Items);
|
||||
}
|
||||
|
||||
internal override IAppCache AppCache
|
||||
{
|
||||
get { return _appCache; }
|
||||
}
|
||||
|
||||
protected override int GetTotalItemCount
|
||||
{
|
||||
get { return _ctx.HttpContext.Items.Count; }
|
||||
}
|
||||
}
|
||||
|
||||
[TestFixture]
|
||||
public class DictionaryAppCacheTests : AppCacheTests
|
||||
{
|
||||
private DictionaryAppCache _appCache;
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
_appCache = new DictionaryAppCache();
|
||||
}
|
||||
|
||||
internal override IAppCache AppCache
|
||||
{
|
||||
get { return _appCache; }
|
||||
}
|
||||
|
||||
protected override int GetTotalItemCount
|
||||
{
|
||||
get { return _appCache.Count; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,9 +130,7 @@
|
||||
<Compile Include="Cache\DistributedCacheBinderTests.cs" />
|
||||
<Compile Include="Cache\RefresherTests.cs" />
|
||||
<Compile Include="Cache\SnapDictionaryTests.cs" />
|
||||
<Compile Include="IO\AbstractFileSystemTests.cs" />
|
||||
<Compile Include="IO\FileSystemsTests.cs" />
|
||||
<Compile Include="IO\PhysicalFileSystemTests.cs" />
|
||||
<Compile Include="IO\ShadowFileSystemTests.cs" />
|
||||
<Compile Include="LegacyXmlPublishedCache\ContentXmlDto.cs" />
|
||||
<Compile Include="LegacyXmlPublishedCache\PreviewXmlDto.cs" />
|
||||
@@ -146,6 +144,7 @@
|
||||
<Compile Include="Routing\BaseUrlProviderTest.cs" />
|
||||
<Compile Include="Routing\UrlProviderWithHideTopLevelNodeFromPathTests.cs" />
|
||||
<Compile Include="Scoping\ScopeEventDispatcherTests.cs" />
|
||||
<Compile Include="Scoping\ScopeTests.cs" />
|
||||
<Compile Include="Security\OwinDataProtectorTokenProviderTests.cs" />
|
||||
<Compile Include="Services\TestWithSomeContentBase.cs" />
|
||||
<Compile Include="TestHelpers\Entities\MockedContent.cs" />
|
||||
@@ -180,7 +179,6 @@
|
||||
<Compile Include="Scoping\ScopedRepositoryTests.cs" />
|
||||
<Compile Include="Scoping\ScopedXmlTests.cs" />
|
||||
<Compile Include="Scoping\ScopedNuCacheTests.cs" />
|
||||
<Compile Include="Scoping\ScopeTests.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingExtensions.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingMiddleware.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\SpecificAssemblyResolver.cs" />
|
||||
@@ -201,7 +199,6 @@
|
||||
<Compile Include="UmbracoExamine\RandomIdRamDirectory.cs" />
|
||||
<Compile Include="Web\AngularIntegration\AngularAntiForgeryTests.cs" />
|
||||
<Compile Include="Migrations\Stubs\DropForeignKeyMigrationStub.cs" />
|
||||
<Compile Include="Cache\DeepCloneAppCacheTests.cs" />
|
||||
<Compile Include="Cache\DefaultCachePolicyTests.cs" />
|
||||
<Compile Include="Cache\FullDataSetCachePolicyTests.cs" />
|
||||
<Compile Include="Cache\SingleItemsOnlyCachePolicyTests.cs" />
|
||||
@@ -220,17 +217,9 @@
|
||||
<Compile Include="Migrations\Stubs\FourElevenMigration.cs" />
|
||||
<Compile Include="Migrations\Stubs\SixZeroMigration2.cs" />
|
||||
<Compile Include="Testing\TestingTests\MockTests.cs" />
|
||||
<Compile Include="Models\Collections\Item.cs" />
|
||||
<Compile Include="Models\Collections\OrderItem.cs" />
|
||||
<Compile Include="Models\Collections\SimpleOrder.cs" />
|
||||
<Compile Include="Web\Mvc\SurfaceControllerTests.cs" />
|
||||
<Compile Include="Runtimes\CoreRuntimeTests.cs" />
|
||||
<Compile Include="Runtimes\WebRuntimeComponentTests.cs" />
|
||||
<Compile Include="Cache\ObjectAppCacheTests.cs" />
|
||||
<Compile Include="Cache\AppCacheTests.cs" />
|
||||
<Compile Include="Cache\HttpRequestAppCacheTests.cs" />
|
||||
<Compile Include="Cache\RuntimeAppCacheTests.cs" />
|
||||
<Compile Include="Models\ContentExtensionsTests.cs" />
|
||||
<Compile Include="Web\Mvc\MergeParentContextViewDataAttributeTests.cs" />
|
||||
<Compile Include="Web\Mvc\ViewDataDictionaryExtensionTests.cs" />
|
||||
<Compile Include="Persistence\Querying\ContentTypeSqlMappingTests.cs" />
|
||||
@@ -249,7 +238,6 @@
|
||||
<Compile Include="Migrations\Stubs\AlterUserTableMigrationStub.cs" />
|
||||
<Compile Include="Migrations\Stubs\Dummy.cs" />
|
||||
<Compile Include="Migrations\Stubs\SixZeroMigration1.cs" />
|
||||
<Compile Include="Models\Collections\PropertyCollectionTests.cs" />
|
||||
<Compile Include="Models\MediaXmlTest.cs" />
|
||||
<Compile Include="Persistence\FaultHandling\ConnectionRetryTest.cs" />
|
||||
<Compile Include="Persistence\SchemaValidationTest.cs" />
|
||||
@@ -265,7 +253,6 @@
|
||||
<Compile Include="Cache\PublishedCache\PublishedContentCacheTests.cs" />
|
||||
<Compile Include="Routing\ContentFinderByAliasWithDomainsTests.cs" />
|
||||
<Compile Include="Routing\DomainsAndCulturesTests.cs" />
|
||||
<Compile Include="Routing\SiteDomainHelperTests.cs" />
|
||||
<Compile Include="Routing\UrlsWithNestedDomains.cs" />
|
||||
<Compile Include="Packaging\PackageDataInstallationTests.cs" />
|
||||
<Compile Include="Services\Importing\ImportResources.Designer.cs">
|
||||
@@ -274,7 +261,6 @@
|
||||
<DependentUpon>ImportResources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Web\Controllers\PluginControllerAreaTests.cs" />
|
||||
<Compile Include="Cache\DistributedCache\DistributedCacheTests.cs" />
|
||||
<Compile Include="TestHelpers\TestWithDatabaseBase.cs" />
|
||||
<Compile Include="Routing\ContentFinderByAliasTests.cs" />
|
||||
<Compile Include="Routing\ContentFinderByIdTests.cs" />
|
||||
@@ -417,4 +403,4 @@
|
||||
<Message Text="NuGetPackageFolders: $(NuGetPackageFolders)" Importance="high" />
|
||||
<Message Text="NuGetPackages: $(NuGetPackages)" Importance="high" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -34,7 +34,10 @@ namespace Umbraco.Web
|
||||
|
||||
var mainDom = new MainDom(loggerFactory.CreateLogger<MainDom>(), mainDomLock);
|
||||
|
||||
var requestCache = new HttpRequestAppCache(() => HttpContext.Current != null ? HttpContext.Current.Items : null);
|
||||
// Commented out as part of .NET Core transition as the HttpRequestAppCache constructor has changed to
|
||||
// to match the change in the type of the HTTP context Items collection.
|
||||
//// var requestCache = new HttpRequestAppCache(() => HttpContext.Current != null ? HttpContext.Current.Items : null);
|
||||
IRequestCache requestCache = null;
|
||||
var appCaches = new AppCaches(
|
||||
new DeepCloneAppCache(new ObjectCacheAppCache()),
|
||||
requestCache,
|
||||
|
||||
Reference in New Issue
Block a user