Merge branch 'feature/clean-up-umbraco-tests-common' into netcore/feature/merge-v8-18-01-2021

This commit is contained in:
Bjarke Berg
2021-01-18 10:47:18 +01:00
24 changed files with 541 additions and 861 deletions

View File

@@ -23,7 +23,7 @@ namespace Umbraco.Tests.Common.Builders
public override IConfigurationEditor Build()
{
IDictionary<string, object> defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
IDictionary<string, object> defaultConfiguration = _defaultConfiguration ?? new Dictionary<string, object>();
return new ConfigurationEditor()
{

View File

@@ -220,7 +220,6 @@ namespace Umbraco.Tests.Common.Builders
.WithName(name)
.WithParent(parent);
if (!(culture is null))
{
builder = builder.WithCultureName(culture, name);

View File

@@ -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)
{
}

View File

@@ -23,7 +23,8 @@ namespace Umbraco.Tests.Common.Builders
{
}
public ContentTypeSortBuilder(ContentTypeBuilder parentBuilder) : base(parentBuilder)
public ContentTypeSortBuilder(ContentTypeBuilder parentBuilder)
: base(parentBuilder)
{
}

View File

@@ -48,8 +48,7 @@ namespace Umbraco.Tests.Common.Builders
Mock.Of<ILocalizationService>(),
Mock.Of<ILocalizedTextService>(),
Mock.Of<IShortStringHelper>(),
Mock.Of<IJsonSerializer>()
)
Mock.Of<IJsonSerializer>())
{
DefaultConfiguration = defaultConfiguration,
ExplicitConfigurationEditor = explicitConfigurationEditor,

View File

@@ -58,8 +58,7 @@ namespace Umbraco.Tests.Common.Builders
Mock.Of<ILocalizationService>(),
Mock.Of<ILocalizedTextService>(),
Mock.Of<IShortStringHelper>(),
Mock.Of<IJsonSerializer>()
)
Mock.Of<IJsonSerializer>())
{
Configuration = configuration,
View = view,

View File

@@ -1,3 +1,6 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.
namespace Umbraco.Tests.Common.Builders.Interfaces
{
public interface IWithLoginBuilder

View File

@@ -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);
}
}

View File

@@ -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<string>(Mock.Of<IPublishedValueFallback>(), "prop1");
}
@@ -23,7 +26,8 @@ namespace Umbraco.Tests.Published
{
public TestElementModel2(IPublishedElement content, IPublishedValueFallback fallback)
: base(content)
{ }
{
}
public IEnumerable<TestContentModel1> Prop2 => this.Value<IEnumerable<TestContentModel1>>(Mock.Of<IPublishedValueFallback>(), "prop2");
}
@@ -33,7 +37,8 @@ namespace Umbraco.Tests.Published
{
public TestContentModel1(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
{
}
public string Prop1 => this.Value<string>(Mock.Of<IPublishedValueFallback>(), "prop1");
}
@@ -43,10 +48,10 @@ namespace Umbraco.Tests.Published
{
public TestContentModel2(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
{
}
public IEnumerable<TestContentModel1> Prop2 => this.Value<IEnumerable<TestContentModel1>>(Mock.Of<IPublishedValueFallback>(), "prop2");
}
}
}

View File

@@ -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);
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
@@ -33,8 +31,16 @@ namespace Umbraco.Tests.Common
/// <param name="other">An object to compare with this object.</param>
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
/// <param name="obj">The object to compare with the current object. </param>
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
/// <returns>
/// A hash code for the current object.
/// </returns>
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;
}
}

View File

@@ -1,4 +1,7 @@
using Umbraco.Web.PublishedCache;
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Web.PublishedCache;
namespace Umbraco.Tests.Common
{

View File

@@ -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<ITypeFinder>(), Mock.Of<IAppPolicyCache>(), new DirectoryInfo(GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of<ILogger<TypeLoader>>(), Mock.Of<IProfilingLogger>());
}
public TypeLoader GetMockedTypeLoader() =>
new TypeLoader(Mock.Of<ITypeFinder>(), Mock.Of<IAppPolicyCache>(), new DirectoryInfo(GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of<ILogger<TypeLoader>>(), Mock.Of<IProfilingLogger>());
// public Configs GetConfigs() => GetConfigsFactory().Create();
//// public Configs GetConfigs() => GetConfigsFactory().Create();
public abstract IBackOfficeInfo GetBackOfficeInfo();
//public IConfigsFactory GetConfigsFactory() => new ConfigsFactory();
//// public IConfigsFactory GetConfigsFactory() => new ConfigsFactory();
/// <summary>
/// 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;
}
}
/// <summary>
/// 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
/// </summary>
/// <param name="relativePath"></param>
/// <returns></returns>
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"));
}
}
}

View File

@@ -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<IDataTypeService>(),
@@ -21,9 +24,7 @@ namespace Umbraco.Tests.TestHelpers.Entities
new DataEditorAttribute(name, name, name)
{
ValueType = valueType
}
);
});
}
}
}

View File

@@ -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<bool> callback = null)
{
throw new NotImplementedException();
}
public IDisposable ForcedPreview(bool forcedPreview, Action<bool> 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<IPublishedModelFactory>());
}
public void Clear()
{
_content.Clear();
}
public void Add(SolidPublishedContent content) => _content[content.Id] = content.CreateModel(Mock.Of<IPublishedModelFactory>());
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<IPublishedContent> 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<IPublishedContent> 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<IPublishedContent> 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<IPublishedContent> GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars)
{
throw new NotImplementedException();
}
public override IEnumerable<IPublishedContent> 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<IPublishedContent> 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<IPublishedContent> GetByContentType(IPublishedContentType contentType)
{
throw new NotImplementedException();
}
public override IPublishedContentType GetContentType(Guid key) => throw new NotImplementedException();
public override IEnumerable<IPublishedContent> 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<string, PublishedCultureInfo> _cultures;
private Dictionary<string, PublishedCultureInfo> GetCultures()
{
return new Dictionary<string, PublishedCultureInfo> { { "", new PublishedCultureInfo("", Name, UrlSegment, UpdateDate) } };
}
private Dictionary<string, PublishedCultureInfo> GetCultures() => new Dictionary<string, PublishedCultureInfo> { { 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<string, PublishedCultureInfo> 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<int> ChildIds { get; set; }
public IPublishedContent Parent { get; set; }
public IEnumerable<IPublishedContent> Children { get; set; }
public IEnumerable<IPublishedContent> ChildrenForAllCultures => Children;
#endregion
#region ContentType
public IPublishedContentType ContentType { get; set; }
#endregion
#region Properties
public IEnumerable<IPublishedProperty> 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<int>(Mock.Of<IPublishedValueFallback>(), "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<int>(Mock.Of<IPublishedValueFallback>(), "strongValue");
}
@@ -391,7 +328,8 @@ namespace Umbraco.Tests.Common.PublishedContent
{
public PublishedContentStrong1Sub(IPublishedContent content, IPublishedValueFallback fallback)
: base(content, fallback)
{ }
{
}
public int AnotherValue => this.Value<int>(Mock.Of<IPublishedValueFallback>(), "anotherValue");
}
@@ -400,7 +338,8 @@ namespace Umbraco.Tests.Common.PublishedContent
{
public PublishedContentStrong2(IPublishedContent content, IPublishedValueFallback fallback)
: base(content)
{ }
{
}
public int StrongValue => this.Value<int>(Mock.Of<IPublishedValueFallback>(), "strongValue");
}
@@ -415,9 +354,18 @@ namespace Umbraco.Tests.Common.PublishedContent
var jsonSerializer = new JsonNetSerializer();
var dataTypeServiceMock = new Mock<IDataTypeService>();
var dataType = new DataType(new VoidEditor(Mock.Of<ILoggerFactory>(), dataTypeServiceMock.Object,
Mock.Of<ILocalizationService>(), Mock.Of<ILocalizedTextService>(), Mock.Of<IShortStringHelper>(), jsonSerializer), configurationEditorJsonSerializer)
{ Id = 666 };
var dataType = new DataType(
new VoidEditor(
Mock.Of<ILoggerFactory>(),
dataTypeServiceMock.Object,
Mock.Of<ILocalizationService>(),
Mock.Of<ILocalizedTextService>(),
Mock.Of<IShortStringHelper>(),
jsonSerializer),
configurationEditorJsonSerializer)
{
Id = 666
};
dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield);
var factory = new PublishedContentTypeFactory(Mock.Of<IPublishedModelFactory>(), new PropertyValueConverterCollection(Array.Empty<IPropertyValueConverter>()), dataTypeServiceMock.Object);
@@ -426,23 +374,27 @@ namespace Umbraco.Tests.Common.PublishedContent
public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable<PublishedPropertyType> propertyTypes)
: base(key, id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.Nothing)
{ }
{
}
public AutoPublishedContentType(Guid key, int id, string alias, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> propertyTypes)
: base(key, id, alias, PublishedItemType.Content, Enumerable.Empty<string>(), propertyTypes, ContentVariation.Nothing)
{ }
{
}
public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable<string> compositionAliases, IEnumerable<PublishedPropertyType> propertyTypes)
: base(key, id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.Nothing)
{ }
{
}
public AutoPublishedContentType(Guid key, int id, string alias, IEnumerable<string> compositionAliases, Func<IPublishedContentType, IEnumerable<IPublishedPropertyType>> 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;
}
}

View File

@@ -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 @@
/// <returns>The filtered text.</returns>
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 @@
/// <returns>The filtered text.</returns>
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 @@
/// <returns>The filtered text.</returns>
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

View File

@@ -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);
}
}
}
}

View File

@@ -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
/// </summary>
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;
/// <summary>
/// Gets the operation text.
@@ -79,89 +73,65 @@ namespace Umbraco.Tests.Testing
/// </summary>
public List<Operation> Operations { get; } = new List<Operation>();
#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<IInterceptor> Interceptors { get; }
public string ConnectionString { get; }
public DbConnection Connection { get; }
public DbTransaction Transaction { get; }
public IDictionary<string, object> 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<T>(IEnumerable<T> 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<T> ExecuteScalarAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<T> ExecuteScalarAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<T> ExecuteScalarAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public Task<T> ExecuteScalarAsync<T>(Sql sql) => throw new NotImplementedException();
public Task<int> ExecuteAsync(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<int> ExecuteAsync(string sql, params object[] args) => throw new NotImplementedException();
public Task<int> ExecuteAsync(Sql sql)
{
throw new NotImplementedException();
}
public Task<int> ExecuteAsync(Sql sql) => throw new NotImplementedException();
public object Insert<T>(string tableName, string primaryKeyName, bool autoIncrement, T poco)
{
throw new NotImplementedException();
}
public object Insert<T>(string tableName, string primaryKeyName, bool autoIncrement, T poco) => throw new NotImplementedException();
public object Insert<T>(string tableName, string primaryKeyName, T poco)
{
throw new NotImplementedException();
}
public object Insert<T>(string tableName, string primaryKeyName, T poco) => throw new NotImplementedException();
public object Insert<T>(T poco)
{
throw new NotImplementedException();
}
public object Insert<T>(T poco) => throw new NotImplementedException();
public Task<object> InsertAsync<T>(T poco)
{
throw new NotImplementedException();
}
public Task<object> InsertAsync<T>(T poco) => throw new NotImplementedException();
public Task<int> InsertBatchAsync<T>(IEnumerable<T> pocos, BatchOptions options = null) => throw new NotImplementedException();
public Task<int> UpdateAsync(object poco)
{
throw new NotImplementedException();
}
public Task<int> UpdateAsync(object poco) => throw new NotImplementedException();
public Task<int> UpdateAsync(object poco, IEnumerable<string> columns)
{
throw new NotImplementedException();
}
public Task<int> UpdateAsync(object poco, IEnumerable<string> columns) => throw new NotImplementedException();
public Task<int> UpdateAsync<T>(T poco, Expression<Func<T, object>> fields)
{
throw new NotImplementedException();
}
public Task<int> UpdateAsync<T>(T poco, Expression<Func<T, object>> fields) => throw new NotImplementedException();
public Task<int> UpdateBatchAsync<T>(IEnumerable<UpdateBatch<T>> pocos, BatchOptions options = null) => throw new NotImplementedException();
public Task<int> DeleteAsync(object poco)
{
throw new NotImplementedException();
}
public Task<int> DeleteAsync(object poco) => throw new NotImplementedException();
public IAsyncUpdateQueryProvider<T> UpdateManyAsync<T>() => throw new NotImplementedException();
public IAsyncDeleteQueryProvider<T> DeleteManyAsync<T>() => throw new NotImplementedException();
public void InsertBulk<T>(IEnumerable<T> pocos)
{
throw new NotImplementedException();
}
public void InsertBulk<T>(IEnumerable<T> pocos) => throw new NotImplementedException();
int IDatabase.InsertBatch<T>(IEnumerable<T> pocos, BatchOptions options) => throw new NotImplementedException();
public void InsertBatch<T>(IEnumerable<T> pocos, BatchOptions options = null)
{
throw new NotImplementedException();
}
public void InsertBatch<T>(IEnumerable<T> 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<string> columns)
{
throw new NotImplementedException();
}
public int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable<string> columns) => throw new NotImplementedException();
public int Update(string tableName, string primaryKeyName, object poco, IEnumerable<string> columns)
{
throw new NotImplementedException();
}
public int Update(string tableName, string primaryKeyName, object poco, IEnumerable<string> columns) => throw new NotImplementedException();
public int Update(object poco, IEnumerable<string> columns)
{
throw new NotImplementedException();
}
public int Update(object poco, IEnumerable<string> columns) => throw new NotImplementedException();
public int Update(object poco, object primaryKeyValue, IEnumerable<string> columns)
{
throw new NotImplementedException();
}
public int Update(object poco, object primaryKeyValue, IEnumerable<string> columns) => throw new NotImplementedException();
public int Update(object poco)
{
throw new NotImplementedException();
}
public int Update(object poco) => throw new NotImplementedException();
public int Update<T>(T poco, Expression<Func<T, object>> fields)
{
throw new NotImplementedException();
}
public int Update<T>(T poco, Expression<Func<T, object>> 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<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public int Update<T>(string sql, params object[] args) => throw new NotImplementedException();
public int Update<T>(Sql sql)
{
throw new NotImplementedException();
}
public int Update<T>(Sql sql) => throw new NotImplementedException();
public int UpdateBatch<T>(IEnumerable<UpdateBatch<T>> pocos, BatchOptions options = null) => throw new NotImplementedException();
public IUpdateQueryProvider<T> UpdateMany<T>()
{
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<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public int Delete<T>(Sql sql)
{
throw new NotImplementedException();
}
public int Delete<T>(object pocoOrPrimaryKey)
{
throw new NotImplementedException();
}
public IDeleteQueryProvider<T> DeleteMany<T>()
{
throw new NotImplementedException();
}
public void Save<T>(T poco)
{
throw new NotImplementedException();
}
public bool IsNew<T>(T poco)
{
throw new NotImplementedException();
}
#endregion
#region Reads (not implemented)
public List<object> Fetch(Type type, string sql, params object[] args)
{
throw new NotImplementedException();
}
public List<object> Fetch(Type type, Sql Sql)
{
throw new NotImplementedException();
}
public IEnumerable<object> Query(Type type, string sql, params object[] args)
{
throw new NotImplementedException();
}
public IEnumerable<object> Query(Type type, Sql Sql)
{
throw new NotImplementedException();
}
public List<T> Fetch<T>()
{
throw new NotImplementedException();
}
public List<T> Fetch<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public List<T> Fetch<T>(Sql sql)
{
throw new NotImplementedException();
}
public List<T> Fetch<T>(long page, long itemsPerPage, string sql, params object[] args)
{
throw new NotImplementedException();
}
public List<T> Fetch<T>(long page, long itemsPerPage, Sql sql)
{
throw new NotImplementedException();
}
public Page<T> Page<T>(long page, long itemsPerPage, string sql, params object[] args)
{
throw new NotImplementedException();
}
public Page<T> Page<T>(long page, long itemsPerPage, Sql sql)
{
throw new NotImplementedException();
}
public List<T> SkipTake<T>(long skip, long take, string sql, params object[] args)
{
throw new NotImplementedException();
}
public List<T> SkipTake<T>(long skip, long take, Sql sql)
{
throw new NotImplementedException();
}
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, string sql, params object[] args)
{
throw new NotImplementedException();
}
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, Sql sql)
{
throw new NotImplementedException();
}
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, Func<T, object> idFunc, string sql, params object[] args)
{
throw new NotImplementedException();
}
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, Func<T, object> idFunc, Sql sql)
{
throw new NotImplementedException();
}
public IEnumerable<T> Query<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public IEnumerable<T> Query<T>(Sql sql)
{
throw new NotImplementedException();
}
public IQueryProviderWithIncludes<T> Query<T>()
{
throw new NotImplementedException();
}
public T SingleById<T>(object primaryKey)
{
throw new NotImplementedException();
}
public T Single<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public T SingleInto<T>(T instance, string sql, params object[] args)
{
throw new NotImplementedException();
}
public T SingleOrDefaultById<T>(object primaryKey)
{
throw new NotImplementedException();
}
public T SingleOrDefault<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public T SingleOrDefaultInto<T>(T instance, string sql, params object[] args)
{
throw new NotImplementedException();
}
public T First<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public T FirstInto<T>(T instance, string sql, params object[] args)
{
throw new NotImplementedException();
}
public T FirstOrDefault<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public T FirstOrDefaultInto<T>(T instance, string sql, params object[] args)
{
throw new NotImplementedException();
}
public T Single<T>(Sql sql)
{
throw new NotImplementedException();
}
public T SingleInto<T>(T instance, Sql sql)
{
throw new NotImplementedException();
}
public T SingleOrDefault<T>(Sql sql)
{
throw new NotImplementedException();
}
public T SingleOrDefaultInto<T>(T instance, Sql sql)
{
throw new NotImplementedException();
}
public T First<T>(Sql sql)
{
throw new NotImplementedException();
}
public T FirstInto<T>(T instance, Sql sql)
{
throw new NotImplementedException();
}
public T FirstOrDefault<T>(Sql sql)
{
throw new NotImplementedException();
}
public T FirstOrDefaultInto<T>(T instance, Sql sql)
{
throw new NotImplementedException();
}
public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(Sql Sql)
{
throw new NotImplementedException();
}
public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public bool Exists<T>(object primaryKey)
{
throw new NotImplementedException();
}
public TRet FetchMultiple<T1, T2, TRet>(Func<List<T1>, List<T2>, TRet> cb, string sql, params object[] args)
{
throw new NotImplementedException();
}
public TRet FetchMultiple<T1, T2, T3, TRet>(Func<List<T1>, List<T2>, List<T3>, TRet> cb, string sql, params object[] args)
{
throw new NotImplementedException();
}
public TRet FetchMultiple<T1, T2, T3, T4, TRet>(Func<List<T1>, List<T2>, List<T3>, List<T4>, TRet> cb, string sql, params object[] args)
{
throw new NotImplementedException();
}
public TRet FetchMultiple<T1, T2, TRet>(Func<List<T1>, List<T2>, TRet> cb, Sql sql)
{
throw new NotImplementedException();
}
public TRet FetchMultiple<T1, T2, T3, TRet>(Func<List<T1>, List<T2>, List<T3>, TRet> cb, Sql sql)
{
throw new NotImplementedException();
}
public TRet FetchMultiple<T1, T2, T3, T4, TRet>(Func<List<T1>, List<T2>, List<T3>, List<T4>, TRet> cb, Sql sql)
{
throw new NotImplementedException();
}
public Tuple<List<T1>, List<T2>> FetchMultiple<T1, T2>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Tuple<List<T1>, List<T2>, List<T3>> FetchMultiple<T1, T2, T3>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Tuple<List<T1>, List<T2>, List<T3>, List<T4>> FetchMultiple<T1, T2, T3, T4>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Tuple<List<T1>, List<T2>> FetchMultiple<T1, T2>(Sql sql)
{
throw new NotImplementedException();
}
public Tuple<List<T1>, List<T2>, List<T3>> FetchMultiple<T1, T2, T3>(Sql sql)
{
throw new NotImplementedException();
}
public Tuple<List<T1>, List<T2>, List<T3>, List<T4>> FetchMultiple<T1, T2, T3, T4>(Sql sql)
{
throw new NotImplementedException();
}
public Task<T> SingleAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<T> SingleAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public Task<T> SingleOrDefaultAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<T> SingleOrDefaultAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public Task<T> SingleByIdAsync<T>(object primaryKey)
{
throw new NotImplementedException();
}
public Task<T> SingleOrDefaultByIdAsync<T>(object primaryKey)
{
throw new NotImplementedException();
}
public Task<T> FirstAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<T> FirstAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public Task<T> FirstOrDefaultAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<T> FirstOrDefaultAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public Task<IEnumerable<T>> QueryAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<IEnumerable<T>> QueryAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public IUpdateQueryProvider<T> UpdateMany<T>() => 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<T>(string sql, params object[] args) => throw new NotImplementedException();
public int Delete<T>(Sql sql) => throw new NotImplementedException();
public int Delete<T>(object pocoOrPrimaryKey) => throw new NotImplementedException();
public IDeleteQueryProvider<T> DeleteMany<T>() => throw new NotImplementedException();
public void Save<T>(T poco) => throw new NotImplementedException();
public bool IsNew<T>(T poco) => throw new NotImplementedException();
public List<object> Fetch(Type type, string sql, params object[] args) => throw new NotImplementedException();
public List<object> Fetch(Type type, Sql sql) => throw new NotImplementedException();
public IEnumerable<object> Query(Type type, string sql, params object[] args) => throw new NotImplementedException();
public IEnumerable<object> Query(Type type, Sql sql) => throw new NotImplementedException();
public List<T> Fetch<T>() => throw new NotImplementedException();
public List<T> Fetch<T>(string sql, params object[] args) => throw new NotImplementedException();
public List<T> Fetch<T>(Sql sql) => throw new NotImplementedException();
public List<T> Fetch<T>(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException();
public List<T> Fetch<T>(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException();
public Page<T> Page<T>(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException();
public Page<T> Page<T>(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException();
public List<T> SkipTake<T>(long skip, long take, string sql, params object[] args) => throw new NotImplementedException();
public List<T> SkipTake<T>(long skip, long take, Sql sql) => throw new NotImplementedException();
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, string sql, params object[] args) => throw new NotImplementedException();
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, Sql sql) => throw new NotImplementedException();
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, Func<T, object> idFunc, string sql, params object[] args) => throw new NotImplementedException();
public List<T> FetchOneToMany<T>(Expression<Func<T, IList>> many, Func<T, object> idFunc, Sql sql) => throw new NotImplementedException();
public IEnumerable<T> Query<T>(string sql, params object[] args) => throw new NotImplementedException();
public IEnumerable<T> Query<T>(Sql sql) => throw new NotImplementedException();
public IQueryProviderWithIncludes<T> Query<T>() => throw new NotImplementedException();
public T SingleById<T>(object primaryKey) => throw new NotImplementedException();
public T Single<T>(string sql, params object[] args) => throw new NotImplementedException();
public T SingleInto<T>(T instance, string sql, params object[] args) => throw new NotImplementedException();
public T SingleOrDefaultById<T>(object primaryKey) => throw new NotImplementedException();
public T SingleOrDefault<T>(string sql, params object[] args) => throw new NotImplementedException();
public T SingleOrDefaultInto<T>(T instance, string sql, params object[] args) => throw new NotImplementedException();
public T First<T>(string sql, params object[] args) => throw new NotImplementedException();
public T FirstInto<T>(T instance, string sql, params object[] args) => throw new NotImplementedException();
public T FirstOrDefault<T>(string sql, params object[] args) => throw new NotImplementedException();
public T FirstOrDefaultInto<T>(T instance, string sql, params object[] args) => throw new NotImplementedException();
public T Single<T>(Sql sql) => throw new NotImplementedException();
public T SingleInto<T>(T instance, Sql sql) => throw new NotImplementedException();
public T SingleOrDefault<T>(Sql sql) => throw new NotImplementedException();
public T SingleOrDefaultInto<T>(T instance, Sql sql) => throw new NotImplementedException();
public T First<T>(Sql sql) => throw new NotImplementedException();
public T FirstInto<T>(T instance, Sql sql) => throw new NotImplementedException();
public T FirstOrDefault<T>(Sql sql) => throw new NotImplementedException();
public T FirstOrDefaultInto<T>(T instance, Sql sql) => throw new NotImplementedException();
public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(Sql sql) => throw new NotImplementedException();
public Dictionary<TKey, TValue> Dictionary<TKey, TValue>(string sql, params object[] args) => throw new NotImplementedException();
public bool Exists<T>(object primaryKey) => throw new NotImplementedException();
public TRet FetchMultiple<T1, T2, TRet>(Func<List<T1>, List<T2>, TRet> cb, string sql, params object[] args) => throw new NotImplementedException();
public TRet FetchMultiple<T1, T2, T3, TRet>(Func<List<T1>, List<T2>, List<T3>, TRet> cb, string sql, params object[] args) => throw new NotImplementedException();
public TRet FetchMultiple<T1, T2, T3, T4, TRet>(Func<List<T1>, List<T2>, List<T3>, List<T4>, TRet> cb, string sql, params object[] args) => throw new NotImplementedException();
public TRet FetchMultiple<T1, T2, TRet>(Func<List<T1>, List<T2>, TRet> cb, Sql sql) => throw new NotImplementedException();
public TRet FetchMultiple<T1, T2, T3, TRet>(Func<List<T1>, List<T2>, List<T3>, TRet> cb, Sql sql) => throw new NotImplementedException();
public TRet FetchMultiple<T1, T2, T3, T4, TRet>(Func<List<T1>, List<T2>, List<T3>, List<T4>, TRet> cb, Sql sql) => throw new NotImplementedException();
public Tuple<List<T1>, List<T2>> FetchMultiple<T1, T2>(string sql, params object[] args) => throw new NotImplementedException();
public Tuple<List<T1>, List<T2>, List<T3>> FetchMultiple<T1, T2, T3>(string sql, params object[] args) => throw new NotImplementedException();
public Tuple<List<T1>, List<T2>, List<T3>, List<T4>> FetchMultiple<T1, T2, T3, T4>(string sql, params object[] args) => throw new NotImplementedException();
public Tuple<List<T1>, List<T2>> FetchMultiple<T1, T2>(Sql sql) => throw new NotImplementedException();
public Tuple<List<T1>, List<T2>, List<T3>> FetchMultiple<T1, T2, T3>(Sql sql) => throw new NotImplementedException();
public Tuple<List<T1>, List<T2>, List<T3>, List<T4>> FetchMultiple<T1, T2, T3, T4>(Sql sql) => throw new NotImplementedException();
public Task<T> SingleAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<T> SingleAsync<T>(Sql sql) => throw new NotImplementedException();
public Task<T> SingleOrDefaultAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<T> SingleOrDefaultAsync<T>(Sql sql) => throw new NotImplementedException();
public Task<T> SingleByIdAsync<T>(object primaryKey) => throw new NotImplementedException();
public Task<T> SingleOrDefaultByIdAsync<T>(object primaryKey) => throw new NotImplementedException();
public Task<T> FirstAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<T> FirstAsync<T>(Sql sql) => throw new NotImplementedException();
public Task<T> FirstOrDefaultAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<T> FirstOrDefaultAsync<T>(Sql sql) => throw new NotImplementedException();
public Task<IEnumerable<T>> QueryAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<IEnumerable<T>> QueryAsync<T>(Sql sql) => throw new NotImplementedException();
public IAsyncQueryProviderWithIncludes<T> QueryAsync<T>() => throw new NotImplementedException();
public Task<List<T>> FetchAsync<T>(string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<List<T>> FetchAsync<T>(string sql, params object[] args) => throw new NotImplementedException();
public Task<List<T>> FetchAsync<T>(Sql sql)
{
throw new NotImplementedException();
}
public Task<List<T>> FetchAsync<T>(Sql sql) => throw new NotImplementedException();
public Task<List<T>> FetchAsync<T>()
{
throw new NotImplementedException();
}
public Task<List<T>> FetchAsync<T>() => throw new NotImplementedException();
public Task<Page<T>> PageAsync<T>(long page, long itemsPerPage, string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<Page<T>> PageAsync<T>(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException();
public Task<Page<T>> PageAsync<T>(long page, long itemsPerPage, Sql sql)
{
throw new NotImplementedException();
}
public Task<Page<T>> PageAsync<T>(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException();
public Task<List<T>> FetchAsync<T>(long page, long itemsPerPage, string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<List<T>> FetchAsync<T>(long page, long itemsPerPage, string sql, params object[] args) => throw new NotImplementedException();
public Task<List<T>> FetchAsync<T>(long page, long itemsPerPage, Sql sql)
{
throw new NotImplementedException();
}
public Task<List<T>> FetchAsync<T>(long page, long itemsPerPage, Sql sql) => throw new NotImplementedException();
public Task<List<T>> SkipTakeAsync<T>(long skip, long take, string sql, params object[] args)
{
throw new NotImplementedException();
}
public Task<List<T>> SkipTakeAsync<T>(long skip, long take, string sql, params object[] args) => throw new NotImplementedException();
public Task<List<T>> SkipTakeAsync<T>(long skip, long take, Sql sql)
{
throw new NotImplementedException();
}
public Task<List<T>> SkipTakeAsync<T>(long skip, long take, Sql sql) => throw new NotImplementedException();
#endregion
#region Stuff
public void BuildPageQueries<T>(long skip, long take, string sql, ref object[] args, out string sqlCount, out string sqlPage)
{
throw new NotImplementedException();
}
#endregion
public void BuildPageQueries<T>(long skip, long take, string sql, ref object[] args, out string sqlCount, out string sqlPage) => throw new NotImplementedException();
}
}

View File

@@ -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);
}
}

View File

@@ -1,4 +1,7 @@
using Umbraco.Web.PublishedCache;
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Web.PublishedCache;
namespace Umbraco.Tests.Common
{

View File

@@ -1,4 +1,7 @@
using Umbraco.Web;
// Copyright (c) Umbraco.
// See LICENSE for more details.
using Umbraco.Web;
namespace Umbraco.Tests.Common
{

View File

@@ -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
{

View File

@@ -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<TOptions>(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<TOptions>(Type type)
where TOptions : TestOptionAttributeBase, new()
{
return Get<TOptions>(type, null);
}
where TOptions : TestOptionAttributeBase, new() => Get<TOptions>(type, null);
public static TOptions GetTestOptions<TOptions>()
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<TOptions>(methodInfo);
MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads?
TOptions options = GetTestOptions<TOptions>(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>(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;
}
}

View File

@@ -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
/// <para>Implies Mapper = true (, ResetPluginManager = false).</para>
/// </remarks>
public bool WithApplication { get => _withApplication.ValueOrDefault(false); set => _withApplication.Set(value); }
private readonly Settable<bool> _withApplication = new Settable<bool>();
/// <summary>
@@ -22,12 +26,14 @@ namespace Umbraco.Tests.Testing
/// </summary>
/// <remarks>Default is false unless WithApplication is true, in which case default is true.</remarks>
public bool Mapper { get => _mapper.ValueOrDefault(WithApplication); set => _mapper.Set(value); }
private readonly Settable<bool> _mapper = new Settable<bool>();
/// <summary>
/// Gets or sets a value indicating whether the LEGACY XML Cache used in tests should bind to repository events
/// </summary>
public bool PublishedRepositoryEvents { get => _publishedRepositoryEvents.ValueOrDefault(false); set => _publishedRepositoryEvents.Set(value); }
private readonly Settable<bool> _publishedRepositoryEvents = new Settable<bool>();
/// <summary>
@@ -35,6 +41,7 @@ namespace Umbraco.Tests.Testing
/// </summary>
/// <remarks>Default is to mock logging.</remarks>
public UmbracoTestOptions.Logger Logger { get => _logger.ValueOrDefault(UmbracoTestOptions.Logger.Mock); set => _logger.Set(value); }
private readonly Settable<UmbracoTestOptions.Logger> _logger = new Settable<UmbracoTestOptions.Logger>();
/// <summary>
@@ -42,6 +49,7 @@ namespace Umbraco.Tests.Testing
/// </summary>
/// <remarks>Default is no database support.</remarks>
public UmbracoTestOptions.Database Database { get => _database.ValueOrDefault(UmbracoTestOptions.Database.None); set => _database.Set(value); }
private readonly Settable<UmbracoTestOptions.Database> _database = new Settable<UmbracoTestOptions.Database>();
/// <summary>
@@ -49,16 +57,19 @@ namespace Umbraco.Tests.Testing
/// </summary>
/// <remarks>Default is to use the global tests plugin manager.</remarks>
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<bool> _boot = new Settable<bool>();
public bool Boot { get => _boot.ValueOrDefault(false); set => _boot.Set(value); }
private readonly Settable<bool> _boot = new Settable<bool>();
private readonly Settable<UmbracoTestOptions.TypeLoader> _typeLoader = new Settable<UmbracoTestOptions.TypeLoader>();
protected override TestOptionAttributeBase Merge(TestOptionAttributeBase other)
{
if (!(other is UmbracoTestAttribute attr))
{
throw new ArgumentException(nameof(other));
}
base.Merge(other);
_boot.Set(attr.Boot);

View File

@@ -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
/// </summary>
Mock,
/// <summary>
/// Serilog for tests
/// </summary>
Serilog,
/// <summary>
/// console logger
/// </summary>
@@ -24,18 +29,22 @@
/// no database
/// </summary>
None,
/// <summary>
/// new empty database file for the entire fixture
/// </summary>
NewEmptyPerFixture,
/// <summary>
/// new empty database file per test
/// </summary>
NewEmptyPerTest,
/// <summary>
/// new database file with schema for the entire fixture
/// </summary>
NewSchemaPerFixture,
/// <summary>
/// new database file with schema per test
/// </summary>
@@ -48,10 +57,12 @@
/// the default, global type loader for tests
/// </summary>
Default,
/// <summary>
/// create one type loader for the feature
/// </summary>
PerFixture,
/// <summary>
/// create one type loader for each test
/// </summary>