Refactor IPublishedContent.Name()
This commit is contained in:
@@ -202,35 +202,33 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var publishedContent = snapshot.Content.GetById(1);
|
||||
|
||||
Assert.IsNotNull(publishedContent);
|
||||
Assert.AreEqual("It Works1!", publishedContent.Name);
|
||||
Assert.AreEqual("val1", publishedContent.Value<string>("prop"));
|
||||
Assert.AreEqual("val-fr1", publishedContent.Value<string>("prop", "fr-FR"));
|
||||
Assert.AreEqual("val-uk1", publishedContent.Value<string>("prop", "en-UK"));
|
||||
|
||||
Assert.AreEqual("name-fr1", publishedContent.GetCulture("fr-FR").Name);
|
||||
Assert.AreEqual("name-uk1", publishedContent.GetCulture("en-UK").Name);
|
||||
Assert.IsNull(publishedContent.Name()); // no invariant name for varying content
|
||||
Assert.AreEqual("name-fr1", publishedContent.Name("fr-FR"));
|
||||
Assert.AreEqual("name-uk1", publishedContent.Name("en-UK"));
|
||||
|
||||
var draftContent = snapshot.Content.GetById(true, 1);
|
||||
Assert.AreEqual("It Works2!", draftContent.Name);
|
||||
Assert.AreEqual("val2", draftContent.Value<string>("prop"));
|
||||
Assert.AreEqual("val-fr2", draftContent.Value<string>("prop", "fr-FR"));
|
||||
Assert.AreEqual("val-uk2", draftContent.Value<string>("prop", "en-UK"));
|
||||
|
||||
Assert.AreEqual("name-fr2", draftContent.GetCulture("fr-FR").Name);
|
||||
Assert.AreEqual("name-uk2", draftContent.GetCulture("en-UK").Name);
|
||||
Assert.IsNull(draftContent.Name()); // no invariant name for varying content
|
||||
Assert.AreEqual("name-fr2", draftContent.Name("fr-FR"));
|
||||
Assert.AreEqual("name-uk2", draftContent.Name("en-UK"));
|
||||
|
||||
// now french is default
|
||||
_variationAccesor.VariationContext = new VariationContext("fr-FR");
|
||||
Assert.AreEqual("val-fr1", publishedContent.Value<string>("prop"));
|
||||
Assert.AreEqual("name-fr1", publishedContent.GetCulture().Name);
|
||||
Assert.AreEqual("name-fr1", publishedContent.Name);
|
||||
Assert.AreEqual("name-fr1", publishedContent.Name());
|
||||
Assert.AreEqual(new DateTime(2018, 01, 01, 01, 00, 00), publishedContent.GetCulture().Date);
|
||||
|
||||
// now uk is default
|
||||
_variationAccesor.VariationContext = new VariationContext("en-UK");
|
||||
Assert.AreEqual("val-uk1", publishedContent.Value<string>("prop"));
|
||||
Assert.AreEqual("name-uk1", publishedContent.GetCulture().Name);
|
||||
Assert.AreEqual("name-uk1", publishedContent.Name);
|
||||
Assert.AreEqual("name-uk1", publishedContent.Name());
|
||||
Assert.AreEqual(new DateTime(2018, 01, 02, 01, 00, 00), publishedContent.GetCulture().Date);
|
||||
|
||||
// invariant needs to be retrieved explicitly, when it's not default
|
||||
@@ -251,7 +249,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.AreEqual(ContentVariation.Nothing, againContent.ContentType.GetPropertyType("prop").Variations);
|
||||
|
||||
// now, "no culture" means "invariant"
|
||||
Assert.AreEqual("It Works1!", againContent.Name);
|
||||
Assert.IsNull(againContent.Name()); // no invariant name for varying content
|
||||
Assert.AreEqual("val1", againContent.Value<string>("prop"));
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
UpdateDate = DateTime.Now,
|
||||
Path = "-1,3",
|
||||
UrlSegment = "home-page",
|
||||
Name = "Page" + Guid.NewGuid().ToString(),
|
||||
Version = Guid.NewGuid(),
|
||||
WriterId = 1,
|
||||
WriterName = "Shannon",
|
||||
@@ -148,6 +147,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Level = 1,
|
||||
Children = new List<IPublishedContent>()
|
||||
};
|
||||
d.SetName("Page" + Guid.NewGuid());
|
||||
d.Properties = new Collection<IPublishedProperty>(new List<IPublishedProperty>
|
||||
{
|
||||
new RawValueProperty(factory.CreatePropertyType("property1", 1), d, "value" + indexVals),
|
||||
@@ -183,6 +183,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
// l8tr...
|
||||
private class TestPublishedContent : IPublishedContent
|
||||
{
|
||||
private readonly Dictionary<string, string> _names = new Dictionary<string, string>();
|
||||
|
||||
public string Url { get; set; }
|
||||
public string GetUrl(string culture = null) => throw new NotSupportedException();
|
||||
|
||||
@@ -203,7 +205,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
public Guid Key { get; set; }
|
||||
public int? TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name(string culture = null) => _names.TryGetValue(culture ?? "", out var name) ? name : null;
|
||||
public void SetName(string name, string culture = null) => _names[culture ?? ""] = name;
|
||||
public PublishedCultureInfo GetCulture(string culture = null) => throw new NotSupportedException();
|
||||
public IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => throw new NotSupportedException();
|
||||
public string UrlSegment { get; set; }
|
||||
|
||||
@@ -122,7 +122,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
Id = 1,
|
||||
SortOrder = 0,
|
||||
Name = "Content 1",
|
||||
UrlSegment = "content-1",
|
||||
Path = "/1",
|
||||
Level = 1,
|
||||
@@ -134,12 +133,12 @@ namespace Umbraco.Tests.PublishedContent
|
||||
prop1, prop2, noprop
|
||||
}
|
||||
};
|
||||
item1.SetName("Content 1");
|
||||
|
||||
var item2 = new SolidPublishedContent(contentType1)
|
||||
{
|
||||
Id = 2,
|
||||
SortOrder = 0,
|
||||
Name = "Content 2",
|
||||
UrlSegment = "content-2",
|
||||
Path = "/1/2",
|
||||
Level = 2,
|
||||
@@ -151,6 +150,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
prop3
|
||||
}
|
||||
};
|
||||
item2.SetName("Content 2");
|
||||
|
||||
var prop4 = new SolidPublishedPropertyWithLanguageVariants
|
||||
{
|
||||
@@ -164,7 +164,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
Id = 3,
|
||||
SortOrder = 0,
|
||||
Name = "Content 3",
|
||||
UrlSegment = "content-3",
|
||||
Path = "/1/2/3",
|
||||
Level = 3,
|
||||
@@ -176,6 +175,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
prop4
|
||||
}
|
||||
};
|
||||
item3.SetName("Content 3");
|
||||
|
||||
item1.Children = new List<IPublishedContent> { item2 };
|
||||
item2.Parent = item1;
|
||||
|
||||
@@ -25,11 +25,10 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var contentType2 = factory.CreateContentType(2, "ContentType2", Enumerable.Empty<string>(), CreatePropertyTypes);
|
||||
var contentType2Sub = factory.CreateContentType(3, "ContentType2Sub", Enumerable.Empty<string>(), CreatePropertyTypes);
|
||||
|
||||
cache.Add(new SolidPublishedContent(contentType1)
|
||||
var content = new SolidPublishedContent(contentType1)
|
||||
{
|
||||
Id = 1,
|
||||
SortOrder = 0,
|
||||
Name = "Content 1",
|
||||
UrlSegment = "content-1",
|
||||
Path = "/1",
|
||||
Level = 1,
|
||||
@@ -37,22 +36,23 @@ namespace Umbraco.Tests.PublishedContent
|
||||
ParentId = -1,
|
||||
ChildIds = new int[] { },
|
||||
Properties = new Collection<IPublishedProperty>
|
||||
{
|
||||
new SolidPublishedProperty
|
||||
{
|
||||
new SolidPublishedProperty
|
||||
{
|
||||
Alias = "prop1",
|
||||
SolidHasValue = true,
|
||||
SolidValue = 1234,
|
||||
SolidSourceValue = "1234"
|
||||
}
|
||||
Alias = "prop1",
|
||||
SolidHasValue = true,
|
||||
SolidValue = 1234,
|
||||
SolidSourceValue = "1234"
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
content.SetName("Content 1");
|
||||
cache.Add(content);
|
||||
|
||||
cache.Add(new SolidPublishedContent(contentType2)
|
||||
content = new SolidPublishedContent(contentType2)
|
||||
{
|
||||
Id = 2,
|
||||
SortOrder = 1,
|
||||
Name = "Content 2",
|
||||
UrlSegment = "content-2",
|
||||
Path = "/2",
|
||||
Level = 1,
|
||||
@@ -60,22 +60,23 @@ namespace Umbraco.Tests.PublishedContent
|
||||
ParentId = -1,
|
||||
ChildIds = new int[] { },
|
||||
Properties = new Collection<IPublishedProperty>
|
||||
{
|
||||
new SolidPublishedProperty
|
||||
{
|
||||
new SolidPublishedProperty
|
||||
{
|
||||
Alias = "prop1",
|
||||
SolidHasValue = true,
|
||||
SolidValue = 1234,
|
||||
SolidSourceValue = "1234"
|
||||
}
|
||||
Alias = "prop1",
|
||||
SolidHasValue = true,
|
||||
SolidValue = 1234,
|
||||
SolidSourceValue = "1234"
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
content.SetName("Content 2");
|
||||
cache.Add(content);
|
||||
|
||||
cache.Add(new SolidPublishedContent(contentType2Sub)
|
||||
content = new SolidPublishedContent(contentType2Sub)
|
||||
{
|
||||
Id = 3,
|
||||
SortOrder = 2,
|
||||
Name = "Content 2Sub",
|
||||
UrlSegment = "content-2sub",
|
||||
Path = "/3",
|
||||
Level = 1,
|
||||
@@ -92,14 +93,16 @@ namespace Umbraco.Tests.PublishedContent
|
||||
SolidSourceValue = "1234"
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
content.SetName("Content 2Sub");
|
||||
cache.Add(content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void First()
|
||||
{
|
||||
var content = Current.UmbracoContext.ContentCache.GetAtRoot().First();
|
||||
Assert.AreEqual("Content 1", content.Name);
|
||||
Assert.AreEqual("Content 1", content.Name());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -111,17 +114,17 @@ namespace Umbraco.Tests.PublishedContent
|
||||
.ToIndexedArray();
|
||||
|
||||
var item = items[0];
|
||||
Assert.AreEqual("Content 1", item.Content.Name);
|
||||
Assert.AreEqual("Content 1", item.Content.Name());
|
||||
Assert.IsTrue(item.IsFirst());
|
||||
Assert.IsFalse(item.IsLast());
|
||||
|
||||
item = items[1];
|
||||
Assert.AreEqual("Content 2", item.Content.Name);
|
||||
Assert.AreEqual("Content 2", item.Content.Name());
|
||||
Assert.IsFalse(item.IsFirst());
|
||||
Assert.IsFalse(item.IsLast());
|
||||
|
||||
item = items[2];
|
||||
Assert.AreEqual("Content 2Sub", item.Content.Name);
|
||||
Assert.AreEqual("Content 2Sub", item.Content.Name());
|
||||
Assert.IsFalse(item.IsFirst());
|
||||
Assert.IsTrue(item.IsLast());
|
||||
}
|
||||
@@ -154,7 +157,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
var content = Current.UmbracoContext.ContentCache.GetAtRoot()
|
||||
.OfType<ContentType2>()
|
||||
.First(x => x.Prop1 == 1234);
|
||||
Assert.AreEqual("Content 2", content.Name);
|
||||
Assert.AreEqual("Content 2", content.Name());
|
||||
Assert.AreEqual(1234, content.Prop1);
|
||||
}
|
||||
|
||||
|
||||
@@ -495,7 +495,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
Assert.AreEqual(nodeId, converted.Id);
|
||||
Assert.AreEqual(3, converted.Level);
|
||||
Assert.AreEqual(1, converted.SortOrder);
|
||||
Assert.AreEqual("Sam's Umbraco Image", converted.Name);
|
||||
Assert.AreEqual("Sam's Umbraco Image", converted.Name());
|
||||
Assert.AreEqual("-1,1111,2222,2112", converted.Path);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Umbraco.Tests.PublishedContent
|
||||
{
|
||||
var pc = new Mock<IPublishedContent>();
|
||||
pc.Setup(content => content.Id).Returns(1);
|
||||
pc.Setup(content => content.Name).Returns("test");
|
||||
pc.Setup(content => content.Name(It.IsAny<string>())).Returns("test");
|
||||
pc.Setup(content => content.WriterName).Returns("admin");
|
||||
pc.Setup(content => content.CreatorName).Returns("admin");
|
||||
pc.Setup(content => content.CreateDate).Returns(DateTime.Now);
|
||||
|
||||
@@ -153,8 +153,10 @@ namespace Umbraco.Tests.PublishedContent
|
||||
}
|
||||
}
|
||||
|
||||
class SolidPublishedContent : IPublishedContent
|
||||
internal class SolidPublishedContent : IPublishedContent
|
||||
{
|
||||
private readonly Dictionary<string, string> _names = new Dictionary<string, string>();
|
||||
|
||||
#region Constructor
|
||||
|
||||
public SolidPublishedContent(IPublishedContentType contentType)
|
||||
@@ -177,7 +179,8 @@ namespace Umbraco.Tests.PublishedContent
|
||||
public Guid Key { get; set; }
|
||||
public int? TemplateId { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name(string culture = null) => _names.TryGetValue(culture ?? "", out var name) ? name : null;
|
||||
public void SetName(string name, string culture = null) => _names[culture ?? ""] = name;
|
||||
public PublishedCultureInfo GetCulture(string culture = null) => throw new NotSupportedException();
|
||||
public IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => throw new NotSupportedException();
|
||||
public string UrlSegment { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user