diff --git a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs index bb55762826..4b8098e19d 100644 --- a/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs +++ b/src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs @@ -41,7 +41,7 @@ namespace Umbraco.Core.Cache public virtual IEnumerable SearchByKey(string keyStartsWith) { var plen = CacheItemPrefix.Length + 1; - IEnumerable entries; + IEnumerable> 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 entries; + IEnumerable> 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 GetDictionaryEntries(); + protected abstract IEnumerable> GetDictionaryEntries(); protected abstract void RemoveEntry(string key); protected abstract object GetEntry(string key); diff --git a/src/Umbraco.Core/Cache/GenericDictionaryRequestAppCache.cs b/src/Umbraco.Core/Cache/GenericDictionaryRequestAppCache.cs index 193235ca7e..31914eb5b0 100644 --- a/src/Umbraco.Core/Cache/GenericDictionaryRequestAppCache.cs +++ b/src/Umbraco.Core/Cache/GenericDictionaryRequestAppCache.cs @@ -115,13 +115,13 @@ namespace Umbraco.Core.Cache #region Entries - protected override IEnumerable GetDictionaryEntries() + protected override IEnumerable> GetDictionaryEntries() { const string prefix = CacheItemPrefix + "-"; - if (!TryGetContextItems(out var items)) return Enumerable.Empty(); + if (!TryGetContextItems(out var items)) return Enumerable.Empty>(); - return items.Cast() + return items.Cast>() .Where(x => x.Key is string s && s.StartsWith(prefix)); } diff --git a/src/Umbraco.Core/Cache/HttpRequestAppCache.cs b/src/Umbraco.Core/Cache/HttpRequestAppCache.cs index 6ce43a7bc9..00d427c965 100644 --- a/src/Umbraco.Core/Cache/HttpRequestAppCache.cs +++ b/src/Umbraco.Core/Cache/HttpRequestAppCache.cs @@ -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 /// 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. + /// /// Initializes a new instance of the class with a context, for unit tests! /// - public HttpRequestAppCache(Func requestItems) : base() + public HttpRequestAppCache(Func> requestItems) : base() { ContextItems = requestItems; } - private Func ContextItems { get; } + private Func> ContextItems { get; } public bool IsAvailable => TryGetContextItems(out _); - private bool TryGetContextItems(out IDictionary items) + private bool TryGetContextItems(out IDictionary items) { items = ContextItems?.Invoke(); return items != null; @@ -115,13 +118,13 @@ namespace Umbraco.Core.Cache #region Entries - protected override IEnumerable GetDictionaryEntries() + protected override IEnumerable> GetDictionaryEntries() { const string prefix = CacheItemPrefix + "-"; - if (!TryGetContextItems(out var items)) return Enumerable.Empty(); + if (!TryGetContextItems(out var items)) return Enumerable.Empty>(); - return items.Cast() + return items.Cast>() .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(item.Key.ToString(), item.Value); } diff --git a/src/Umbraco.Tests/Cache/AppCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/AppCacheTests.cs similarity index 95% rename from src/Umbraco.Tests/Cache/AppCacheTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/AppCacheTests.cs index 6b1c14d320..a30e254235 100644 --- a/src/Umbraco.Tests/Cache/AppCacheTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/AppCacheTests.cs @@ -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 + { + } } } diff --git a/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DeepCloneAppCacheTests.cs similarity index 84% rename from src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DeepCloneAppCacheTests.cs index f7b39590f2..cbcd164b62 100644 --- a/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DeepCloneAppCacheTests.cs @@ -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(ListCloneBehavior.Always); - original.Add(new TestClone()); - original.Add(new TestClone()); - original.Add(new TestClone()); + var original = new DeepCloneableList(ListCloneBehavior.Always) + { + new TestClone(), + new TestClone(), + new TestClone() + }; - var val = _provider.GetCacheItem>("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("test", () => original); + var val = _provider.GetCacheItem("test", () => original); Assert.AreNotEqual(original.CloneId, val.CloneId); Assert.IsFalse(val.IsDirty()); diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DictionaryAppCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DictionaryAppCacheTests.cs new file mode 100644 index 0000000000..91d71d3144 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DictionaryAppCacheTests.cs @@ -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; + } +} diff --git a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs similarity index 90% rename from src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs index 6043e7b0d6..0d5b1edb31 100644 --- a/src/Umbraco.Tests/Cache/DistributedCache/DistributedCacheTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/DistributedCache/DistributedCacheTests.cs @@ -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 { /// /// 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; } } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/HttpRequestAppCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/HttpRequestAppCacheTests.cs new file mode 100644 index 0000000000..02a10fcff4 --- /dev/null +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/HttpRequestAppCacheTests.cs @@ -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; + } +} diff --git a/src/Umbraco.Tests/Cache/ObjectAppCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ObjectAppCacheTests.cs similarity index 91% rename from src/Umbraco.Tests/Cache/ObjectAppCacheTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ObjectAppCacheTests.cs index 3172738bf7..51639d7c49 100644 --- a/src/Umbraco.Tests/Cache/ObjectAppCacheTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ObjectAppCacheTests.cs @@ -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 diff --git a/src/Umbraco.Tests/Cache/RuntimeAppCacheTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/RuntimeAppCacheTests.cs similarity index 94% rename from src/Umbraco.Tests/Cache/RuntimeAppCacheTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/RuntimeAppCacheTests.cs index 1beeae74db..33a71b1044 100644 --- a/src/Umbraco.Tests/Cache/RuntimeAppCacheTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/RuntimeAppCacheTests.cs @@ -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 { diff --git a/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/IO/AbstractFileSystemTests.cs similarity index 98% rename from src/Umbraco.Tests/IO/AbstractFileSystemTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/IO/AbstractFileSystemTests.cs index 2ca5d0bdc2..3502c74494 100644 --- a/src/Umbraco.Tests/IO/AbstractFileSystemTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/IO/AbstractFileSystemTests.cs @@ -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); diff --git a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs similarity index 95% rename from src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs index bd26bbcc66..7b98d77f58 100644 --- a/src/Umbraco.Tests/IO/PhysicalFileSystemTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/IO/PhysicalFileSystemTests.cs @@ -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(() => { - 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); }); } diff --git a/src/Umbraco.Tests/Models/Collections/Item.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/Item.cs similarity index 99% rename from src/Umbraco.Tests/Models/Collections/Item.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/Item.cs index 38cf8ecb4b..8593d01946 100644 --- a/src/Umbraco.Tests/Models/Collections/Item.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/Item.cs @@ -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 { diff --git a/src/Umbraco.Tests/Models/Collections/OrderItem.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/OrderItem.cs similarity index 78% rename from src/Umbraco.Tests/Models/Collections/OrderItem.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/OrderItem.cs index 8d010495ac..60c57dd1e5 100644 --- a/src/Umbraco.Tests/Models/Collections/OrderItem.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/OrderItem.cs @@ -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); diff --git a/src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/PropertyCollectionTests.cs similarity index 77% rename from src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/PropertyCollectionTests.cs index e36e89e183..6c76cc29a2 100644 --- a/src/Umbraco.Tests/Models/Collections/PropertyCollectionTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/PropertyCollectionTests.cs @@ -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); diff --git a/src/Umbraco.Tests/Models/Collections/SimpleOrder.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/SimpleOrder.cs similarity index 93% rename from src/Umbraco.Tests/Models/Collections/SimpleOrder.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/SimpleOrder.cs index 4b52289e2a..d8c47f45f4 100644 --- a/src/Umbraco.Tests/Models/Collections/SimpleOrder.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/Collections/SimpleOrder.cs @@ -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, 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); } } } diff --git a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/ContentExtensionsTests.cs similarity index 62% rename from src/Umbraco.Tests/Models/ContentExtensionsTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/ContentExtensionsTests.cs index ae59e377d0..333ec11720 100644 --- a/src/Umbraco.Tests/Models/ContentExtensionsTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Models/ContentExtensionsTests.cs @@ -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()); - - // all this is required so we can validate properties... - var editor = new TextboxPropertyEditor(NullLoggerFactory.Instance, Mock.Of(), Mock.Of(), IOHelper, ShortStringHelper, LocalizedTextService) { Alias = "test" }; - Composition.Register(_ => new DataEditorCollection(new[] { editor })); - Composition.Register(); - var dataType = Mock.Of(); - Mock.Get(dataType).Setup(x => x.Configuration).Returns(() => new object()); - var dataTypeService = Mock.Of(); - Mock.Get(dataTypeService) - .Setup(x => x.GetDataType(It.IsAny())) - .Returns(() => dataType); - - _contentTypeService = Mock.Of(); - var mediaTypeService = Mock.Of(); - var memberTypeService = Mock.Of(); - 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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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().Setup(x => x.Get(It.IsAny())).Returns(contentType); + var contentTypeService = Mock.Of(); + var contentType = ContentTypeBuilder.CreateTextPageContentType(); + Mock.Get(contentTypeService).As().Setup(x => x.Get(It.IsAny())).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()); diff --git a/src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/SiteDomainHelperTests.cs similarity index 78% rename from src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs rename to src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/SiteDomainHelperTests.cs index 1ef632b497..d32340b6b0 100644 --- a/src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Core/Routing/SiteDomainHelperTests.cs @@ -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); - // } - //} } } diff --git a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs deleted file mode 100644 index 2eea382bd3..0000000000 --- a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs +++ /dev/null @@ -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; } - } - } -} diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 4ac4d1fed5..526e1aa252 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -130,9 +130,7 @@ - - @@ -146,6 +144,7 @@ + @@ -180,7 +179,6 @@ - @@ -201,7 +199,6 @@ - @@ -220,17 +217,9 @@ - - - - - - - - @@ -249,7 +238,6 @@ - @@ -265,7 +253,6 @@ - @@ -274,7 +261,6 @@ ImportResources.resx - @@ -417,4 +403,4 @@ - + \ No newline at end of file diff --git a/src/Umbraco.Web/UmbracoApplication.cs b/src/Umbraco.Web/UmbracoApplication.cs index 8f6231b22a..90b2569c67 100644 --- a/src/Umbraco.Web/UmbracoApplication.cs +++ b/src/Umbraco.Web/UmbracoApplication.cs @@ -34,7 +34,10 @@ namespace Umbraco.Web var mainDom = new MainDom(loggerFactory.CreateLogger(), 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,