Port v7@2aa0dfb2c5 - WIP
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NPoco;
|
||||
using StackExchange.Profiling;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.FaultHandling;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.SqlSyntax;
|
||||
|
||||
namespace Umbraco.Core.Persistence
|
||||
{
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Horology;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using Umbraco.Tests.Benchmarks.Config;
|
||||
|
||||
namespace Umbraco.Tests.Benchmarks
|
||||
{
|
||||
|
||||
@@ -3,10 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Horology;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using Moq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -14,6 +10,7 @@ using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Benchmarks.Config;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.Benchmarks
|
||||
|
||||
@@ -146,7 +146,7 @@ namespace Umbraco.Tests.Composing
|
||||
[Test]
|
||||
public void Detect_Legacy_Plugin_File_List()
|
||||
{
|
||||
var filePath = _typeLoader.GeTypesListFilePath();
|
||||
var filePath = TypeLoader.GetTypesListFilePath();
|
||||
var fileDir = Path.GetDirectoryName(filePath);
|
||||
Directory.CreateDirectory(fileDir);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading;
|
||||
using System.Web.UI.WebControls;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Tests.CoreThings
|
||||
{
|
||||
@@ -165,7 +166,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
Assert.AreEqual("Hello world", result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Test]
|
||||
public virtual void CanConvertObjectToSameObject()
|
||||
{
|
||||
var obj = new MyTestObject();
|
||||
@@ -174,6 +175,141 @@ namespace Umbraco.Tests.CoreThings
|
||||
Assert.AreEqual(obj, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertToIntegerTest()
|
||||
{
|
||||
var conv = "100".TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
|
||||
conv = "100.000".TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
|
||||
conv = "100,000".TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
|
||||
// oops
|
||||
conv = "100.001".TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
|
||||
conv = 100m.TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
|
||||
conv = 100.000m.TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
|
||||
// oops
|
||||
conv = 100.001m.TryConvertTo<int>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100, conv.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertToDecimalTest()
|
||||
{
|
||||
var conv = "100".TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = "100.000".TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = "100,000".TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = "100.001".TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100.001m, conv.Result);
|
||||
|
||||
conv = 100m.TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = 100.000m.TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = 100.001m.TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100.001m, conv.Result);
|
||||
|
||||
conv = 100.TryConvertTo<decimal>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertToNullableDecimalTest()
|
||||
{
|
||||
var conv = "100".TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = "100.000".TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = "100,000".TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = "100.001".TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100.001m, conv.Result);
|
||||
|
||||
conv = 100m.TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = 100.000m.TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
|
||||
conv = 100.001m.TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100.001m, conv.Result);
|
||||
|
||||
conv = 100.TryConvertTo<decimal?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(100m, conv.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertToDateTimeTest()
|
||||
{
|
||||
var conv = "2016-06-07".TryConvertTo<DateTime>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(new DateTime(2016, 6, 7), conv.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertToNullableDateTimeTest()
|
||||
{
|
||||
var conv = "2016-06-07".TryConvertTo<DateTime?>();
|
||||
Assert.IsTrue(conv);
|
||||
Assert.AreEqual(new DateTime(2016, 6, 7), conv.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Value_Editor_Can_Convert_Decimal_To_Decimal_Clr_Type()
|
||||
{
|
||||
var valueEditor = new DataValueEditor
|
||||
{
|
||||
ValueType = ValueTypes.Decimal
|
||||
};
|
||||
|
||||
var result = valueEditor.TryConvertValueToCrlType(12.34d);
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(12.34d, result.Result);
|
||||
}
|
||||
|
||||
private class MyTestObject
|
||||
{
|
||||
public override string ToString()
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Umbraco.Tests.CoreThings
|
||||
var container = new Mock<IServiceContainer>();
|
||||
container.Setup(x => x.GetInstance(typeof (TypeLoader))).Returns(new TypeLoader(NullCacheProvider.Instance, new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>())));
|
||||
Current.Container = container.Object;
|
||||
|
||||
Udi.ResetUdiTypes();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
@@ -133,6 +133,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.PropertyTypes.ElementAt(j).DataTypeId);
|
||||
Assert.AreEqual(propTypes.ElementAt(j).MemberCanViewProperty, result.MemberCanViewProperty(result.PropertyTypes.ElementAt(j).Alias));
|
||||
Assert.AreEqual(propTypes.ElementAt(j).MemberCanEditProperty, result.MemberCanEditProperty(result.PropertyTypes.ElementAt(j).Alias));
|
||||
Assert.AreEqual(propTypes.ElementAt(j).IsSensitiveData, result.IsSensitiveProperty(result.PropertyTypes.ElementAt(j).Alias));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
// setup the mocks to return the data we want to test against...
|
||||
|
||||
var memberType = MockedContentTypes.CreateSimpleMemberType();
|
||||
memberType.MemberTypePropertyTypes[memberType.PropertyTypes.Last().Alias] = new MemberTypePropertyProfileAccess(true, true);
|
||||
memberType.MemberTypePropertyTypes[memberType.PropertyTypes.Last().Alias] = new MemberTypePropertyProfileAccess(true, true, true);
|
||||
|
||||
MockedContentTypes.EnsureAllIds(memberType, 8888);
|
||||
|
||||
@@ -470,18 +471,18 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
|
||||
//TODO: Now we need to assert all of the more complicated parts
|
||||
|
||||
Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count());
|
||||
for (var i = 0; i < contentType.PropertyGroups.Count(); i++)
|
||||
Assert.AreEqual(contentType.PropertyGroups.Count, result.Groups.Count());
|
||||
for (var i = 0; i < contentType.PropertyGroups.Count; i++)
|
||||
{
|
||||
Assert.AreEqual(contentType.PropertyGroups.ElementAt(i).Id, result.Groups.ElementAt(i).Id);
|
||||
Assert.AreEqual(contentType.PropertyGroups.ElementAt(i).Name, result.Groups.ElementAt(i).Name);
|
||||
var propTypes = contentType.PropertyGroups.ElementAt(i).PropertyTypes;
|
||||
Assert.AreEqual(contentType.PropertyGroups[i].Id, result.Groups.ElementAt(i).Id);
|
||||
Assert.AreEqual(contentType.PropertyGroups[i].Name, result.Groups.ElementAt(i).Name);
|
||||
var propTypes = contentType.PropertyGroups[i].PropertyTypes;
|
||||
|
||||
Assert.AreEqual(propTypes.Count(), result.Groups.ElementAt(i).Properties.Count());
|
||||
for (var j = 0; j < propTypes.Count(); j++)
|
||||
Assert.AreEqual(propTypes.Count, result.Groups.ElementAt(i).Properties.Count());
|
||||
for (var j = 0; j < propTypes.Count; j++)
|
||||
{
|
||||
Assert.AreEqual(propTypes.ElementAt(j).Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id);
|
||||
Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId);
|
||||
Assert.AreEqual(propTypes[j].Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id);
|
||||
Assert.AreEqual(propTypes[j].DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,6 +517,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
{
|
||||
MemberCanEditProperty = true,
|
||||
MemberCanViewProperty = true,
|
||||
IsSensitiveData = true,
|
||||
Id = 33,
|
||||
SortOrder = 1,
|
||||
Alias = "prop1",
|
||||
@@ -533,6 +535,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
{
|
||||
MemberCanViewProperty = false,
|
||||
MemberCanEditProperty = false,
|
||||
IsSensitiveData = false,
|
||||
Id = 34,
|
||||
SortOrder = 2,
|
||||
Alias = "prop2",
|
||||
@@ -897,6 +900,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
Label = "Prop 1",
|
||||
MemberCanViewProperty = true,
|
||||
MemberCanEditProperty = true,
|
||||
IsSensitiveData = true,
|
||||
Validation = new PropertyTypeValidation()
|
||||
{
|
||||
Mandatory = true,
|
||||
@@ -916,6 +920,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
Assert.AreEqual(basic.Validation, result.Validation);
|
||||
Assert.AreEqual(basic.MemberCanViewProperty, result.MemberCanViewProperty);
|
||||
Assert.AreEqual(basic.MemberCanEditProperty, result.MemberCanEditProperty);
|
||||
Assert.AreEqual(basic.IsSensitiveData, result.IsSensitiveData);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -982,6 +987,7 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
{
|
||||
MemberCanEditProperty = true,
|
||||
MemberCanViewProperty = true,
|
||||
IsSensitiveData = true,
|
||||
Alias = "property1",
|
||||
Description = "this is property 1",
|
||||
Inherited = false,
|
||||
|
||||
@@ -135,6 +135,23 @@ namespace Umbraco.Tests.Models.Mapping
|
||||
Assert.IsTrue(result.Tabs.Except(new[] {result.Tabs.First()}).All(x => x.IsActive == false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void To_Display_Model_No_Tabs()
|
||||
{
|
||||
var contentType = MockedContentTypes.CreateSimpleContentType();
|
||||
contentType.PropertyGroups.Clear();
|
||||
var content = new Content("Home", -1, contentType) { Level = 1, SortOrder = 1, CreatorId = 0, WriterId = 0 };
|
||||
|
||||
var result = Mapper.Map<IContent, ContentItemDisplay>(content);
|
||||
|
||||
AssertBasics(result, content);
|
||||
foreach (var p in content.Properties)
|
||||
{
|
||||
AssertDisplayProperty(result, p);
|
||||
}
|
||||
Assert.AreEqual(content.PropertyGroups.Count(), result.Tabs.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void To_Display_Model_With_Non_Grouped_Properties()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.Scoping;
|
||||
@@ -29,5 +31,95 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
Assert.That(dtos.First().Comment, Is.EqualTo("This is a System audit trail"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Paged_Items()
|
||||
{
|
||||
var sp = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var repo = new AuditRepository((IScopeAccessor) sp, CacheHelper, Logger);
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
repo.Save(new AuditItem(i, $"Content {i} created", AuditType.New, 0));
|
||||
repo.Save(new AuditItem(i, $"Content {i} published", AuditType.Publish, 0));
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var repo = new AuditRepository((IScopeAccessor) sp, CacheHelper, Logger);
|
||||
|
||||
var page = repo.GetPagedResultsByQuery(sp.SqlContext.Query<IAuditItem>(), 0, 10, out var total, Direction.Descending, null, null);
|
||||
|
||||
Assert.AreEqual(10, page.Count());
|
||||
Assert.AreEqual(200, total);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Paged_Items_With_AuditType_Filter()
|
||||
{
|
||||
var sp = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var repo = new AuditRepository((IScopeAccessor) sp, CacheHelper, Logger);
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
repo.Save(new AuditItem(i, $"Content {i} created", AuditType.New, 0));
|
||||
repo.Save(new AuditItem(i, $"Content {i} published", AuditType.Publish, 0));
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var repo = new AuditRepository((IScopeAccessor) sp, CacheHelper, Logger);
|
||||
|
||||
var page = repo.GetPagedResultsByQuery(sp.SqlContext.Query<IAuditItem>(), 0, 9, out var total, Direction.Descending,
|
||||
new[] {AuditType.Publish}, null)
|
||||
.ToArray();
|
||||
|
||||
Assert.AreEqual(9, page.Length);
|
||||
Assert.IsTrue(page.All(x => x.AuditType == AuditType.Publish));
|
||||
Assert.AreEqual(100, total);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Paged_Items_With_Custom_Filter()
|
||||
{
|
||||
var sp = TestObjects.GetScopeProvider(Logger);
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var repo = new AuditRepository((IScopeAccessor) sp, CacheHelper, Logger);
|
||||
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
repo.Save(new AuditItem(i, "Content created", AuditType.New, 0));
|
||||
repo.Save(new AuditItem(i, "Content published", AuditType.Publish, 0));
|
||||
}
|
||||
|
||||
scope.Complete();
|
||||
}
|
||||
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var repo = new AuditRepository((IScopeAccessor) sp, CacheHelper, Logger);
|
||||
|
||||
var page = repo.GetPagedResultsByQuery(sp.SqlContext.Query<IAuditItem>(), 0, 8, out var total, Direction.Descending,
|
||||
null, sp.SqlContext.Query<IAuditItem>().Where(item => item.Comment == "Content created"))
|
||||
.ToArray();
|
||||
|
||||
Assert.AreEqual(8, page.Length);
|
||||
Assert.IsTrue(page.All(x => x.Comment == "Content created"));
|
||||
Assert.AreEqual(100, total);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +313,9 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
|
||||
Assert.AreEqual(4, contentType.PropertyTypes.Count());
|
||||
|
||||
// remove all templates - since they are not saved, they would break the (wtf) mapping code
|
||||
contentType.AllowedTemplates = new ITemplate[0];
|
||||
|
||||
// there is NO mapping from display to contentType, but only from save
|
||||
// to contentType, so if we want to test, let's to it properly!
|
||||
var display = Mapper.Map<DocumentTypeDisplay>(contentType);
|
||||
|
||||
@@ -21,6 +21,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[TestCase("Alpha (10)", "Alpha (2)", +1)] // this is the real stuff
|
||||
[TestCase("Kilo", "Golf (2)", +1)]
|
||||
[TestCase("Kilo (1)", "Golf (2)", +1)]
|
||||
[TestCase("", "", 0)]
|
||||
[TestCase(null, null, 0)]
|
||||
public void ComparerTest(string name1, string name2, int expected)
|
||||
{
|
||||
var comparer = new SimilarNodeName.Comparer();
|
||||
@@ -73,6 +75,8 @@ namespace Umbraco.Tests.Persistence.Repositories
|
||||
[TestCase(0, "Alpha", "Alpha (3)")]
|
||||
[TestCase(0, "Kilo (1)", "Kilo (1) (1)")] // though... we might consider "Kilo (2)"
|
||||
[TestCase(6, "Kilo (1)", "Kilo (1)")] // because of the id
|
||||
[TestCase(0, "", " (1)")]
|
||||
[TestCase(0, null, " (1)")]
|
||||
public void Test(int nodeId, string nodeName, string expected)
|
||||
{
|
||||
var names = new[]
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
public void Only_Tests_On_JArray()
|
||||
{
|
||||
var validator = new ColorPickerConfigurationEditor.ColorListValidator();
|
||||
var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(0, result.Count());
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
public void Only_Tests_On_JArray_Of_Item_JObject()
|
||||
{
|
||||
var validator = new ColorPickerConfigurationEditor.ColorListValidator();
|
||||
var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(0, result.Count());
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
JObject.FromObject(new { value = "zxcvzxcvxzcv" }),
|
||||
JObject.FromObject(new { value = "ABC" }),
|
||||
JObject.FromObject(new { value = "1234567" })),
|
||||
null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(2, result.Count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
public void Only_Tests_On_JArray()
|
||||
{
|
||||
var validator = new ValueListUniqueValueValidator();
|
||||
var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
var result = validator.Validate("hello", null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(0, result.Count());
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
public void Only_Tests_On_JArray_Of_Item_JObject()
|
||||
{
|
||||
var validator = new ValueListUniqueValueValidator();
|
||||
var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
var result = validator.Validate(new JArray("hello", "world"), null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(0, result.Count());
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
public void Allows_Unique_Values()
|
||||
{
|
||||
var validator = new ValueListUniqueValueValidator();
|
||||
var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" })), null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "world" })), null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(0, result.Count());
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
{
|
||||
var validator = new ValueListUniqueValueValidator();
|
||||
var result = validator.Validate(new JArray(JObject.FromObject(new { value = "hello" }), JObject.FromObject(new { value = "hello" })),
|
||||
null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(1, result.Count());
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
JObject.FromObject(new { value = "hello" }),
|
||||
JObject.FromObject(new { value = "world" }),
|
||||
JObject.FromObject(new { value = "world" })),
|
||||
null, new ColorPickerPropertyEditor(Mock.Of<ILogger>(), Mock.Of<ILocalizedTextService>()));
|
||||
null, new ColorPickerPropertyEditor(Mock.Of<ILogger>()));
|
||||
Assert.AreEqual(2, result.Count());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +95,14 @@ namespace Umbraco.Tests.Routing
|
||||
Assert.AreEqual(assert, result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void Is_Client_Side_Request_InvalidPath_ReturnFalse()
|
||||
{
|
||||
//This url is invalid. Default to false when the extension cannot be determined
|
||||
var uri = new Uri("http://test.com/installing-modules+foobar+\"yipee\"");
|
||||
var result = uri.IsClientSideRequest();
|
||||
Assert.AreEqual(false, result);
|
||||
}
|
||||
|
||||
//NOTE: This test shows how we can test most of the HttpModule, it however is testing a method that no longer exists and is testing too much,
|
||||
// we need to write unit tests for each of the components: NiceUrlProvider, all of the Lookup classes, etc...
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Collections;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -12,6 +14,7 @@ using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Tests.Scoping
|
||||
{
|
||||
@@ -139,7 +142,7 @@ namespace Umbraco.Tests.Scoping
|
||||
|
||||
//content1 will be filtered from the args
|
||||
scope.Events.Dispatch(DoSaveForContent, this, new SaveEventArgs<IContent>(new[]{ content1 , content3}));
|
||||
scope.Events.Dispatch(DoDeleteForContent, this, new DeleteEventArgs<IContent>(content1));
|
||||
scope.Events.Dispatch(DoDeleteForContent, this, new DeleteEventArgs<IContent>(content1), "DoDeleteForContent");
|
||||
scope.Events.Dispatch(DoSaveForContent, this, new SaveEventArgs<IContent>(content2));
|
||||
//this entire event will be filtered
|
||||
scope.Events.Dispatch(DoForTestArgs, this, new TestEventArgs(content1));
|
||||
@@ -163,6 +166,24 @@ namespace Umbraco.Tests.Scoping
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupersededEvents2()
|
||||
{
|
||||
var contentService = Mock.Of<IContentService>();
|
||||
var content = Mock.Of<IContent>();
|
||||
|
||||
var scopeProvider = _testObjects.GetScopeProvider(Mock.Of<ILogger>());
|
||||
using (var scope = scopeProvider.CreateScope(eventDispatcher: new PassiveEventDispatcher()))
|
||||
{
|
||||
scope.Events.Dispatch(Test_UnPublished, contentService, new PublishEventArgs<IContent>(new [] { content }), "UnPublished");
|
||||
scope.Events.Dispatch(Test_Deleted, contentService, new DeleteEventArgs<IContent>(new [] { content }), "Deleted");
|
||||
|
||||
// see U4-10764
|
||||
var events = scope.Events.GetEvents(EventDefinitionFilter.All).ToArray();
|
||||
Assert.AreEqual(2, events.Length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This will test that when we track events that before we Get the events we normalize all of the
|
||||
/// event entities to be the latest one (most current) found amongst the event so that there is
|
||||
@@ -371,6 +392,9 @@ namespace Umbraco.Tests.Scoping
|
||||
|
||||
public static event TypedEventHandler<ScopeEventDispatcherTests, SaveEventArgs<decimal>> DoThing3;
|
||||
|
||||
public static event TypedEventHandler<IContentService, PublishEventArgs<IContent>> Test_UnPublished;
|
||||
public static event TypedEventHandler<IContentService, DeleteEventArgs<IContent>> Test_Deleted;
|
||||
|
||||
public class TestEventArgs : CancellableObjectEventArgs
|
||||
{
|
||||
public TestEventArgs(object eventObject) : base(eventObject)
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Umbraco.Tests.Security
|
||||
public void Create_From_Claims_Identity()
|
||||
{
|
||||
var sessionId = Guid.NewGuid().ToString();
|
||||
var securityStamp = Guid.NewGuid().ToString();
|
||||
var claimsIdentity = new ClaimsIdentity(new[]
|
||||
{
|
||||
//This is the id that 'identity' uses to check for the user id
|
||||
@@ -36,12 +37,14 @@ namespace Umbraco.Tests.Security
|
||||
new Claim(ClaimTypes.Locality, "en-us", ClaimValueTypes.String, TestIssuer, TestIssuer),
|
||||
new Claim(Constants.Security.SessionIdClaimType, sessionId, Constants.Security.SessionIdClaimType, TestIssuer, TestIssuer),
|
||||
new Claim(ClaimsIdentity.DefaultRoleClaimType, "admin", ClaimValueTypes.String, TestIssuer, TestIssuer),
|
||||
new Claim(Microsoft.AspNet.Identity.Constants.DefaultSecurityStampClaimType, securityStamp, ClaimValueTypes.String, TestIssuer, TestIssuer),
|
||||
});
|
||||
|
||||
var backofficeIdentity = UmbracoBackOfficeIdentity.FromClaimsIdentity(claimsIdentity);
|
||||
|
||||
Assert.AreEqual("1234", backofficeIdentity.Id);
|
||||
Assert.AreEqual(sessionId, backofficeIdentity.SessionId);
|
||||
Assert.AreEqual(securityStamp, backofficeIdentity.SecurityStamp);
|
||||
Assert.AreEqual("testing", backofficeIdentity.Username);
|
||||
Assert.AreEqual("hello world", backofficeIdentity.RealName);
|
||||
Assert.AreEqual(1, backofficeIdentity.StartContentNodes.Length);
|
||||
@@ -50,7 +53,7 @@ namespace Umbraco.Tests.Security
|
||||
Assert.AreEqual("en-us", backofficeIdentity.Culture);
|
||||
Assert.IsTrue(new[] { "admin" }.SequenceEqual(backofficeIdentity.Roles));
|
||||
|
||||
Assert.AreEqual(10, backofficeIdentity.Claims.Count());
|
||||
Assert.AreEqual(11, backofficeIdentity.Claims.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -93,6 +96,7 @@ namespace Umbraco.Tests.Security
|
||||
var sessionId = Guid.NewGuid().ToString();
|
||||
var userData = new UserData(sessionId)
|
||||
{
|
||||
SecurityStamp = sessionId,
|
||||
AllowedApplications = new[] {"content", "media"},
|
||||
Culture = "en-us",
|
||||
Id = 1234,
|
||||
@@ -113,6 +117,7 @@ namespace Umbraco.Tests.Security
|
||||
var sessionId = Guid.NewGuid().ToString();
|
||||
var userData = new UserData(sessionId)
|
||||
{
|
||||
SecurityStamp = sessionId,
|
||||
AllowedApplications = new[] { "content", "media" },
|
||||
Culture = "en-us",
|
||||
Id = 1234,
|
||||
@@ -139,6 +144,7 @@ namespace Umbraco.Tests.Security
|
||||
var sessionId = Guid.NewGuid().ToString();
|
||||
var userData = new UserData(sessionId)
|
||||
{
|
||||
SecurityStamp = sessionId,
|
||||
AllowedApplications = new[] { "content", "media" },
|
||||
Culture = "en-us",
|
||||
Id = 1234,
|
||||
@@ -162,6 +168,7 @@ namespace Umbraco.Tests.Security
|
||||
var sessionId = Guid.NewGuid().ToString();
|
||||
var userData = new UserData(sessionId)
|
||||
{
|
||||
SecurityStamp = sessionId,
|
||||
AllowedApplications = new[] { "content", "media" },
|
||||
Culture = "en-us",
|
||||
Id = 1234,
|
||||
|
||||
52
src/Umbraco.Tests/Services/AuditServiceTests.cs
Normal file
52
src/Umbraco.Tests/Services/AuditServiceTests.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Services.Implement;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class AuditServiceTests : TestWithDatabaseBase
|
||||
{
|
||||
[Test]
|
||||
public void CanCrudAuditEntry()
|
||||
{
|
||||
var yesterday = DateTime.UtcNow.AddDays(-1);
|
||||
var entry = ServiceContext.AuditService.Write(123, "user 123, bob@example.com", null, yesterday, 456, "user 456, alice@example.com", "umbraco/user", "change property whatever value");
|
||||
Assert.AreEqual(123, entry.PerformingUserId);
|
||||
Assert.AreEqual("user 123, bob@example.com", entry.PerformingDetails);
|
||||
Assert.AreEqual(yesterday, entry.EventDateUtc);
|
||||
Assert.AreEqual(456, entry.AffectedUserId);
|
||||
Assert.AreEqual("user 456, alice@example.com", entry.AffectedDetails);
|
||||
Assert.AreEqual("umbraco/user", entry.EventType);
|
||||
Assert.AreEqual("change property whatever value", entry.EventDetails);
|
||||
|
||||
var entries = ((AuditService)ServiceContext.AuditService).GetAll().ToArray();
|
||||
Assert.IsNotNull(entries);
|
||||
Assert.AreEqual(1, entries.Length);
|
||||
Assert.AreEqual(123, entries[0].PerformingUserId);
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
yesterday = yesterday.AddMinutes(1);
|
||||
entry = ServiceContext.AuditService.Write(123 + i, "user 123, bob@example.com", null, yesterday, 456 + i, "user 456, alice@example.com", "umbraco/user", "change property whatever value");
|
||||
}
|
||||
|
||||
//
|
||||
// page 0 contains 123+9, 123+8
|
||||
// page 1 contains 123+7, 123+6
|
||||
// page 2 contains 123+5, 123+4
|
||||
// ...
|
||||
|
||||
entries = ((AuditService)ServiceContext.AuditService).GetPage(2, 2, out var count).ToArray();
|
||||
|
||||
Assert.AreEqual(2, entries.Length);
|
||||
|
||||
Assert.AreEqual(123 + 5, entries[0].PerformingUserId);
|
||||
Assert.AreEqual(123 + 4, entries[1].PerformingUserId);
|
||||
}
|
||||
}
|
||||
}
|
||||
109
src/Umbraco.Tests/Services/ConsentServiceTests.cs
Normal file
109
src/Umbraco.Tests/Services/ConsentServiceTests.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
||||
public class ConsentServiceTests : TestWithDatabaseBase
|
||||
{
|
||||
[Test]
|
||||
public void CanCrudConsent()
|
||||
{
|
||||
var consentService = ServiceContext.ConsentService;
|
||||
|
||||
// can register
|
||||
|
||||
var consent = consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted, "no comment");
|
||||
Assert.AreNotEqual(0, consent.Id);
|
||||
|
||||
Assert.IsTrue(consent.Current);
|
||||
Assert.AreEqual("user/1234", consent.Source);
|
||||
Assert.AreEqual("app1", consent.Context);
|
||||
Assert.AreEqual("do-something", consent.Action);
|
||||
Assert.AreEqual(ConsentState.Granted, consent.State);
|
||||
Assert.AreEqual("no comment", consent.Comment);
|
||||
|
||||
Assert.IsTrue(consent.IsGranted());
|
||||
|
||||
// can register more
|
||||
|
||||
consentService.RegisterConsent("user/1234", "app1", "do-something-else", ConsentState.Granted, "no comment");
|
||||
consentService.RegisterConsent("user/1236", "app1", "do-something", ConsentState.Granted, "no comment");
|
||||
consentService.RegisterConsent("user/1237", "app2", "do-something", ConsentState.Granted, "no comment");
|
||||
|
||||
// can get by source
|
||||
|
||||
var consents = consentService.LookupConsent(source: "user/1235").ToArray();
|
||||
Assert.IsEmpty(consents);
|
||||
|
||||
consents = consentService.LookupConsent(source: "user/1234").ToArray();
|
||||
Assert.AreEqual(2, consents.Length);
|
||||
Assert.IsTrue(consents.All(x => x.Source == "user/1234"));
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something"));
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something-else"));
|
||||
|
||||
// can get by context
|
||||
|
||||
consents = consentService.LookupConsent(context: "app3").ToArray();
|
||||
Assert.IsEmpty(consents);
|
||||
|
||||
consents = consentService.LookupConsent(context: "app2").ToArray();
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
|
||||
consents = consentService.LookupConsent(context: "app1").ToArray();
|
||||
Assert.AreEqual(3, consents.Length);
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something"));
|
||||
Assert.IsTrue(consents.Any(x => x.Action == "do-something-else"));
|
||||
|
||||
// can get by action
|
||||
|
||||
consents = consentService.LookupConsent(action: "do-whatever").ToArray();
|
||||
Assert.IsEmpty(consents);
|
||||
|
||||
consents = consentService.LookupConsent(context: "app1", action: "do-something").ToArray();
|
||||
Assert.AreEqual(2, consents.Length);
|
||||
Assert.IsTrue(consents.All(x => x.Action == "do-something"));
|
||||
Assert.IsTrue(consents.Any(x => x.Source == "user/1234"));
|
||||
Assert.IsTrue(consents.Any(x => x.Source == "user/1236"));
|
||||
|
||||
// can revoke
|
||||
|
||||
consent = consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Revoked, "no comment");
|
||||
|
||||
consents = consentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something").ToArray();
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
Assert.IsTrue(consents[0].Current);
|
||||
Assert.AreEqual(ConsentState.Revoked, consents[0].State);
|
||||
|
||||
// can filter
|
||||
|
||||
consents = consentService.LookupConsent(context: "app1", action: "do-", actionStartsWith: true).ToArray();
|
||||
Assert.AreEqual(3, consents.Length);
|
||||
Assert.IsTrue(consents.All(x => x.Context == "app1"));
|
||||
Assert.IsTrue(consents.All(x => x.Action.StartsWith("do-")));
|
||||
|
||||
// can get history
|
||||
|
||||
consents = consentService.LookupConsent(source: "user/1234", context: "app1", action: "do-something", includeHistory: true).ToArray();
|
||||
Assert.AreEqual(1, consents.Length);
|
||||
Assert.IsTrue(consents[0].Current);
|
||||
Assert.AreEqual(ConsentState.Revoked, consents[0].State);
|
||||
Assert.IsTrue(consents[0].IsRevoked());
|
||||
Assert.IsNotNull(consents[0].History);
|
||||
var history = consents[0].History.ToArray();
|
||||
Assert.AreEqual(1, history.Length);
|
||||
Assert.IsFalse(history[0].Current);
|
||||
Assert.AreEqual(ConsentState.Granted, history[0].State);
|
||||
|
||||
// cannot be stupid
|
||||
|
||||
Assert.Throws<ArgumentException>(() =>
|
||||
consentService.RegisterConsent("user/1234", "app1", "do-something", ConsentState.Granted | ConsentState.Revoked, "no comment"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -529,6 +529,16 @@ namespace Umbraco.Tests.Services
|
||||
Assert.AreEqual(mediaObjectType, UmbracoObjectTypes.MediaType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Key_For_Id_With_Unknown_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result = service.GetKey(1060, UmbracoObjectTypes.Unknown);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Key_For_Id()
|
||||
{
|
||||
@@ -550,6 +560,16 @@ namespace Umbraco.Tests.Services
|
||||
Assert.IsFalse(result2.Success);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Id_For_Key_With_Unknown_Type()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var result = service.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"), UmbracoObjectTypes.Unknown);
|
||||
|
||||
Assert.IsTrue(result.Success);
|
||||
Assert.AreEqual(1060, result.Result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EntityService_Can_Get_Id_For_Key()
|
||||
{
|
||||
@@ -571,6 +591,30 @@ namespace Umbraco.Tests.Services
|
||||
Assert.IsFalse(result2.Success);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReserveId()
|
||||
{
|
||||
var service = ServiceContext.EntityService;
|
||||
var guid = Guid.NewGuid();
|
||||
|
||||
// can reserve
|
||||
var reservedId = service.ReserveId(guid);
|
||||
Assert.IsTrue(reservedId > 0);
|
||||
|
||||
// can get it back
|
||||
var id = service.GetId(guid, UmbracoObjectTypes.DocumentType);
|
||||
Assert.IsTrue(id.Success);
|
||||
Assert.AreEqual(reservedId, id.Result);
|
||||
|
||||
// anything goes
|
||||
id = service.GetId(guid, UmbracoObjectTypes.Media);
|
||||
Assert.IsTrue(id.Success);
|
||||
Assert.AreEqual(reservedId, id.Result);
|
||||
|
||||
// a random guid won't work
|
||||
Assert.IsFalse(service.GetId(Guid.NewGuid(), UmbracoObjectTypes.DocumentType).Success);
|
||||
}
|
||||
|
||||
private static bool _isSetup = false;
|
||||
|
||||
private int folderId;
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Umbraco.Tests.Strings
|
||||
Assert.IsTrue(foo.IsValid("futureTLD@somewhere.fooo"));
|
||||
|
||||
Assert.IsTrue(foo.IsValid("abc@xyz.financial"));
|
||||
Assert.IsTrue(foo.IsValid("admin+gmail-syntax@c.pizza"));
|
||||
Assert.IsTrue(foo.IsValid("admin@c.pizza"));
|
||||
|
||||
Assert.IsFalse(foo.IsValid("fdsa"));
|
||||
Assert.IsFalse(foo.IsValid("fdsa@"));
|
||||
|
||||
@@ -24,9 +24,11 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
{
|
||||
protected override Task<AuthenticationTicket> AuthenticateCoreAsync()
|
||||
{
|
||||
var sessionId = Guid.NewGuid().ToString();
|
||||
var identity = new UmbracoBackOfficeIdentity(
|
||||
new UserData(Guid.NewGuid().ToString())
|
||||
new UserData(sessionId)
|
||||
{
|
||||
SecurityStamp = sessionId,
|
||||
Id = 0,
|
||||
Roles = new[] { "admin" },
|
||||
AllowedApplications = new[] { "content", "media", "members" },
|
||||
|
||||
@@ -51,12 +51,20 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
var mockedContentService = Mock.Of<IContentService>();
|
||||
var mockedMediaService = Mock.Of<IMediaService>();
|
||||
var mockedEntityService = Mock.Of<IEntityService>();
|
||||
var mockedMemberService = Mock.Of<IMemberService>();
|
||||
var mockedMemberTypeService = Mock.Of<IMemberTypeService>();
|
||||
var mockedDataTypeService = Mock.Of<IDataTypeService>();
|
||||
var mockedContentTypeService = Mock.Of<IContentTypeService>();
|
||||
|
||||
var serviceContext = new ServiceContext(
|
||||
userService: mockedUserService,
|
||||
contentService: mockedContentService,
|
||||
mediaService: mockedMediaService,
|
||||
entityService: mockedEntityService,
|
||||
memberService: mockedMemberService,
|
||||
memberTypeService: mockedMemberTypeService,
|
||||
dataTypeService: mockedDataTypeService,
|
||||
contentTypeService: mockedContentTypeService,
|
||||
localizedTextService:Mock.Of<ILocalizedTextService>(),
|
||||
sectionService:Mock.Of<ISectionService>());
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var publicAccessService = GetLazyService<IPublicAccessService>(container, c => new PublicAccessService(scopeProvider, logger, eventMessagesFactory, GetRepo<IPublicAccessRepository>(c)));
|
||||
var taskService = GetLazyService<ITaskService>(container, c => new TaskService(scopeProvider, logger, eventMessagesFactory, GetRepo<ITaskTypeRepository>(c), GetRepo<ITaskRepository>(c)));
|
||||
var domainService = GetLazyService<IDomainService>(container, c => new DomainService(scopeProvider, logger, eventMessagesFactory, GetRepo<IDomainRepository>(c)));
|
||||
var auditService = GetLazyService<IAuditService>(container, c => new AuditService(scopeProvider, logger, eventMessagesFactory, GetRepo<IAuditRepository>(c)));
|
||||
var auditService = GetLazyService<IAuditService>(container, c => new AuditService(scopeProvider, logger, eventMessagesFactory, GetRepo<IAuditRepository>(c), GetRepo<IAuditEntryRepository>(c)));
|
||||
|
||||
var localizedTextService = GetLazyService<ILocalizedTextService>(container, c => new LocalizedTextService(
|
||||
new Lazy<LocalizedTextServiceFileSources>(() =>
|
||||
@@ -183,6 +183,7 @@ namespace Umbraco.Tests.TestHelpers
|
||||
var tagService = GetLazyService<ITagService>(container, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo<ITagRepository>(c)));
|
||||
var sectionService = GetLazyService<ISectionService>(container, c => new SectionService(userService.Value, treeService.Value, scopeProvider, cache));
|
||||
var redirectUrlService = GetLazyService<IRedirectUrlService>(container, c => new RedirectUrlService(scopeProvider, logger, eventMessagesFactory, GetRepo<IRedirectUrlRepository>(c)));
|
||||
var consentService = GetLazyService<IConsentService>(container, c => new ConsentService(scopeProvider, logger, eventMessagesFactory, GetRepo<IConsentRepository>(c)));
|
||||
|
||||
return new ServiceContext(
|
||||
publicAccessService,
|
||||
@@ -211,7 +212,8 @@ namespace Umbraco.Tests.TestHelpers
|
||||
memberGroupService,
|
||||
notificationService,
|
||||
externalLoginService,
|
||||
redirectUrlService);
|
||||
redirectUrlService,
|
||||
consentService);
|
||||
}
|
||||
|
||||
private Lazy<T> GetLazyService<T>(IServiceFactory container, Func<IServiceFactory, T> ctor)
|
||||
|
||||
@@ -257,7 +257,9 @@
|
||||
<Compile Include="Scoping\ScopeFileSystemsTests.cs" />
|
||||
<Compile Include="Scoping\ScopedNuCacheTests.cs" />
|
||||
<Compile Include="Scoping\ScopeTests.cs" />
|
||||
<Compile Include="Services\AuditServiceTests.cs" />
|
||||
<Compile Include="Services\CachedDataTypeServiceTests.cs" />
|
||||
<Compile Include="Services\ConsentServiceTests.cs" />
|
||||
<Compile Include="Services\SectionServiceTests.cs" />
|
||||
<Compile Include="TestHelpers\ConsoleLogger.cs" />
|
||||
<Compile Include="TestHelpers\ControllerTesting\AuthenticateEverythingExtensions.cs" />
|
||||
|
||||
@@ -20,6 +20,7 @@ using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Editors;
|
||||
using Umbraco.Web.Features;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
|
||||
@@ -40,6 +41,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
|
||||
// kill the true IEntityService too
|
||||
Container.RegisterSingleton(f => Mock.Of<IEntityService>());
|
||||
|
||||
Container.RegisterSingleton<UmbracoFeatures>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -22,5 +22,40 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
var expected = "<div><h1>hello world</h1><p>hello world<br />hello world<br />hello world<br />hello world</p></div>";
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TruncateWithElipsis()
|
||||
{
|
||||
var output = _htmlStringUtilities.Truncate("hello world", 5, true, false).ToString();
|
||||
var expected = "hello…";
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TruncateWithoutElipsis()
|
||||
{
|
||||
var output = _htmlStringUtilities.Truncate("hello world", 5, false, false).ToString();
|
||||
var expected = "hello";
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TruncateShorterWordThanHellip()
|
||||
{
|
||||
//http://issues.umbraco.org/issue/U4-10478
|
||||
var output = _htmlStringUtilities.Truncate("hi", 5, true, false).ToString();
|
||||
var expected = "hi";
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TruncateAndRemoveSpaceBetweenHellipAndWord()
|
||||
{
|
||||
var output = _htmlStringUtilities.Truncate("hello world", 6 /* hello plus space */, true, false).ToString();
|
||||
var expected = "hello…";
|
||||
Assert.AreEqual(expected, output);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Returns_Binder_For_IPublishedContent_And_IRenderModel()
|
||||
{
|
||||
var binder = new ContentModelBinder();
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var found = binder.GetBinder(typeof (IPublishedContent));
|
||||
Assert.IsNotNull(found);
|
||||
found = binder.GetBinder(typeof(ContentModel));
|
||||
@@ -92,7 +92,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void No_DataToken_Returns_Null()
|
||||
{
|
||||
var binder = new ContentModelBinder();
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var routeData = new RouteData();
|
||||
var result = binder.BindModel(new ControllerContext(Mock.Of<HttpContextBase>(), routeData, Mock.Of<ControllerBase>()),
|
||||
new ModelBindingContext());
|
||||
@@ -103,7 +103,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
[Test]
|
||||
public void Invalid_DataToken_Model_Type_Returns_Null()
|
||||
{
|
||||
var binder = new ContentModelBinder();
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var routeData = new RouteData();
|
||||
routeData.DataTokens[Core.Constants.Web.UmbracoDataToken] = "hello";
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public void IPublishedContent_DataToken_Model_Type_Uses_DefaultImplementation()
|
||||
{
|
||||
var content = new MyContent(Mock.Of<IPublishedContent>());
|
||||
var binder = new ContentModelBinder();
|
||||
var binder = ContentModelBinder.Instance;
|
||||
var routeData = new RouteData();
|
||||
routeData.DataTokens[Core.Constants.Web.UmbracoDataToken] = content;
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace Umbraco.Tests.Web
|
||||
Current.Container = container.Object;
|
||||
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
Udi.ResetUdiTypes();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
Reference in New Issue
Block a user