diff --git a/src/Umbraco.Tests.Common/Builders/ConfigurationEditorBuilder.cs b/src/Umbraco.Tests.Common/Builders/ConfigurationEditorBuilder.cs index 5c9459bf47..2d8a93e772 100644 --- a/src/Umbraco.Tests.Common/Builders/ConfigurationEditorBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ConfigurationEditorBuilder.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Common.Builders public override IConfigurationEditor Build() { - IDictionary defaultConfiguration = _defaultConfiguration ?? new Dictionary(); + IDictionary defaultConfiguration = _defaultConfiguration ?? new Dictionary(); return new ConfigurationEditor() { diff --git a/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs index bd7e3b5b3f..715b504d71 100644 --- a/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ContentBuilder.cs @@ -220,7 +220,6 @@ namespace Umbraco.Tests.Common.Builders .WithName(name) .WithParent(parent); - if (!(culture is null)) { builder = builder.WithCultureName(culture, name); diff --git a/src/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs index f9ad509be4..a9ff520228 100644 --- a/src/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs @@ -13,7 +13,8 @@ namespace Umbraco.Tests.Common.Builders private string _alias; private object _value; - public ContentPropertyBasicBuilder(TParent parentBuilder) : base(parentBuilder) + public ContentPropertyBasicBuilder(TParent parentBuilder) + : base(parentBuilder) { } diff --git a/src/Umbraco.Tests.Common/Builders/ContentTypeSortBuilder.cs b/src/Umbraco.Tests.Common/Builders/ContentTypeSortBuilder.cs index b1e3c494f1..3e7c886623 100644 --- a/src/Umbraco.Tests.Common/Builders/ContentTypeSortBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/ContentTypeSortBuilder.cs @@ -23,7 +23,8 @@ namespace Umbraco.Tests.Common.Builders { } - public ContentTypeSortBuilder(ContentTypeBuilder parentBuilder) : base(parentBuilder) + public ContentTypeSortBuilder(ContentTypeBuilder parentBuilder) + : base(parentBuilder) { } diff --git a/src/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs b/src/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs index a600d2d962..b4db018322 100644 --- a/src/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs @@ -48,8 +48,7 @@ namespace Umbraco.Tests.Common.Builders Mock.Of(), Mock.Of(), Mock.Of(), - Mock.Of() - ) + Mock.Of()) { DefaultConfiguration = defaultConfiguration, ExplicitConfigurationEditor = explicitConfigurationEditor, diff --git a/src/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs b/src/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs index 61f6c3df78..70a8e2c706 100644 --- a/src/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs @@ -58,8 +58,7 @@ namespace Umbraco.Tests.Common.Builders Mock.Of(), Mock.Of(), Mock.Of(), - Mock.Of() - ) + Mock.Of()) { Configuration = configuration, View = view, diff --git a/src/Umbraco.Tests.Common/Builders/Interfaces/IWithLoginBuilder.cs b/src/Umbraco.Tests.Common/Builders/Interfaces/IWithLoginBuilder.cs index 5b844869f0..8ab04bcc3f 100644 --- a/src/Umbraco.Tests.Common/Builders/Interfaces/IWithLoginBuilder.cs +++ b/src/Umbraco.Tests.Common/Builders/Interfaces/IWithLoginBuilder.cs @@ -1,3 +1,6 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + namespace Umbraco.Tests.Common.Builders.Interfaces { public interface IWithLoginBuilder diff --git a/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs b/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs index c442efe334..148bd467db 100644 --- a/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs +++ b/src/Umbraco.Tests.Common/Extensions/ContentBaseExtensions.cs @@ -1,4 +1,8 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; +using System.Reflection; using Umbraco.Core.Models; namespace Umbraco.Tests.Testing @@ -12,16 +16,21 @@ namespace Umbraco.Tests.Testing public static void PropertyValues(this IContentBase content, object value, string culture = null, string segment = null) { if (value == null) + { throw new Exception("No properties has been passed in"); + } - var propertyInfos = value.GetType().GetProperties(); - foreach (var propertyInfo in propertyInfos) + PropertyInfo[] propertyInfos = value.GetType().GetProperties(); + foreach (PropertyInfo propertyInfo in propertyInfos) { if (!content.Properties.TryGetValue(propertyInfo.Name, out var property)) + { throw new Exception($"The property alias {propertyInfo.Name} is not valid, because no PropertyType with this alias exists"); + } property.SetValue(propertyInfo.GetValue(value, null), culture, segment); - //Update item with newly added value + + // Update item with newly added value content.Properties.Add(property); } } diff --git a/src/Umbraco.Tests.Common/Published/PublishedSnapshotTestObjects.cs b/src/Umbraco.Tests.Common/Published/PublishedSnapshotTestObjects.cs index 1c618380a0..2fb6c305fb 100644 --- a/src/Umbraco.Tests.Common/Published/PublishedSnapshotTestObjects.cs +++ b/src/Umbraco.Tests.Common/Published/PublishedSnapshotTestObjects.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.Collections.Generic; using Moq; using Umbraco.Core; using Umbraco.Core.Models.PublishedContent; @@ -7,13 +10,13 @@ namespace Umbraco.Tests.Published { public class PublishedSnapshotTestObjects { - [PublishedModel("element1")] public class TestElementModel1 : PublishedElementModel { public TestElementModel1(IPublishedElement content, IPublishedValueFallback fallback) : base(content) - { } + { + } public string Prop1 => this.Value(Mock.Of(), "prop1"); } @@ -23,7 +26,8 @@ namespace Umbraco.Tests.Published { public TestElementModel2(IPublishedElement content, IPublishedValueFallback fallback) : base(content) - { } + { + } public IEnumerable Prop2 => this.Value>(Mock.Of(), "prop2"); } @@ -33,7 +37,8 @@ namespace Umbraco.Tests.Published { public TestContentModel1(IPublishedContent content, IPublishedValueFallback fallback) : base(content) - { } + { + } public string Prop1 => this.Value(Mock.Of(), "prop1"); } @@ -43,10 +48,10 @@ namespace Umbraco.Tests.Published { public TestContentModel2(IPublishedContent content, IPublishedValueFallback fallback) : base(content) - { } + { + } public IEnumerable Prop2 => this.Value>(Mock.Of(), "prop2"); } - } } diff --git a/src/Umbraco.Tests.Common/TestClone.cs b/src/Umbraco.Tests.Common/TestClone.cs index 5fd0aa30e2..4aa957e376 100644 --- a/src/Umbraco.Tests.Common/TestClone.cs +++ b/src/Umbraco.Tests.Common/TestClone.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; using Umbraco.Core.Models; namespace Umbraco.Tests.Common @@ -11,18 +14,13 @@ namespace Umbraco.Tests.Common IsClone = true; } - public TestClone() - { - Id = Guid.NewGuid(); - } + public TestClone() => Id = Guid.NewGuid(); public Guid Id { get; } + public bool IsClone { get; } - public object DeepClone() - { - return new TestClone(Id); - } + public object DeepClone() => new TestClone(Id); /// /// Indicates whether the current object is equal to another object of the same type. @@ -33,8 +31,16 @@ namespace Umbraco.Tests.Common /// An object to compare with this object. public bool Equals(TestClone other) { - if (ReferenceEquals(null, other)) return false; - if (ReferenceEquals(this, other)) return true; + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + return Id.Equals(other.Id); } @@ -47,9 +53,21 @@ namespace Umbraco.Tests.Common /// The object to compare with the current object. public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; + if (obj is null) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + + if (obj.GetType() != GetType()) + { + return false; + } + return Equals((TestClone)obj); } @@ -59,19 +77,10 @@ namespace Umbraco.Tests.Common /// /// A hash code for the current object. /// - public override int GetHashCode() - { - return Id.GetHashCode(); - } + public override int GetHashCode() => Id.GetHashCode(); - public static bool operator ==(TestClone left, TestClone right) - { - return Equals(left, right); - } + public static bool operator ==(TestClone left, TestClone right) => Equals(left, right); - public static bool operator !=(TestClone left, TestClone right) - { - return Equals(left, right) == false; - } + public static bool operator !=(TestClone left, TestClone right) => Equals(left, right) == false; } } diff --git a/src/Umbraco.Tests.Common/TestDefaultCultureAccessor.cs b/src/Umbraco.Tests.Common/TestDefaultCultureAccessor.cs index e1bec33c94..77b3793f26 100644 --- a/src/Umbraco.Tests.Common/TestDefaultCultureAccessor.cs +++ b/src/Umbraco.Tests.Common/TestDefaultCultureAccessor.cs @@ -1,4 +1,7 @@ -using Umbraco.Web.PublishedCache; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Web.PublishedCache; namespace Umbraco.Tests.Common { diff --git a/src/Umbraco.Tests.Common/TestHelperBase.cs b/src/Umbraco.Tests.Common/TestHelperBase.cs index ed3e28ee21..b7ad1e7f52 100644 --- a/src/Umbraco.Tests.Common/TestHelperBase.cs +++ b/src/Umbraco.Tests.Common/TestHelperBase.cs @@ -1,3 +1,6 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + using System; using System.IO; using System.Reflection; @@ -10,21 +13,18 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Models; -using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Diagnostics; using Umbraco.Core.Hosting; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Models.PublishedContent; -using Umbraco.Net; using Umbraco.Core.Persistence; using Umbraco.Core.Serialization; using Umbraco.Core.Strings; +using Umbraco.Net; +using Umbraco.Tests.Common.TestHelpers; using Umbraco.Web; using Umbraco.Web.Routing; -using Umbraco.Tests.Common.Builders; -using System.Runtime.InteropServices; -using Umbraco.Tests.Common.TestHelpers; namespace Umbraco.Tests.Common { @@ -46,16 +46,14 @@ namespace Umbraco.Tests.Common public ITypeFinder GetTypeFinder() => _typeFinder; - public TypeLoader GetMockedTypeLoader() - { - return new TypeLoader(Mock.Of(), Mock.Of(), new DirectoryInfo(GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of>(), Mock.Of()); - } + public TypeLoader GetMockedTypeLoader() => + new TypeLoader(Mock.Of(), Mock.Of(), new DirectoryInfo(GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of>(), Mock.Of()); - // public Configs GetConfigs() => GetConfigsFactory().Create(); + //// public Configs GetConfigs() => GetConfigsFactory().Create(); public abstract IBackOfficeInfo GetBackOfficeInfo(); - //public IConfigsFactory GetConfigsFactory() => new ConfigsFactory(); + //// public IConfigsFactory GetConfigsFactory() => new ConfigsFactory(); /// /// Gets the working directory of the test project. @@ -64,24 +62,36 @@ namespace Umbraco.Tests.Common { get { - if (_workingDir != null) return _workingDir; + if (_workingDir != null) + { + return _workingDir; + } var dir = Path.Combine(Assembly.GetExecutingAssembly().GetRootDirectorySafe(), "TEMP"); if (!Directory.Exists(dir)) + { Directory.CreateDirectory(dir); + } + _workingDir = dir; return _workingDir; } } public IShortStringHelper ShortStringHelper { get; } = new DefaultShortStringHelper(new DefaultShortStringHelperConfig()); + public IJsonSerializer JsonSerializer { get; } = new JsonNetSerializer(); + public IVariationContextAccessor VariationContextAccessor { get; } = new TestVariationContextAccessor(); + public abstract IDbProviderFactoryCreator DbProviderFactoryCreator { get; } + public abstract IBulkSqlInsertProvider BulkSqlInsertProvider { get; } + public abstract IMarchal Marchal { get; } - public CoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); + + public CoreDebugSettings CoreDebugSettings { get; } = new CoreDebugSettings(); public IIOHelper IOHelper { @@ -89,7 +99,7 @@ namespace Umbraco.Tests.Common { if (_ioHelper == null) { - var hostingEnvironment = GetHostingEnvironment(); + IHostingEnvironment hostingEnvironment = GetHostingEnvironment(); if (TestEnvironment.IsWindows) { @@ -108,29 +118,35 @@ namespace Umbraco.Tests.Common throw new NotSupportedException("Unexpected OS"); } } + return _ioHelper; } } public IMainDom MainDom { get; } + public UriUtility UriUtility { get { if (_uriUtility == null) + { _uriUtility = new UriUtility(GetHostingEnvironment()); + } + return _uriUtility; } } + /// /// Some test files are copied to the /bin (/bin/debug) on build, this is a utility to return their physical path based on a virtual path name /// - /// - /// public virtual string MapPathForTestFiles(string relativePath) { if (!relativePath.StartsWith("~/")) + { throw new ArgumentException("relativePath must start with '~/'", nameof(relativePath)); + } var codeBase = typeof(TestHelperBase).Assembly.CodeBase; var uri = new Uri(codeBase); @@ -142,20 +158,15 @@ namespace Umbraco.Tests.Common public IUmbracoVersion GetUmbracoVersion() => new UmbracoVersion(); - public IServiceCollection GetRegister() - { - return new ServiceCollection(); - } + public IServiceCollection GetRegister() => new ServiceCollection(); public abstract IHostingEnvironment GetHostingEnvironment(); + public abstract IApplicationShutdownRegistry GetHostingEnvironmentLifetime(); public abstract IIpResolver GetIpResolver(); - public IRequestCache GetRequestCache() - { - return new DictionaryAppCache(); - } + public IRequestCache GetRequestCache() => new DictionaryAppCache(); public IPublishedUrlProvider GetPublishedUrlProvider() { @@ -168,7 +179,7 @@ namespace Umbraco.Tests.Common { hostingEnv = hostingEnv ?? GetHostingEnvironment(); return new LoggingConfiguration( - Path.Combine(hostingEnv.ApplicationPhysicalPath, "umbraco","logs")); + Path.Combine(hostingEnv.ApplicationPhysicalPath, "umbraco", "logs")); } } } diff --git a/src/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs b/src/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs index b80a2996ca..9069bdcbf0 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs @@ -1,3 +1,6 @@ +// Copyright (c) Umbraco. +// See LICENSE for more details. + using Moq; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Serialization; @@ -10,7 +13,7 @@ namespace Umbraco.Tests.TestHelpers.Entities { public static DataValueEditor CreateDataValueEditor(string name) { - var valueType = (ValueTypes.IsValue(name)) ? name : ValueTypes.String; + var valueType = ValueTypes.IsValue(name) ? name : ValueTypes.String; return new DataValueEditor( Mock.Of(), @@ -21,9 +24,7 @@ namespace Umbraco.Tests.TestHelpers.Entities new DataEditorAttribute(name, name, name) { ValueType = valueType - } - - ); + }); } } } diff --git a/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs b/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs index e7f6cc4442..f14b6633ba 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/SolidPublishedSnapshot.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; @@ -28,20 +31,19 @@ namespace Umbraco.Tests.Common.PublishedContent public IDomainCache Domains => null; - public IDisposable ForcedPreview(bool forcedPreview, Action callback = null) - { - throw new NotImplementedException(); - } + public IDisposable ForcedPreview(bool forcedPreview, Action callback = null) => throw new NotImplementedException(); public void Resync() - { } + { + } public IAppCache SnapshotCache => null; public IAppCache ElementsCache => null; public void Dispose() - { } + { + } } public class SolidPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache @@ -50,121 +52,56 @@ namespace Umbraco.Tests.Common.PublishedContent public SolidPublishedContentCache() : base(false) - { } - - public void Add(SolidPublishedContent content) { - _content[content.Id] = content.CreateModel(Mock.Of()); } - public void Clear() - { - _content.Clear(); - } + public void Add(SolidPublishedContent content) => _content[content.Id] = content.CreateModel(Mock.Of()); - public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null) - { - throw new NotImplementedException(); - } + public void Clear() => _content.Clear(); - public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null) - { - throw new NotImplementedException(); - } + public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); - public string GetRouteById(bool preview, int contentId, string culture = null) - { - throw new NotImplementedException(); - } + public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null, string culture = null) => throw new NotImplementedException(); - public string GetRouteById(int contentId, string culture = null) - { - throw new NotImplementedException(); - } + public string GetRouteById(bool preview, int contentId, string culture = null) => throw new NotImplementedException(); - public override IPublishedContent GetById(bool preview, int contentId) - { - return _content.ContainsKey(contentId) ? _content[contentId] : null; - } + public string GetRouteById(int contentId, string culture = null) => throw new NotImplementedException(); - public override IPublishedContent GetById(bool preview, Guid contentId) - { - throw new NotImplementedException(); - } + public override IPublishedContent GetById(bool preview, int contentId) => _content.ContainsKey(contentId) ? _content[contentId] : null; - public override IPublishedContent GetById(bool preview, Udi nodeId) - => throw new NotSupportedException(); + public override IPublishedContent GetById(bool preview, Guid contentId) => throw new NotImplementedException(); - public override bool HasById(bool preview, int contentId) - { - return _content.ContainsKey(contentId); - } + public override IPublishedContent GetById(bool preview, Udi nodeId) => throw new NotSupportedException(); - public override IEnumerable GetAtRoot(bool preview, string culture = null) - { - return _content.Values.Where(x => x.Parent == null); - } + public override bool HasById(bool preview, int contentId) => _content.ContainsKey(contentId); - public override IPublishedContent GetSingleByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars) - { - throw new NotImplementedException(); - } + public override IEnumerable GetAtRoot(bool preview, string culture = null) => _content.Values.Where(x => x.Parent == null); - public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) - { - throw new NotImplementedException(); - } + public override IPublishedContent GetSingleByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars) => throw new NotImplementedException(); - public override IEnumerable GetByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars) - { - throw new NotImplementedException(); - } + public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) => throw new NotImplementedException(); - public override IEnumerable GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) - { - throw new NotImplementedException(); - } + public override IEnumerable GetByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars) => throw new NotImplementedException(); - public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview) - { - throw new NotImplementedException(); - } + public override IEnumerable GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) => throw new NotImplementedException(); - public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview) - { - throw new NotImplementedException(); - } + public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview) => throw new NotImplementedException(); - public override bool HasContent(bool preview) - { - return _content.Count > 0; - } + public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview) => throw new NotImplementedException(); - public override IPublishedContentType GetContentType(int id) - { - throw new NotImplementedException(); - } + public override bool HasContent(bool preview) => _content.Count > 0; - public override IPublishedContentType GetContentType(string alias) - { - throw new NotImplementedException(); - } + public override IPublishedContentType GetContentType(int id) => throw new NotImplementedException(); - public override IPublishedContentType GetContentType(Guid key) - { - throw new NotImplementedException(); - } + public override IPublishedContentType GetContentType(string alias) => throw new NotImplementedException(); - public override IEnumerable GetByContentType(IPublishedContentType contentType) - { - throw new NotImplementedException(); - } + public override IPublishedContentType GetContentType(Guid key) => throw new NotImplementedException(); + + public override IEnumerable GetByContentType(IPublishedContentType contentType) => throw new NotImplementedException(); } public class SolidPublishedContent : IPublishedContent { - #region Constructor - public SolidPublishedContent(IPublishedContentType contentType) { // initialize boring stuff @@ -176,68 +113,67 @@ namespace Umbraco.Tests.Common.PublishedContent ContentType = contentType; } - #endregion - - #region Content - private Dictionary _cultures; - private Dictionary GetCultures() - { - return new Dictionary { { "", new PublishedCultureInfo("", Name, UrlSegment, UpdateDate) } }; - } + private Dictionary GetCultures() => new Dictionary { { string.Empty, new PublishedCultureInfo(string.Empty, Name, UrlSegment, UpdateDate) } }; public int Id { get; set; } + public Guid Key { get; set; } + public int? TemplateId { get; set; } + public int SortOrder { get; set; } + public string Name { get; set; } + public IReadOnlyDictionary Cultures => _cultures ?? (_cultures = GetCultures()); + public string UrlSegment { get; set; } + public int WriterId { get; set; } + public int CreatorId { get; set; } + public string Path { get; set; } + public DateTime CreateDate { get; set; } + public DateTime UpdateDate { get; set; } + public Guid Version { get; set; } + public int Level { get; set; } public PublishedItemType ItemType => PublishedItemType.Content; + public bool IsDraft(string culture = null) => false; + public bool IsPublished(string culture = null) => true; - #endregion - - #region Tree - public int ParentId { get; set; } + public IEnumerable ChildIds { get; set; } public IPublishedContent Parent { get; set; } + public IEnumerable Children { get; set; } + public IEnumerable ChildrenForAllCultures => Children; - #endregion - - #region ContentType - public IPublishedContentType ContentType { get; set; } - #endregion - - #region Properties - public IEnumerable Properties { get; set; } - public IPublishedProperty GetProperty(string alias) - { - return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); - } + public IPublishedProperty GetProperty(string alias) => Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); public IPublishedProperty GetProperty(string alias, bool recurse) { - var property = GetProperty(alias); - if (recurse == false) return property; + IPublishedProperty property = GetProperty(alias); + if (recurse == false) + { + return property; + } IPublishedContent content = this; while (content != null && (property == null || property.HasValue() == false)) @@ -257,22 +193,28 @@ namespace Umbraco.Tests.Common.PublishedContent return property == null || property.HasValue() == false ? null : property.GetValue(); } } - - #endregion } public class SolidPublishedProperty : IPublishedProperty { public IPublishedPropertyType PropertyType { get; set; } + public string Alias { get; set; } + public object SolidSourceValue { get; set; } + public object SolidValue { get; set; } + public bool SolidHasValue { get; set; } + public object SolidXPathValue { get; set; } public virtual object GetSourceValue(string culture = null, string segment = null) => SolidSourceValue; + public virtual object GetValue(string culture = null, string segment = null) => SolidValue; + public virtual object GetXPathValue(string culture = null, string segment = null) => SolidXPathValue; + public virtual bool HasValue(string culture = null, string segment = null) => SolidHasValue; } @@ -355,13 +297,10 @@ namespace Umbraco.Tests.Common.PublishedContent [PublishedModel("ContentType2")] public class ContentType2 : PublishedContentModel { - #region Plumbing - public ContentType2(IPublishedContent content, IPublishedValueFallback fallback) : base(content) - { } - - #endregion + { + } public int Prop1 => this.Value(Mock.Of(), "prop1"); } @@ -369,20 +308,18 @@ namespace Umbraco.Tests.Common.PublishedContent [PublishedModel("ContentType2Sub")] public class ContentType2Sub : ContentType2 { - #region Plumbing - public ContentType2Sub(IPublishedContent content, IPublishedValueFallback fallback) : base(content, fallback) - { } - - #endregion + { + } } public class PublishedContentStrong1 : PublishedContentModel { public PublishedContentStrong1(IPublishedContent content, IPublishedValueFallback fallback) : base(content) - { } + { + } public int StrongValue => this.Value(Mock.Of(), "strongValue"); } @@ -391,7 +328,8 @@ namespace Umbraco.Tests.Common.PublishedContent { public PublishedContentStrong1Sub(IPublishedContent content, IPublishedValueFallback fallback) : base(content, fallback) - { } + { + } public int AnotherValue => this.Value(Mock.Of(), "anotherValue"); } @@ -400,7 +338,8 @@ namespace Umbraco.Tests.Common.PublishedContent { public PublishedContentStrong2(IPublishedContent content, IPublishedValueFallback fallback) : base(content) - { } + { + } public int StrongValue => this.Value(Mock.Of(), "strongValue"); } @@ -415,9 +354,18 @@ namespace Umbraco.Tests.Common.PublishedContent var jsonSerializer = new JsonNetSerializer(); var dataTypeServiceMock = new Mock(); - var dataType = new DataType(new VoidEditor(Mock.Of(), dataTypeServiceMock.Object, - Mock.Of(), Mock.Of(), Mock.Of(), jsonSerializer), configurationEditorJsonSerializer) - { Id = 666 }; + var dataType = new DataType( + new VoidEditor( + Mock.Of(), + dataTypeServiceMock.Object, + Mock.Of(), + Mock.Of(), + Mock.Of(), + jsonSerializer), + configurationEditorJsonSerializer) + { + Id = 666 + }; dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield); var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), dataTypeServiceMock.Object); @@ -426,23 +374,27 @@ namespace Umbraco.Tests.Common.PublishedContent public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable propertyTypes) : base(key, id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing) - { } + { + } public AutoPublishedContentType(Guid key, int id, string alias, Func> propertyTypes) : base(key, id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.Nothing) - { } + { + } public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes) : base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing) - { } + { + } public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable compositionAliases, Func> propertyTypes) : base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing) - { } + { + } public override IPublishedPropertyType GetPropertyType(string alias) { - var propertyType = base.GetPropertyType(alias); + IPublishedPropertyType propertyType = base.GetPropertyType(alias); return propertyType ?? Default; } } diff --git a/src/Umbraco.Tests.Common/TestHelpers/StringNewlineExtensions.cs b/src/Umbraco.Tests.Common/TestHelpers/StringNewlineExtensions.cs index 6de58f84b2..70e84a41c2 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/StringNewlineExtensions.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/StringNewlineExtensions.cs @@ -1,4 +1,7 @@ -namespace Umbraco.Tests +// Copyright (c) Umbraco. +// See LICENSE for more details. + +namespace Umbraco.Tests { public static class StringNewLineExtensions { @@ -9,8 +12,12 @@ /// The filtered text. public static string Lf(this string text) { - if (string.IsNullOrEmpty(text)) return text; - text = text.Replace("\r", ""); // remove CR + if (string.IsNullOrEmpty(text)) + { + return text; + } + + text = text.Replace("\r", string.Empty); // remove CR return text; } @@ -21,8 +28,12 @@ /// The filtered text. public static string CrLf(this string text) { - if (string.IsNullOrEmpty(text)) return text; - text = text.Replace("\r", ""); // remove CR + if (string.IsNullOrEmpty(text)) + { + return text; + } + + text = text.Replace("\r", string.Empty); // remove CR text = text.Replace("\n", "\r\n"); // add CRLF everywhere return text; } @@ -34,7 +45,11 @@ /// The filtered text. public static string NoCrLf(this string text) { - if (string.IsNullOrEmpty(text)) return text; + if (string.IsNullOrEmpty(text)) + { + return text; + } + text = text.Replace("\r\n", " "); // remove CRLF text = text.Replace("\r", " "); // remove CR text = text.Replace("\n", " "); // remove LF diff --git a/src/Umbraco.Tests.Common/TestHelpers/Stubs/TestProfiler.cs b/src/Umbraco.Tests.Common/TestHelpers/Stubs/TestProfiler.cs index ea0f9cc44f..478fde32d4 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/Stubs/TestProfiler.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/Stubs/TestProfiler.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; using StackExchange.Profiling; using StackExchange.Profiling.SqlFormatters; using Umbraco.Core.Logging; @@ -7,41 +10,37 @@ namespace Umbraco.Tests.TestHelpers.Stubs { public class TestProfiler : IProfiler { - public static void Enable() - { - _enabled = true; - } + public static void Enable() => s_enabled = true; - public static void Disable() - { - _enabled = false; - } + public static void Disable() => s_enabled = false; - private static bool _enabled; + private static bool s_enabled; - public IDisposable Step(string name) - { - return _enabled ? MiniProfiler.Current.Step(name) : null; - } + public IDisposable Step(string name) => s_enabled ? MiniProfiler.Current.Step(name) : null; public void Start() { - if (_enabled == false) return; + if (s_enabled == false) + { + return; + } - //see https://miniprofiler.com/dotnet/AspDotNet + // See https://miniprofiler.com/dotnet/AspDotNet MiniProfiler.Configure(new MiniProfilerOptions { SqlFormatter = new SqlServerFormatter(), StackMaxLength = 5000, }); - + MiniProfiler.StartNew(); } public void Stop(bool discardResults = false) { - if (_enabled) + if (s_enabled) + { MiniProfiler.Current.Stop(discardResults); + } } } } diff --git a/src/Umbraco.Tests.Common/TestHelpers/TestDatabase.cs b/src/Umbraco.Tests.Common/TestHelpers/TestDatabase.cs index d1e5669100..303d534b98 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/TestDatabase.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/TestDatabase.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; using System.Collections; using System.Collections.Generic; using System.Data; @@ -41,22 +44,13 @@ namespace Umbraco.Tests.Testing /// public class Operation { - public Operation(string text) - { - Text = text; - } + public Operation(string text) => Text = text; public Operation(string text, string sql) - : this(text) - { - Sql = sql; - } + : this(text) => Sql = sql; public Operation(string text, string sql, params object[] args) - : this(text, sql) - { - Args = args; - } + : this(text, sql) => Args = args; /// /// Gets the operation text. @@ -79,89 +73,65 @@ namespace Umbraco.Tests.Testing /// public List Operations { get; } = new List(); - #region Connection, Transaction and Stuff - public void Dispose() - { } - - public IDatabase OpenSharedConnection() { - return this; } + public IDatabase OpenSharedConnection() => this; + public void CloseSharedConnection() - { } + { + } public int OneTimeCommandTimeout { get; set; } + public MapperCollection Mappers { get; set; } + public IPocoDataFactory PocoDataFactory { get; set; } + public DatabaseType DatabaseType { get; } + public List Interceptors { get; } + public string ConnectionString { get; } public DbConnection Connection { get; } + public DbTransaction Transaction { get; } + public IDictionary Data { get; } + public ISqlContext SqlContext { get; } + public string InstanceId { get; } + public bool InTransaction { get; } + public bool EnableSqlCount { get; set; } + public int SqlCount { get; } + public int BulkInsertRecords(IEnumerable records) => throw new NotImplementedException(); - public DbParameter CreateParameter() - { - throw new NotImplementedException(); - } + public DbParameter CreateParameter() => throw new NotImplementedException(); - public void AddParameter(DbCommand cmd, object value) - { - throw new NotImplementedException(); - } + public void AddParameter(DbCommand cmd, object value) => throw new NotImplementedException(); - public DbCommand CreateCommand(DbConnection connection, CommandType commandType, string sql, params object[] args) - { - throw new NotImplementedException(); - } + public DbCommand CreateCommand(DbConnection connection, CommandType commandType, string sql, params object[] args) => throw new NotImplementedException(); - public ITransaction GetTransaction() - { - throw new NotImplementedException(); - } + public ITransaction GetTransaction() => throw new NotImplementedException(); - public ITransaction GetTransaction(IsolationLevel isolationLevel) - { - throw new NotImplementedException(); - } + public ITransaction GetTransaction(IsolationLevel isolationLevel) => throw new NotImplementedException(); - public void SetTransaction(DbTransaction tran) - { - throw new NotImplementedException(); - } + public void SetTransaction(DbTransaction tran) => throw new NotImplementedException(); - public void BeginTransaction() - { - Operations.Add(new Operation("BEGIN")); - } + public void BeginTransaction() => Operations.Add(new Operation("BEGIN")); - public void BeginTransaction(IsolationLevel isolationLevel) - { - Operations.Add(new Operation("BEGIN " + isolationLevel)); - } + public void BeginTransaction(IsolationLevel isolationLevel) => Operations.Add(new Operation("BEGIN " + isolationLevel)); - public void AbortTransaction() - { - Operations.Add(new Operation("ABORT")); - } + public void AbortTransaction() => Operations.Add(new Operation("ABORT")); - public void CompleteTransaction() - { - Operations.Add(new Operation("COMMIT")); - } - - #endregion - - #region Writes + public void CompleteTransaction() => Operations.Add(new Operation("COMMIT")); public int Execute(string sql, params object[] args) { @@ -199,578 +169,238 @@ namespace Umbraco.Tests.Testing return default; } - public Task ExecuteScalarAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } + public Task ExecuteScalarAsync(string sql, params object[] args) => throw new NotImplementedException(); - public Task ExecuteScalarAsync(Sql sql) - { - throw new NotImplementedException(); - } + public Task ExecuteScalarAsync(Sql sql) => throw new NotImplementedException(); - public Task ExecuteAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } + public Task ExecuteAsync(string sql, params object[] args) => throw new NotImplementedException(); - public Task ExecuteAsync(Sql sql) - { - throw new NotImplementedException(); - } + public Task ExecuteAsync(Sql sql) => throw new NotImplementedException(); - public object Insert(string tableName, string primaryKeyName, bool autoIncrement, T poco) - { - throw new NotImplementedException(); - } + public object Insert(string tableName, string primaryKeyName, bool autoIncrement, T poco) => throw new NotImplementedException(); - public object Insert(string tableName, string primaryKeyName, T poco) - { - throw new NotImplementedException(); - } + public object Insert(string tableName, string primaryKeyName, T poco) => throw new NotImplementedException(); - public object Insert(T poco) - { - throw new NotImplementedException(); - } + public object Insert(T poco) => throw new NotImplementedException(); - public Task InsertAsync(T poco) - { - throw new NotImplementedException(); - } + public Task InsertAsync(T poco) => throw new NotImplementedException(); public Task InsertBatchAsync(IEnumerable pocos, BatchOptions options = null) => throw new NotImplementedException(); - public Task UpdateAsync(object poco) - { - throw new NotImplementedException(); - } + public Task UpdateAsync(object poco) => throw new NotImplementedException(); - public Task UpdateAsync(object poco, IEnumerable columns) - { - throw new NotImplementedException(); - } + public Task UpdateAsync(object poco, IEnumerable columns) => throw new NotImplementedException(); - public Task UpdateAsync(T poco, Expression> fields) - { - throw new NotImplementedException(); - } + public Task UpdateAsync(T poco, Expression> fields) => throw new NotImplementedException(); public Task UpdateBatchAsync(IEnumerable> pocos, BatchOptions options = null) => throw new NotImplementedException(); - public Task DeleteAsync(object poco) - { - throw new NotImplementedException(); - } + public Task DeleteAsync(object poco) => throw new NotImplementedException(); public IAsyncUpdateQueryProvider UpdateManyAsync() => throw new NotImplementedException(); public IAsyncDeleteQueryProvider DeleteManyAsync() => throw new NotImplementedException(); - public void InsertBulk(IEnumerable pocos) - { - throw new NotImplementedException(); - } + public void InsertBulk(IEnumerable pocos) => throw new NotImplementedException(); int IDatabase.InsertBatch(IEnumerable pocos, BatchOptions options) => throw new NotImplementedException(); - public void InsertBatch(IEnumerable pocos, BatchOptions options = null) - { - throw new NotImplementedException(); - } + public void InsertBatch(IEnumerable pocos, BatchOptions options = null) => throw new NotImplementedException(); - public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue) - { - throw new NotImplementedException(); - } + public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue) => throw new NotImplementedException(); - public int Update(string tableName, string primaryKeyName, object poco) - { - throw new NotImplementedException(); - } + public int Update(string tableName, string primaryKeyName, object poco) => throw new NotImplementedException(); - public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns) - { - throw new NotImplementedException(); - } + public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns) => throw new NotImplementedException(); - public int Update(string tableName, string primaryKeyName, object poco, IEnumerable columns) - { - throw new NotImplementedException(); - } + public int Update(string tableName, string primaryKeyName, object poco, IEnumerable columns) => throw new NotImplementedException(); - public int Update(object poco, IEnumerable columns) - { - throw new NotImplementedException(); - } + public int Update(object poco, IEnumerable columns) => throw new NotImplementedException(); - public int Update(object poco, object primaryKeyValue, IEnumerable columns) - { - throw new NotImplementedException(); - } + public int Update(object poco, object primaryKeyValue, IEnumerable columns) => throw new NotImplementedException(); - public int Update(object poco) - { - throw new NotImplementedException(); - } + public int Update(object poco) => throw new NotImplementedException(); - public int Update(T poco, Expression> fields) - { - throw new NotImplementedException(); - } + public int Update(T poco, Expression> fields) => throw new NotImplementedException(); - public int Update(object poco, object primaryKeyValue) - { - throw new NotImplementedException(); - } + public int Update(object poco, object primaryKeyValue) => throw new NotImplementedException(); - public int Update(string sql, params object[] args) - { - throw new NotImplementedException(); - } + public int Update(string sql, params object[] args) => throw new NotImplementedException(); - public int Update(Sql sql) - { - throw new NotImplementedException(); - } + public int Update(Sql sql) => throw new NotImplementedException(); public int UpdateBatch(IEnumerable> pocos, BatchOptions options = null) => throw new NotImplementedException(); - public IUpdateQueryProvider UpdateMany() - { - throw new NotImplementedException(); - } - - public int Delete(string tableName, string primaryKeyName, object poco) - { - throw new NotImplementedException(); - } - - public int Delete(string tableName, string primaryKeyName, object poco, object primaryKeyValue) - { - throw new NotImplementedException(); - } - - public int Delete(object poco) - { - throw new NotImplementedException(); - } - - public int Delete(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public int Delete(Sql sql) - { - throw new NotImplementedException(); - } - - public int Delete(object pocoOrPrimaryKey) - { - throw new NotImplementedException(); - } - - public IDeleteQueryProvider DeleteMany() - { - throw new NotImplementedException(); - } - - public void Save(T poco) - { - throw new NotImplementedException(); - } - - public bool IsNew(T poco) - { - throw new NotImplementedException(); - } - - #endregion - - #region Reads (not implemented) - - public List Fetch(Type type, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public List Fetch(Type type, Sql Sql) - { - throw new NotImplementedException(); - } - - public IEnumerable Query(Type type, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public IEnumerable Query(Type type, Sql Sql) - { - throw new NotImplementedException(); - } - - public List Fetch() - { - throw new NotImplementedException(); - } - - public List Fetch(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public List Fetch(Sql sql) - { - throw new NotImplementedException(); - } - - public List Fetch(long page, long itemsPerPage, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public List Fetch(long page, long itemsPerPage, Sql sql) - { - throw new NotImplementedException(); - } - - public Page Page(long page, long itemsPerPage, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Page Page(long page, long itemsPerPage, Sql sql) - { - throw new NotImplementedException(); - } - - public List SkipTake(long skip, long take, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public List SkipTake(long skip, long take, Sql sql) - { - throw new NotImplementedException(); - } - - public List FetchOneToMany(Expression> many, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public List FetchOneToMany(Expression> many, Sql sql) - { - throw new NotImplementedException(); - } - - public List FetchOneToMany(Expression> many, Func idFunc, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public List FetchOneToMany(Expression> many, Func idFunc, Sql sql) - { - throw new NotImplementedException(); - } - - public IEnumerable Query(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public IEnumerable Query(Sql sql) - { - throw new NotImplementedException(); - } - - public IQueryProviderWithIncludes Query() - { - throw new NotImplementedException(); - } - - public T SingleById(object primaryKey) - { - throw new NotImplementedException(); - } - - public T Single(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T SingleInto(T instance, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T SingleOrDefaultById(object primaryKey) - { - throw new NotImplementedException(); - } - - public T SingleOrDefault(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T SingleOrDefaultInto(T instance, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T First(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T FirstInto(T instance, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T FirstOrDefault(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T FirstOrDefaultInto(T instance, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public T Single(Sql sql) - { - throw new NotImplementedException(); - } - - public T SingleInto(T instance, Sql sql) - { - throw new NotImplementedException(); - } - - public T SingleOrDefault(Sql sql) - { - throw new NotImplementedException(); - } - - public T SingleOrDefaultInto(T instance, Sql sql) - { - throw new NotImplementedException(); - } - - public T First(Sql sql) - { - throw new NotImplementedException(); - } - - public T FirstInto(T instance, Sql sql) - { - throw new NotImplementedException(); - } - - public T FirstOrDefault(Sql sql) - { - throw new NotImplementedException(); - } - - public T FirstOrDefaultInto(T instance, Sql sql) - { - throw new NotImplementedException(); - } - - public Dictionary Dictionary(Sql Sql) - { - throw new NotImplementedException(); - } - - public Dictionary Dictionary(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public bool Exists(object primaryKey) - { - throw new NotImplementedException(); - } - - public TRet FetchMultiple(Func, List, TRet> cb, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public TRet FetchMultiple(Func, List, List, TRet> cb, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public TRet FetchMultiple(Func, List, List, List, TRet> cb, string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public TRet FetchMultiple(Func, List, TRet> cb, Sql sql) - { - throw new NotImplementedException(); - } - - public TRet FetchMultiple(Func, List, List, TRet> cb, Sql sql) - { - throw new NotImplementedException(); - } - - public TRet FetchMultiple(Func, List, List, List, TRet> cb, Sql sql) - { - throw new NotImplementedException(); - } - - public Tuple, List> FetchMultiple(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Tuple, List, List> FetchMultiple(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Tuple, List, List, List> FetchMultiple(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Tuple, List> FetchMultiple(Sql sql) - { - throw new NotImplementedException(); - } - - public Tuple, List, List> FetchMultiple(Sql sql) - { - throw new NotImplementedException(); - } - - public Tuple, List, List, List> FetchMultiple(Sql sql) - { - throw new NotImplementedException(); - } - - public Task SingleAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Task SingleAsync(Sql sql) - { - throw new NotImplementedException(); - } - - public Task SingleOrDefaultAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Task SingleOrDefaultAsync(Sql sql) - { - throw new NotImplementedException(); - } - - public Task SingleByIdAsync(object primaryKey) - { - throw new NotImplementedException(); - } - - public Task SingleOrDefaultByIdAsync(object primaryKey) - { - throw new NotImplementedException(); - } - - public Task FirstAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Task FirstAsync(Sql sql) - { - throw new NotImplementedException(); - } - - public Task FirstOrDefaultAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Task FirstOrDefaultAsync(Sql sql) - { - throw new NotImplementedException(); - } - - public Task> QueryAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } - - public Task> QueryAsync(Sql sql) - { - throw new NotImplementedException(); - } + public IUpdateQueryProvider UpdateMany() => throw new NotImplementedException(); + + public int Delete(string tableName, string primaryKeyName, object poco) => throw new NotImplementedException(); + + public int Delete(string tableName, string primaryKeyName, object poco, object primaryKeyValue) => throw new NotImplementedException(); + + public int Delete(object poco) => throw new NotImplementedException(); + + public int Delete(string sql, params object[] args) => throw new NotImplementedException(); + + public int Delete(Sql sql) => throw new NotImplementedException(); + + public int Delete(object pocoOrPrimaryKey) => throw new NotImplementedException(); + + public IDeleteQueryProvider DeleteMany() => throw new NotImplementedException(); + + public void Save(T poco) => throw new NotImplementedException(); + + public bool IsNew(T poco) => throw new NotImplementedException(); + + public List Fetch(Type type, string sql, params object[] args) => throw new NotImplementedException(); + + public List Fetch(Type type, Sql sql) => throw new NotImplementedException(); + + public IEnumerable Query(Type type, string sql, params object[] args) => throw new NotImplementedException(); + + public IEnumerable Query(Type type, Sql sql) => throw new NotImplementedException(); + + public List Fetch() => throw new NotImplementedException(); + + public List Fetch(string sql, params object[] args) => throw new NotImplementedException(); + + public List Fetch(Sql sql) => throw new NotImplementedException(); + + public List Fetch(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException(); + + public List Fetch(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException(); + + public Page Page(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException(); + + public Page Page(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException(); + + public List SkipTake(long skip, long take, string sql, params object[] args) => throw new NotImplementedException(); + + public List SkipTake(long skip, long take, Sql sql) => throw new NotImplementedException(); + + public List FetchOneToMany(Expression> many, string sql, params object[] args) => throw new NotImplementedException(); + + public List FetchOneToMany(Expression> many, Sql sql) => throw new NotImplementedException(); + + public List FetchOneToMany(Expression> many, Func idFunc, string sql, params object[] args) => throw new NotImplementedException(); + + public List FetchOneToMany(Expression> many, Func idFunc, Sql sql) => throw new NotImplementedException(); + + public IEnumerable Query(string sql, params object[] args) => throw new NotImplementedException(); + + public IEnumerable Query(Sql sql) => throw new NotImplementedException(); + + public IQueryProviderWithIncludes Query() => throw new NotImplementedException(); + + public T SingleById(object primaryKey) => throw new NotImplementedException(); + + public T Single(string sql, params object[] args) => throw new NotImplementedException(); + + public T SingleInto(T instance, string sql, params object[] args) => throw new NotImplementedException(); + + public T SingleOrDefaultById(object primaryKey) => throw new NotImplementedException(); + + public T SingleOrDefault(string sql, params object[] args) => throw new NotImplementedException(); + + public T SingleOrDefaultInto(T instance, string sql, params object[] args) => throw new NotImplementedException(); + + public T First(string sql, params object[] args) => throw new NotImplementedException(); + + public T FirstInto(T instance, string sql, params object[] args) => throw new NotImplementedException(); + + public T FirstOrDefault(string sql, params object[] args) => throw new NotImplementedException(); + + public T FirstOrDefaultInto(T instance, string sql, params object[] args) => throw new NotImplementedException(); + + public T Single(Sql sql) => throw new NotImplementedException(); + + public T SingleInto(T instance, Sql sql) => throw new NotImplementedException(); + + public T SingleOrDefault(Sql sql) => throw new NotImplementedException(); + + public T SingleOrDefaultInto(T instance, Sql sql) => throw new NotImplementedException(); + + public T First(Sql sql) => throw new NotImplementedException(); + + public T FirstInto(T instance, Sql sql) => throw new NotImplementedException(); + + public T FirstOrDefault(Sql sql) => throw new NotImplementedException(); + + public T FirstOrDefaultInto(T instance, Sql sql) => throw new NotImplementedException(); + + public Dictionary Dictionary(Sql sql) => throw new NotImplementedException(); + + public Dictionary Dictionary(string sql, params object[] args) => throw new NotImplementedException(); + + public bool Exists(object primaryKey) => throw new NotImplementedException(); + + public TRet FetchMultiple(Func, List, TRet> cb, string sql, params object[] args) => throw new NotImplementedException(); + + public TRet FetchMultiple(Func, List, List, TRet> cb, string sql, params object[] args) => throw new NotImplementedException(); + + public TRet FetchMultiple(Func, List, List, List, TRet> cb, string sql, params object[] args) => throw new NotImplementedException(); + + public TRet FetchMultiple(Func, List, TRet> cb, Sql sql) => throw new NotImplementedException(); + + public TRet FetchMultiple(Func, List, List, TRet> cb, Sql sql) => throw new NotImplementedException(); + + public TRet FetchMultiple(Func, List, List, List, TRet> cb, Sql sql) => throw new NotImplementedException(); + + public Tuple, List> FetchMultiple(string sql, params object[] args) => throw new NotImplementedException(); + + public Tuple, List, List> FetchMultiple(string sql, params object[] args) => throw new NotImplementedException(); + + public Tuple, List, List, List> FetchMultiple(string sql, params object[] args) => throw new NotImplementedException(); + + public Tuple, List> FetchMultiple(Sql sql) => throw new NotImplementedException(); + + public Tuple, List, List> FetchMultiple(Sql sql) => throw new NotImplementedException(); + + public Tuple, List, List, List> FetchMultiple(Sql sql) => throw new NotImplementedException(); + + public Task SingleAsync(string sql, params object[] args) => throw new NotImplementedException(); + + public Task SingleAsync(Sql sql) => throw new NotImplementedException(); + + public Task SingleOrDefaultAsync(string sql, params object[] args) => throw new NotImplementedException(); + + public Task SingleOrDefaultAsync(Sql sql) => throw new NotImplementedException(); + + public Task SingleByIdAsync(object primaryKey) => throw new NotImplementedException(); + + public Task SingleOrDefaultByIdAsync(object primaryKey) => throw new NotImplementedException(); + + public Task FirstAsync(string sql, params object[] args) => throw new NotImplementedException(); + + public Task FirstAsync(Sql sql) => throw new NotImplementedException(); + + public Task FirstOrDefaultAsync(string sql, params object[] args) => throw new NotImplementedException(); + + public Task FirstOrDefaultAsync(Sql sql) => throw new NotImplementedException(); + + public Task> QueryAsync(string sql, params object[] args) => throw new NotImplementedException(); + + public Task> QueryAsync(Sql sql) => throw new NotImplementedException(); public IAsyncQueryProviderWithIncludes QueryAsync() => throw new NotImplementedException(); - public Task> FetchAsync(string sql, params object[] args) - { - throw new NotImplementedException(); - } + public Task> FetchAsync(string sql, params object[] args) => throw new NotImplementedException(); - public Task> FetchAsync(Sql sql) - { - throw new NotImplementedException(); - } + public Task> FetchAsync(Sql sql) => throw new NotImplementedException(); - public Task> FetchAsync() - { - throw new NotImplementedException(); - } + public Task> FetchAsync() => throw new NotImplementedException(); - public Task> PageAsync(long page, long itemsPerPage, string sql, params object[] args) - { - throw new NotImplementedException(); - } + public Task> PageAsync(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException(); - public Task> PageAsync(long page, long itemsPerPage, Sql sql) - { - throw new NotImplementedException(); - } + public Task> PageAsync(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException(); - public Task> FetchAsync(long page, long itemsPerPage, string sql, params object[] args) - { - throw new NotImplementedException(); - } + public Task> FetchAsync(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException(); - public Task> FetchAsync(long page, long itemsPerPage, Sql sql) - { - throw new NotImplementedException(); - } + public Task> FetchAsync(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException(); - public Task> SkipTakeAsync(long skip, long take, string sql, params object[] args) - { - throw new NotImplementedException(); - } + public Task> SkipTakeAsync(long skip, long take, string sql, params object[] args) => throw new NotImplementedException(); - public Task> SkipTakeAsync(long skip, long take, Sql sql) - { - throw new NotImplementedException(); - } + public Task> SkipTakeAsync(long skip, long take, Sql sql) => throw new NotImplementedException(); - #endregion - - #region Stuff - - public void BuildPageQueries(long skip, long take, string sql, ref object[] args, out string sqlCount, out string sqlPage) - { - throw new NotImplementedException(); - } - - #endregion + public void BuildPageQueries(long skip, long take, string sql, ref object[] args, out string sqlCount, out string sqlPage) => throw new NotImplementedException(); } } diff --git a/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs b/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs index e5d5d2650e..d0e9fe879f 100644 --- a/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs +++ b/src/Umbraco.Tests.Common/TestHelpers/TestEnvironment.cs @@ -1,4 +1,7 @@ -using System.Runtime.InteropServices; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System.Runtime.InteropServices; namespace Umbraco.Tests.Common.TestHelpers { @@ -6,8 +9,8 @@ namespace Umbraco.Tests.Common.TestHelpers { public static bool IsLinux => RuntimeInformation.IsOSPlatform(OSPlatform.Linux); - public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + public static bool IsWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } } diff --git a/src/Umbraco.Tests.Common/TestPublishedSnapshotAccessor.cs b/src/Umbraco.Tests.Common/TestPublishedSnapshotAccessor.cs index ed1ba0b5b9..6b2bc69e24 100644 --- a/src/Umbraco.Tests.Common/TestPublishedSnapshotAccessor.cs +++ b/src/Umbraco.Tests.Common/TestPublishedSnapshotAccessor.cs @@ -1,4 +1,7 @@ -using Umbraco.Web.PublishedCache; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Web.PublishedCache; namespace Umbraco.Tests.Common { diff --git a/src/Umbraco.Tests.Common/TestUmbracoContextAccessor.cs b/src/Umbraco.Tests.Common/TestUmbracoContextAccessor.cs index feaf8eafa5..3c88765f44 100644 --- a/src/Umbraco.Tests.Common/TestUmbracoContextAccessor.cs +++ b/src/Umbraco.Tests.Common/TestUmbracoContextAccessor.cs @@ -1,4 +1,7 @@ -using Umbraco.Web; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Web; namespace Umbraco.Tests.Common { diff --git a/src/Umbraco.Tests.Common/TestVariationContextAccessor.cs b/src/Umbraco.Tests.Common/TestVariationContextAccessor.cs index b2a07b74f2..c1ff438b8c 100644 --- a/src/Umbraco.Tests.Common/TestVariationContextAccessor.cs +++ b/src/Umbraco.Tests.Common/TestVariationContextAccessor.cs @@ -1,4 +1,7 @@ -using Umbraco.Core.Models.PublishedContent; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using Umbraco.Core.Models.PublishedContent; namespace Umbraco.Tests.Common { diff --git a/src/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs b/src/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs index bbfa68778f..9520532eaa 100644 --- a/src/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs +++ b/src/Umbraco.Tests.Common/Testing/TestOptionAttributeBase.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -14,41 +17,40 @@ namespace Umbraco.Tests.Testing public static TOptions GetTestOptions(MethodInfo method) where TOptions : TestOptionAttributeBase, new() { - var attr = ((TOptions[]) method.GetCustomAttributes(typeof (TOptions), true)).FirstOrDefault(); - var type = method.DeclaringType; + TOptions attr = ((TOptions[])method.GetCustomAttributes(typeof(TOptions), true)).FirstOrDefault(); + Type type = method.DeclaringType; return Get(type, attr); } public static TOptions GetFixtureOptions(Type type) - where TOptions : TestOptionAttributeBase, new() - { - return Get(type, null); - } + where TOptions : TestOptionAttributeBase, new() => Get(type, null); public static TOptions GetTestOptions() where TOptions : TestOptionAttributeBase, new() { - var test = TestContext.CurrentContext.Test; + TestContext.TestAdapter test = TestContext.CurrentContext.Test; var typeName = test.ClassName; var methodName = test.MethodName; - // this will only get types from whatever is already loaded in the app domain + + // This will only get types from whatever is already loaded in the app domain. var type = Type.GetType(typeName, false); if (type == null) { // automatically add the executing and calling assemblies to the list to scan for this type - var scanAssemblies = ScanAssemblies.Union(new[] {Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly()}).ToList(); + var scanAssemblies = ScanAssemblies.Union(new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly() }).ToList(); type = scanAssemblies .Select(assembly => assembly.GetType(typeName, false)) .FirstOrDefault(x => x != null); if (type == null) - { + { throw new PanicException($"Could not resolve the running test fixture from type name {typeName}.\n" + $"To use base classes from Umbraco.Tests, add your test assembly to TestOptionAttributeBase.ScanAssemblies"); } } - var methodInfo = type.GetMethod(methodName); // what about overloads? - var options = GetTestOptions(methodInfo); + + MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads? + TOptions options = GetTestOptions(methodInfo); return options; } @@ -57,26 +59,34 @@ namespace Umbraco.Tests.Testing { while (type != null && type != typeof(object)) { - var attr2 = ((TOptions[]) type.GetCustomAttributes(typeof (TOptions), true)).FirstOrDefault(); + TOptions attr2 = ((TOptions[])type.GetCustomAttributes(typeof(TOptions), true)).FirstOrDefault(); if (attr2 != null) + { attr = attr == null ? attr2 : attr2.Merge(attr); + } + type = type.BaseType; } + return attr ?? new TOptions(); } private TOptions Merge(TOptions other) where TOptions : TestOptionAttributeBase { - if (other == null) throw new ArgumentNullException(nameof(other)); - if (!(Merge((TestOptionAttributeBase) other) is TOptions merged)) + if (other == null) + { + throw new ArgumentNullException(nameof(other)); + } + + if (!(Merge((TestOptionAttributeBase)other) is TOptions merged)) + { throw new PanicException("Could not merge test options"); + } + return merged; } - protected virtual TestOptionAttributeBase Merge(TestOptionAttributeBase other) - { - return this; - } + protected virtual TestOptionAttributeBase Merge(TestOptionAttributeBase other) => this; } } diff --git a/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs b/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs index 4c1101d6f1..b21d8b0614 100644 --- a/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs +++ b/src/Umbraco.Tests.Common/Testing/UmbracoTestAttribute.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) Umbraco. +// See LICENSE for more details. + +using System; using Umbraco.Core; namespace Umbraco.Tests.Testing @@ -15,6 +18,7 @@ namespace Umbraco.Tests.Testing /// Implies Mapper = true (, ResetPluginManager = false). /// public bool WithApplication { get => _withApplication.ValueOrDefault(false); set => _withApplication.Set(value); } + private readonly Settable _withApplication = new Settable(); /// @@ -22,12 +26,14 @@ namespace Umbraco.Tests.Testing /// /// Default is false unless WithApplication is true, in which case default is true. public bool Mapper { get => _mapper.ValueOrDefault(WithApplication); set => _mapper.Set(value); } + private readonly Settable _mapper = new Settable(); /// /// Gets or sets a value indicating whether the LEGACY XML Cache used in tests should bind to repository events /// public bool PublishedRepositoryEvents { get => _publishedRepositoryEvents.ValueOrDefault(false); set => _publishedRepositoryEvents.Set(value); } + private readonly Settable _publishedRepositoryEvents = new Settable(); /// @@ -35,6 +41,7 @@ namespace Umbraco.Tests.Testing /// /// Default is to mock logging. public UmbracoTestOptions.Logger Logger { get => _logger.ValueOrDefault(UmbracoTestOptions.Logger.Mock); set => _logger.Set(value); } + private readonly Settable _logger = new Settable(); /// @@ -42,6 +49,7 @@ namespace Umbraco.Tests.Testing /// /// Default is no database support. public UmbracoTestOptions.Database Database { get => _database.ValueOrDefault(UmbracoTestOptions.Database.None); set => _database.Set(value); } + private readonly Settable _database = new Settable(); /// @@ -49,16 +57,19 @@ namespace Umbraco.Tests.Testing /// /// Default is to use the global tests plugin manager. public UmbracoTestOptions.TypeLoader TypeLoader { get => _typeLoader.ValueOrDefault(UmbracoTestOptions.TypeLoader.Default); set => _typeLoader.Set(value); } - public bool Boot { get => _boot.ValueOrDefault(false); set => _boot.Set(value); } - private readonly Settable _boot = new Settable(); + public bool Boot { get => _boot.ValueOrDefault(false); set => _boot.Set(value); } + + private readonly Settable _boot = new Settable(); private readonly Settable _typeLoader = new Settable(); protected override TestOptionAttributeBase Merge(TestOptionAttributeBase other) { if (!(other is UmbracoTestAttribute attr)) + { throw new ArgumentException(nameof(other)); + } base.Merge(other); _boot.Set(attr.Boot); diff --git a/src/Umbraco.Tests.Common/Testing/UmbracoTestOptions.cs b/src/Umbraco.Tests.Common/Testing/UmbracoTestOptions.cs index eef6e45d7e..477148e300 100644 --- a/src/Umbraco.Tests.Common/Testing/UmbracoTestOptions.cs +++ b/src/Umbraco.Tests.Common/Testing/UmbracoTestOptions.cs @@ -1,4 +1,7 @@ -namespace Umbraco.Tests.Testing +// Copyright (c) Umbraco. +// See LICENSE for more details. + +namespace Umbraco.Tests.Testing { public static class UmbracoTestOptions { @@ -8,10 +11,12 @@ /// pure mocks /// Mock, + /// /// Serilog for tests /// Serilog, + /// /// console logger /// @@ -24,18 +29,22 @@ /// no database /// None, + /// /// new empty database file for the entire fixture /// NewEmptyPerFixture, + /// /// new empty database file per test /// NewEmptyPerTest, + /// /// new database file with schema for the entire fixture /// NewSchemaPerFixture, + /// /// new database file with schema per test /// @@ -48,10 +57,12 @@ /// the default, global type loader for tests /// Default, + /// /// create one type loader for the feature /// PerFixture, + /// /// create one type loader for each test ///