Adds test

This commit is contained in:
Shannon
2018-11-26 17:20:15 +11:00
parent 9368c71ced
commit b6790261c4
25 changed files with 234 additions and 121 deletions
+4 -2
View File
@@ -5,6 +5,8 @@ using Newtonsoft.Json.Linq;
namespace Umbraco.Core.Models
{
//TODO: Make a property value converter for this!
/// <summary>
/// A model representing the value saved for the grid
/// </summary>
@@ -19,7 +21,7 @@ namespace Umbraco.Core.Models
public class GridSection
{
[JsonProperty("grid")]
public string Grid { get; set; }
public string Grid { get; set; } //fixme: what is this?
[JsonProperty("rows")]
public IEnumerable<GridRow> Rows { get; set; }
@@ -46,7 +48,7 @@ namespace Umbraco.Core.Models
public class GridArea
{
[JsonProperty("grid")]
public string Grid { get; set; }
public string Grid { get; set; } //fixme: what is this?
[JsonProperty("controls")]
public IEnumerable<GridControl> Controls { get; set; }
+18 -4
View File
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
@@ -16,7 +17,7 @@ namespace Umbraco.Examine
protected void AddPropertyValue(Property property, string culture, string segment, IDictionary<string, object[]> values)
{
var editor = _propertyEditors[property.Alias];
var editor = _propertyEditors[property.PropertyType.PropertyEditorAlias];
if (editor == null) return;
var indexVals = editor.ValueIndexer.GetIndexValues(property, culture, segment);
@@ -34,11 +35,24 @@ namespace Umbraco.Examine
case null:
continue;
case string strVal:
if (strVal.IsNullOrWhiteSpace()) return;
values.Add($"{keyVal.Key}{cultureSuffix}", new[] { val });
{
if (strVal.IsNullOrWhiteSpace()) return;
var key = $"{keyVal.Key}{cultureSuffix}";
if (values.TryGetValue(key, out var v))
values[key] = new List<object>(v) { val }.ToArray();
else
values.Add($"{keyVal.Key}{cultureSuffix}", new[] { val });
}
break;
default:
values.Add($"{keyVal.Key}{cultureSuffix}", new[] { val });
{
var key = $"{keyVal.Key}{cultureSuffix}";
if (values.TryGetValue(key, out var v))
values[key] = new List<object>(v) { val }.ToArray();
else
values.Add($"{keyVal.Key}{cultureSuffix}", new[] { val });
}
break;
}
}
+1 -1
View File
@@ -48,7 +48,7 @@
</ItemGroup>
<ItemGroup>
<!-- note: NuGet deals with transitive references now -->
<PackageReference Include="Examine" Version="1.0.0-beta031" />
<PackageReference Include="Examine" Version="1.0.0-beta032" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NPoco" Version="3.9.4" />
</ItemGroup>
+2 -2
View File
@@ -31,8 +31,8 @@ namespace Umbraco.Examine
/// </summary>
public class UmbracoContentIndexer : UmbracoExamineIndexer
{
protected IValueSetBuilder<IMedia> MediaValueSetBuilder { get; }
protected IValueSetBuilder<IContent> ContentValueSetBuilder { get; }
public IValueSetBuilder<IMedia> MediaValueSetBuilder { get; }
public IValueSetBuilder<IContent> ContentValueSetBuilder { get; }
protected IContentService ContentService { get; }
protected IMediaService MediaService { get; }
protected ILocalizationService LanguageService { get; }
@@ -39,8 +39,11 @@ namespace Umbraco.Examine
}
//must have a 'path'
if (valueSet.Values.ContainsKey(PathKey) == false) return false;
var path = valueSet.Values[PathKey]?[0].ToString() ?? string.Empty;
if (!valueSet.Values.TryGetValue(PathKey, out var pathValues)) return false;
if (pathValues.Count == 0) return false;
if (pathValues[0] == null) return false;
if (pathValues[0].ToString().IsNullOrWhiteSpace()) return false;
var path = pathValues[0].ToString();
// Test for access if we're only indexing published content
// return nothing if we're not supporting protected content and it is protected, and we're not supporting unpublished content
@@ -78,7 +78,7 @@ namespace Umbraco.Tests.Models.Collections
[Test]
public void PropertyGroups_Collection_FirstOrDefault_Returns_Null()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
Assert.That(contentType.PropertyGroups, Is.Not.Null);
Assert.That(contentType.PropertyGroups.FirstOrDefault(x => x.Name.InvariantEquals("Content")) == null, Is.False);
@@ -16,7 +16,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_Reset_Clears_SavedPublishedState()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.PublishedState = PublishedState.Publishing;
@@ -29,7 +29,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_OnlyIfActuallyChanged_Content()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// if you assign a content property with its value it is not dirty
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_OnlyIfActuallyChanged_User()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var prop = content.Properties.First();
@@ -75,7 +75,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_UpdateDate()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var prop = content.Properties.First();
@@ -98,7 +98,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_WasDirty_ContentProperty()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties(false);
Assert.IsFalse(content.IsDirty());
@@ -125,7 +125,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_WasDirty_ContentSortOrder()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties(false);
Assert.IsFalse(content.IsDirty());
@@ -152,7 +152,7 @@ namespace Umbraco.Tests.Models
[Test]
public void DirtyProperty_WasDirty_UserProperty()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var prop = content.Properties.First();
content.ResetDirtyProperties(false);
+29 -29
View File
@@ -128,7 +128,7 @@ namespace Umbraco.Tests.Models
[Test]
public void All_Dirty_Properties_Get_Reset()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties(false);
@@ -144,7 +144,7 @@ namespace Umbraco.Tests.Models
public void Can_Verify_Mocked_Content()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -157,7 +157,7 @@ namespace Umbraco.Tests.Models
public void Can_Change_Property_Value()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -173,7 +173,7 @@ namespace Umbraco.Tests.Models
public void Can_Set_Property_Value_As_String()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -189,7 +189,7 @@ namespace Umbraco.Tests.Models
public void Can_Clone_Content_With_Reset_Identity()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.Id = 10;
content.Key = new Guid("29181B97-CB8F-403F-86DE-5FEB497F4800");
@@ -218,7 +218,7 @@ namespace Umbraco.Tests.Models
public void Can_Deep_Clone_Perf_Test()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var i = 200;
@@ -269,7 +269,7 @@ namespace Umbraco.Tests.Models
public void Can_Deep_Clone()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
contentType.Variations = ContentVariation.Culture;
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
@@ -394,7 +394,7 @@ namespace Umbraco.Tests.Models
public void Remember_Dirty_Properties()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
contentType.Variations = ContentVariation.Culture;
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
@@ -475,7 +475,7 @@ namespace Umbraco.Tests.Models
var ss = new SerializationService(new JsonNetSerializer());
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
var i = 200;
@@ -530,7 +530,7 @@ namespace Umbraco.Tests.Models
public void Can_Change_Property_Value_Through_Anonymous_Object()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -548,7 +548,7 @@ namespace Umbraco.Tests.Models
public void Can_Verify_Dirty_Property_On_Content()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -564,7 +564,7 @@ namespace Umbraco.Tests.Models
public void Can_Add_PropertyGroup_On_ContentType()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -579,7 +579,7 @@ namespace Umbraco.Tests.Models
public void Can_Remove_PropertyGroup_From_ContentType()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.ResetDirtyProperties();
// Act
@@ -594,7 +594,7 @@ namespace Umbraco.Tests.Models
public void Can_Add_PropertyType_To_Group_On_ContentType()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -616,7 +616,7 @@ namespace Umbraco.Tests.Models
public void Can_Add_New_Property_To_New_PropertyType()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -638,7 +638,7 @@ namespace Umbraco.Tests.Models
public void Can_Add_New_Property_To_New_PropertyType_In_New_PropertyGroup()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act
@@ -669,7 +669,7 @@ namespace Umbraco.Tests.Models
public void Can_Update_PropertyType_Through_Content_Properties()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
// Act - note that the PropertyType's properties like SortOrder is not updated through the Content object
@@ -689,7 +689,7 @@ namespace Umbraco.Tests.Models
public void Can_Change_ContentType_On_Content()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
@@ -708,7 +708,7 @@ namespace Umbraco.Tests.Models
public void Can_Change_ContentType_On_Content_And_Set_Property_Value()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
@@ -725,7 +725,7 @@ namespace Umbraco.Tests.Models
public void Can_Change_ContentType_On_Content_And_Still_Get_Old_Properties()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
@@ -744,7 +744,7 @@ namespace Umbraco.Tests.Models
public void Can_Change_ContentType_On_Content_And_Clear_Old_PropertyTypes()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var simpleContentType = MockedContentTypes.CreateSimpleContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
@@ -760,7 +760,7 @@ namespace Umbraco.Tests.Models
[Test]
public void Can_Verify_Content_Is_Published()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
var content = MockedContent.CreateTextpageContent(contentType, "Textpage", -1);
content.ResetDirtyProperties();
@@ -794,7 +794,7 @@ namespace Umbraco.Tests.Models
public void Adding_PropertyGroup_To_ContentType_Results_In_Dirty_Entity()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.ResetDirtyProperties();
// Act
@@ -811,7 +811,7 @@ namespace Umbraco.Tests.Models
public void After_Committing_Changes_Was_Dirty_Is_True()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.ResetDirtyProperties(); //reset
// Act
@@ -828,7 +828,7 @@ namespace Umbraco.Tests.Models
public void After_Committing_Changes_Was_Dirty_Is_True_On_Changed_Property()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.ResetDirtyProperties(); //reset
var content = MockedContent.CreateTextpageContent(contentType, "test", -1);
content.ResetDirtyProperties();
@@ -859,7 +859,7 @@ namespace Umbraco.Tests.Models
public void If_Not_Committed_Was_Dirty_Is_False()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
// Act
contentType.Alias = "newAlias";
@@ -873,7 +873,7 @@ namespace Umbraco.Tests.Models
public void Detect_That_A_Property_Is_Removed()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
Assert.That(contentType.WasPropertyDirty("HasPropertyTypeBeenRemoved"), Is.False);
// Act
@@ -887,7 +887,7 @@ namespace Umbraco.Tests.Models
public void Adding_PropertyType_To_PropertyGroup_On_ContentType_Results_In_Dirty_Entity()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.ResetDirtyProperties();
// Act
@@ -974,7 +974,7 @@ namespace Umbraco.Tests.Models
[Test]
public void Can_Avoid_Circular_Dependencies_In_Composition()
{
var textPage = MockedContentTypes.CreateTextpageContentType();
var textPage = MockedContentTypes.CreateTextPageContentType();
var parent = MockedContentTypes.CreateSimpleContentType("parent", "Parent", null, true);
var meta = MockedContentTypes.CreateMetaContentType();
var mixin1 = MockedContentTypes.CreateSimpleContentType("mixin1", "Mixin1", new PropertyTypeCollection(true,
+4 -4
View File
@@ -33,7 +33,7 @@ namespace Umbraco.Tests.Models
[Test]
public void Can_Deep_Clone_Content_Type_With_Reset_Identities()
{
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
var i = 200;
@@ -105,7 +105,7 @@ namespace Umbraco.Tests.Models
public void Can_Deep_Clone_Content_Type_Perf_Test()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
var i = 200;
@@ -155,7 +155,7 @@ namespace Umbraco.Tests.Models
public void Can_Deep_Clone_Content_Type()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
var i = 200;
@@ -256,7 +256,7 @@ namespace Umbraco.Tests.Models
var ss = new SerializationService(new JsonNetSerializer());
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
contentType.Id = 99;
var i = 200;
+1 -1
View File
@@ -18,7 +18,7 @@ namespace Umbraco.Tests.Models
public void Can_Generate_Xml_Representation_Of_Content()
{
// Arrange
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate); // else, FK violation on contentType!
ServiceContext.ContentTypeService.Save(contentType);
@@ -427,7 +427,7 @@ namespace Umbraco.Tests.Models.Mapping
// setup the mocks to return the data we want to test against...
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
MockedContentTypes.EnsureAllIds(contentType, 8888);
//Act
@@ -964,7 +964,7 @@ namespace Umbraco.Tests.Persistence.Repositories
ServiceContext.ContentTypeService.Save(simpleContentType);
//Create and Save ContentType "textPage" -> (NodeDto.NodeIdSeed + 1)
ContentType textpageContentType = MockedContentTypes.CreateTextpageContentType();
ContentType textpageContentType = MockedContentTypes.CreateTextPageContentType();
ServiceContext.ContentTypeService.Save(textpageContentType);
}
}
@@ -65,9 +65,9 @@ namespace Umbraco.Tests.Services
// ... NOPE, made even more nice changes, it is now...
// 4452ms !!!!!!!
var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "test1");
var contentType2 = MockedContentTypes.CreateTextpageContentType("test2", "test2");
var contentType3 = MockedContentTypes.CreateTextpageContentType("test3", "test3");
var contentType1 = MockedContentTypes.CreateTextPageContentType("test1", "test1");
var contentType2 = MockedContentTypes.CreateTextPageContentType("test2", "test2");
var contentType3 = MockedContentTypes.CreateTextPageContentType("test3", "test3");
ServiceContext.ContentTypeService.Save(new[] { contentType1, contentType2, contentType3 });
contentType1.AllowedContentTypes = new[]
{
@@ -291,7 +291,7 @@ namespace Umbraco.Tests.Services
public void CreateTestData()
{
//Create and Save ContentType "textpage" -> NodeDto.NodeIdSeed
ContentType contentType = MockedContentTypes.CreateTextpageContentType();
ContentType contentType = MockedContentTypes.CreateTextPageContentType();
ServiceContext.ContentTypeService.Save(contentType);
}
}
@@ -92,7 +92,7 @@ namespace Umbraco.Tests.Services
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
contentTypeService.Save(contentType);
@@ -118,7 +118,7 @@ namespace Umbraco.Tests.Services
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
contentTypeService.Save(contentType);
@@ -142,7 +142,7 @@ namespace Umbraco.Tests.Services
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var contentType = MockedContentTypes.CreateTextpageContentType();
var contentType = MockedContentTypes.CreateTextPageContentType();
ServiceContext.FileService.SaveTemplate(contentType.DefaultTemplate);
contentTypeService.Save(contentType);
@@ -170,10 +170,10 @@ namespace Umbraco.Tests.Services
var contentService = ServiceContext.ContentService;
var contentTypeService = ServiceContext.ContentTypeService;
var ct1 = MockedContentTypes.CreateTextpageContentType("ct1");
var ct1 = MockedContentTypes.CreateTextPageContentType("ct1");
ServiceContext.FileService.SaveTemplate(ct1.DefaultTemplate);
contentTypeService.Save(ct1);
var ct2 = MockedContentTypes.CreateTextpageContentType("ct2");
var ct2 = MockedContentTypes.CreateTextPageContentType("ct2");
ServiceContext.FileService.SaveTemplate(ct2.DefaultTemplate);
contentTypeService.Save(ct2);
@@ -611,7 +611,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Deleting_PropertyType_Removes_The_Property_From_Content()
{
IContentType contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "Test1");
IContentType contentType1 = MockedContentTypes.CreateTextPageContentType("test1", "Test1");
ServiceContext.FileService.SaveTemplate(contentType1.DefaultTemplate);
ServiceContext.ContentTypeService.Save(contentType1);
IContent contentItem = MockedContent.CreateTextpageContent(contentType1, "Testing", -1);
@@ -633,11 +633,11 @@ namespace Umbraco.Tests.Services
[Test]
public void Rebuild_Content_Xml_On_Alias_Change()
{
var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "Test1");
var contentType1 = MockedContentTypes.CreateTextPageContentType("test1", "Test1");
ServiceContext.FileService.SaveTemplate(contentType1.DefaultTemplate);
ServiceContext.ContentTypeService.Save(contentType1);
var contentType2 = MockedContentTypes.CreateTextpageContentType("test2", "Test2");
var contentType2 = MockedContentTypes.CreateTextPageContentType("test2", "Test2");
ServiceContext.FileService.SaveTemplate(contentType2.DefaultTemplate);
ServiceContext.ContentTypeService.Save(contentType2);
@@ -701,7 +701,7 @@ namespace Umbraco.Tests.Services
[Test]
public void Rebuild_Content_Xml_On_Property_Removal()
{
var contentType1 = MockedContentTypes.CreateTextpageContentType("test1", "Test1");
var contentType1 = MockedContentTypes.CreateTextPageContentType("test1", "Test1");
ServiceContext.FileService.SaveTemplate(contentType1.DefaultTemplate);
ServiceContext.ContentTypeService.Save(contentType1);
var contentItems1 = MockedContent.CreateTextpageContent(contentType1, -1, 10).ToArray();
@@ -26,7 +26,7 @@ namespace Umbraco.Tests.TestHelpers.Entities
return contentType;
}
public static ContentType CreateTextpageContentType(string alias = "textPage", string name = "Text Page")
public static ContentType CreateTextPageContentType(string alias = "textPage", string name = "Text Page")
{
var contentType = new ContentType(-1)
{
+1 -1
View File
@@ -77,7 +77,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="Castle.Core" Version="4.2.1" />
<PackageReference Include="Examine" Version="1.0.0-beta031" />
<PackageReference Include="Examine" Version="1.0.0-beta032" />
<PackageReference Include="HtmlAgilityPack">
<Version>1.8.9</Version>
</PackageReference>
+99 -2
View File
@@ -10,6 +10,11 @@ using Umbraco.Tests.Testing;
using Umbraco.Examine;
using Umbraco.Core.PropertyEditors;
using LightInject;
using Umbraco.Tests.TestHelpers.Entities;
using Umbraco.Core.Models;
using Newtonsoft.Json;
using System.Collections.Generic;
using System;
namespace Umbraco.Tests.UmbracoExamine
{
@@ -22,6 +27,98 @@ namespace Umbraco.Tests.UmbracoExamine
public class IndexTest : ExamineBaseTest
{
[Test]
public void Index_Property_Data_With_Value_Indexer()
{
using (var luceneDir = new RandomIdRamDirectory())
using (var indexer = IndexInitializer.GetUmbracoIndexer(
ProfilingLogger, luceneDir, ScopeProvider.SqlContext, Container.GetInstance<PropertyEditorCollection>(),
options: new UmbracoContentIndexerOptions(true, false, null)))
using (indexer.ProcessNonAsync())
{
indexer.EnsureIndex(true);
var contentType = MockedContentTypes.CreateBasicContentType();
contentType.AddPropertyType(new PropertyType("test", ValueStorageType.Ntext)
{
Alias = "grid",
Name = "Grid",
PropertyEditorAlias = Core.Constants.PropertyEditors.Aliases.Grid
});
var content = MockedContent.CreateBasicContent(contentType);
content.Id = 555;
content.Path = "-1,555";
var gridVal = new GridValue
{
Name = "n1",
Sections = new List<GridValue.GridSection>
{
new GridValue.GridSection
{
Grid = "g1",
Rows = new List<GridValue.GridRow>
{
new GridValue.GridRow
{
Id = Guid.NewGuid(),
Name = "row1",
Areas = new List<GridValue.GridArea>
{
new GridValue.GridArea
{
Grid = "g2",
Controls = new List<GridValue.GridControl>
{
new GridValue.GridControl
{
Editor = new GridValue.GridEditor
{
Alias = "editor1",
View = "view1"
},
Value = "value1"
},
new GridValue.GridControl
{
Editor = new GridValue.GridEditor
{
Alias = "editor1",
View = "view1"
},
Value = "value2"
}
}
}
}
}
}
}
}
};
var json = JsonConvert.SerializeObject(gridVal);
content.Properties["grid"].SetValue(json);
var valueSet = indexer.ContentValueSetBuilder.GetValueSets(content);
indexer.IndexItems(valueSet);
var searcher = indexer.GetSearcher();
var results = searcher.Search(searcher.CreateCriteria().Id(555).Compile());
Assert.AreEqual(1, results.TotalItemCount);
var result = results.First();
Assert.IsTrue(result.Values.ContainsKey("grid.row1"));
Assert.AreEqual("value1", result.AllValues["grid.row1"][0]);
Assert.AreEqual("value2", result.AllValues["grid.row1"][1]);
Assert.IsTrue(result.Values.ContainsKey("grid"));
Assert.AreEqual("value1 value2 ", result["grid"]);
Assert.IsTrue(result.Values.ContainsKey($"{UmbracoExamineIndexer.RawFieldPrefix}grid"));
Assert.AreEqual(json, result[$"{UmbracoExamineIndexer.RawFieldPrefix}grid"]);
}
}
[Test]
public void Rebuild_Index()
{
@@ -98,7 +195,7 @@ namespace Umbraco.Tests.UmbracoExamine
Assert.AreEqual("-1,1111,2222,2112", currPath);
//ensure it's indexed
indexer.IndexItems(new []{ node.ConvertToValueSet(IndexTypes.Media) });
indexer.IndexItem(node.ConvertToValueSet(IndexTypes.Media));
//it will not exist because it exists under 2222
var results = searcher.Search(searcher.CreateCriteria().Id(2112).Compile());
@@ -140,7 +237,7 @@ namespace Umbraco.Tests.UmbracoExamine
Assert.AreEqual("-1,1111,2222,2112", currPath);
//ensure it's indexed
indexer1.IndexItems(new[] { node.ConvertToValueSet(IndexTypes.Media) });
indexer1.IndexItem(node.ConvertToValueSet(IndexTypes.Media));
@@ -87,7 +87,7 @@ namespace Umbraco.Tests.UmbracoExamine
var currentSort = 0;
foreach (var searchResult in results)
{
var sort = int.Parse(searchResult.Fields["sortOrder"]);
var sort = int.Parse(searchResult.Values["sortOrder"]);
if (currentSort >= sort)
{
return false;
+1 -1
View File
@@ -88,7 +88,7 @@
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
<PackageReference Include="ClientDependency" Version="1.9.7" />
<PackageReference Include="ClientDependency-Mvc5" Version="1.8.0.0" />
<PackageReference Include="Examine" Version="1.0.0-beta031" />
<PackageReference Include="Examine" Version="1.0.0-beta032" />
<PackageReference Include="ImageProcessor.Web" Version="4.9.3.25" />
<PackageReference Include="ImageProcessor.Web.Config" Version="2.4.1.19" />
<PackageReference Include="Lucene.Net.Contrib" Version="3.0.3" />
@@ -123,22 +123,22 @@ namespace Umbraco.Web.Models.Mapping
.AfterMap((src, dest) =>
{
//get the icon if there is one
dest.Icon = src.Fields.ContainsKey(UmbracoExamineIndexer.IconFieldName)
? src.Fields[UmbracoExamineIndexer.IconFieldName]
dest.Icon = src.Values.ContainsKey(UmbracoExamineIndexer.IconFieldName)
? src.Values[UmbracoExamineIndexer.IconFieldName]
: "icon-document";
dest.Name = src.Fields.ContainsKey("nodeName") ? src.Fields["nodeName"] : "[no name]";
if (src.Fields.ContainsKey(UmbracoExamineIndexer.NodeKeyFieldName))
dest.Name = src.Values.ContainsKey("nodeName") ? src.Values["nodeName"] : "[no name]";
if (src.Values.ContainsKey(UmbracoExamineIndexer.NodeKeyFieldName))
{
Guid key;
if (Guid.TryParse(src.Fields[UmbracoExamineIndexer.NodeKeyFieldName], out key))
if (Guid.TryParse(src.Values[UmbracoExamineIndexer.NodeKeyFieldName], out key))
{
dest.Key = key;
//need to set the UDI
if (src.Fields.ContainsKey(LuceneIndexer.CategoryFieldName))
if (src.Values.ContainsKey(LuceneIndexer.CategoryFieldName))
{
switch (src.Fields[LuceneIndexer.CategoryFieldName])
switch (src.Values[LuceneIndexer.CategoryFieldName])
{
case IndexTypes.Member:
dest.Udi = new GuidUdi(Constants.UdiEntityType.Member, dest.Key);
@@ -154,10 +154,10 @@ namespace Umbraco.Web.Models.Mapping
}
}
if (src.Fields.ContainsKey("parentID"))
if (src.Values.ContainsKey("parentID"))
{
int parentId;
if (int.TryParse(src.Fields["parentID"], out parentId))
if (int.TryParse(src.Values["parentID"], out parentId))
{
dest.ParentId = parentId;
}
@@ -166,11 +166,11 @@ namespace Umbraco.Web.Models.Mapping
dest.ParentId = -1;
}
}
dest.Path = src.Fields.ContainsKey(UmbracoExamineIndexer.IndexPathFieldName) ? src.Fields[UmbracoExamineIndexer.IndexPathFieldName] : "";
dest.Path = src.Values.ContainsKey(UmbracoExamineIndexer.IndexPathFieldName) ? src.Values[UmbracoExamineIndexer.IndexPathFieldName] : "";
if (src.Fields.ContainsKey(LuceneIndexer.ItemTypeFieldName))
if (src.Values.ContainsKey(LuceneIndexer.ItemTypeFieldName))
{
dest.AdditionalData.Add("contentType", src.Fields[LuceneIndexer.ItemTypeFieldName]);
dest.AdditionalData.Add("contentType", src.Values[LuceneIndexer.ItemTypeFieldName]);
}
});
@@ -10,6 +10,7 @@ using Umbraco.Examine;
namespace Umbraco.Web.PropertyEditors
{
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models;
/// <summary>
@@ -19,7 +20,7 @@ namespace Umbraco.Web.PropertyEditors
{
public IEnumerable<KeyValuePair<string, object[]>> GetIndexValues(Property property, string culture, string segment)
{
var result = new Dictionary<string, object[]>();
var result = new List<KeyValuePair<string, object[]>>();
var val = property.GetValue(culture, segment);
@@ -28,44 +29,40 @@ namespace Umbraco.Web.PropertyEditors
{
try
{
//TODO: We should deserialize this to Umbraco.Core.Models.GridValue instead of doing the below
var json = JsonConvert.DeserializeObject<JObject>(rawVal);
var gridVal = JsonConvert.DeserializeObject<GridValue>(rawVal);
//check if this is formatted for grid json
if (json.HasValues && json.TryGetValue("name", out _) && json.TryGetValue("sections", out _))
//get all values and put them into a single field (using JsonPath)
var sb = new StringBuilder();
foreach (var row in gridVal.Sections.SelectMany(x => x.Rows))
{
//get all values and put them into a single field (using JsonPath)
var sb = new StringBuilder();
foreach (var row in json.SelectTokens("$.sections[*].rows[*]"))
var rowName = row.Name;
foreach (var control in row.Areas.SelectMany(x => x.Controls))
{
var rowName = row["name"].Value<string>();
var areaVals = row.SelectTokens("$.areas[*].controls[*].value");
var controlVal = control.Value;
foreach (var areaVal in areaVals)
//TODO: If it's not a string, then it's a json formatted value -
// we cannot really index this in a smart way since it could be 'anything'
if (controlVal.Type == JTokenType.String)
{
//TODO: If it's not a string, then it's a json formatted value -
// we cannot really index this in a smart way since it could be 'anything'
if (areaVal.Type == JTokenType.String)
{
var str = areaVal.Value<string>();
str = XmlHelper.CouldItBeXml(str) ? str.StripHtml() : str;
sb.Append(str);
sb.Append(" ");
var str = controlVal.Value<string>();
str = XmlHelper.CouldItBeXml(str) ? str.StripHtml() : str;
sb.Append(str);
sb.Append(" ");
//add the row name as an individual field
result.Add($"{property.Alias}.{rowName}", new[] { str });
}
//add the row name as an individual field
result.Add(new KeyValuePair<string, object[]>($"{property.Alias}.{rowName}", new[] { str }));
}
}
}
if (sb.Length > 0)
{
//First save the raw value to a raw field
result.Add($"{UmbracoExamineIndexer.RawFieldPrefix}{property.Alias}", new[] { rawVal });
if (sb.Length > 0)
{
//First save the raw value to a raw field
result.Add(new KeyValuePair<string, object[]>($"{UmbracoExamineIndexer.RawFieldPrefix}{property.Alias}", new[] { rawVal }));
//index the property with the combined/cleaned value
result.Add(property.Alias, new[] { sb.ToString() });
}
//index the property with the combined/cleaned value
result.Add(new KeyValuePair<string, object[]>(property.Alias, new[] { sb.ToString() }));
}
}
catch (InvalidCastException)
@@ -359,7 +359,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
return new CacheValues
{
Values = searchResult.Fields,
Values = searchResult.Values,
FromExamine = true
};
}
@@ -278,14 +278,14 @@ namespace Umbraco.Web.Search
}
var searchResult = results.First(x => x.Id == m.Id.ToString());
if (searchResult.Fields.ContainsKey("email") && searchResult.Fields["email"] != null)
if (searchResult.Values.ContainsKey("email") && searchResult.Values["email"] != null)
{
m.AdditionalData["Email"] = results.First(x => x.Id == m.Id.ToString()).Fields["email"];
m.AdditionalData["Email"] = results.First(x => x.Id == m.Id.ToString()).Values["email"];
}
if (searchResult.Fields.ContainsKey("__key") && searchResult.Fields["__key"] != null)
if (searchResult.Values.ContainsKey("__key") && searchResult.Values["__key"] != null)
{
Guid key;
if (Guid.TryParse(searchResult.Fields["__key"], out key))
if (Guid.TryParse(searchResult.Values["__key"], out key))
{
m.Key = key;
}
+1 -1
View File
@@ -62,7 +62,7 @@
<PackageReference Include="AutoMapper" Version="7.0.1" />
<PackageReference Include="ClientDependency" Version="1.9.7" />
<PackageReference Include="CSharpTest.Net.Collections" Version="14.906.1403.1082" />
<PackageReference Include="Examine" Version="1.0.0-beta031" />
<PackageReference Include="Examine" Version="1.0.0-beta032" />
<PackageReference Include="HtmlAgilityPack" Version="1.8.9" />
<PackageReference Include="ImageProcessor">
<Version>2.6.2.25</Version>