Migrated DictionaryTranslationBuilders into new unit test project and builder format.
This commit is contained in:
@@ -20,6 +20,11 @@ namespace Umbraco.Tests.Common.Builders
|
||||
private DateTime? _updateDate;
|
||||
private string _value;
|
||||
|
||||
public DictionaryTranslationBuilder() : base(null)
|
||||
{
|
||||
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
|
||||
}
|
||||
|
||||
public DictionaryTranslationBuilder(DictionaryItemBuilder parentBuilder) : base(parentBuilder)
|
||||
{
|
||||
_languageBuilder = new LanguageBuilder<DictionaryTranslationBuilder>(this);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Umbraco.Tests.Common.Builders.Interfaces;
|
||||
|
||||
namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
@@ -192,5 +193,12 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
builder.IsContainer = isContainer;
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithCultureInfo<T>(this T builder, string name)
|
||||
where T : IWithCultureInfoBuilder
|
||||
{
|
||||
builder.CultureInfo = new CultureInfo(name);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,30 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Serialization;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.Models
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Infrastructure.Models
|
||||
{
|
||||
[TestFixture]
|
||||
public class DictionaryTranslationTests
|
||||
{
|
||||
private IGlobalSettings GlobalSettings { get; } = SettingsForTests.GenerateMockGlobalSettings();
|
||||
private DictionaryTranslationBuilder _builder = new DictionaryTranslationBuilder();
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_builder = new DictionaryTranslationBuilder();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Deep_Clone()
|
||||
{
|
||||
var item = new DictionaryTranslation(new Language(GlobalSettings, "en-AU")
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
CultureName = "en",
|
||||
Id = 11,
|
||||
IsoCode = "AU",
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now
|
||||
}, "colour")
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
Id = 88,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now
|
||||
};
|
||||
var item = BuildDictionaryTranslation();
|
||||
|
||||
var clone = (DictionaryTranslation) item.DeepClone();
|
||||
var clone = (DictionaryTranslation)item.DeepClone();
|
||||
|
||||
Assert.AreNotSame(clone, item);
|
||||
Assert.AreEqual(clone, item);
|
||||
@@ -53,32 +42,26 @@ namespace Umbraco.Tests.Models
|
||||
//This double verifies by reflection
|
||||
var allProps = clone.GetType().GetProperties();
|
||||
foreach (var propertyInfo in allProps.Where(x => x.Name != "Language"))
|
||||
{
|
||||
Assert.AreEqual(propertyInfo.GetValue(clone, null), propertyInfo.GetValue(item, null));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_Without_Error()
|
||||
{
|
||||
var item = new DictionaryTranslation(new Language(GlobalSettings, "en-AU")
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
CultureName = "en",
|
||||
Id = 11,
|
||||
IsoCode = "AU",
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now
|
||||
}, "colour")
|
||||
{
|
||||
CreateDate = DateTime.Now,
|
||||
Id = 88,
|
||||
Key = Guid.NewGuid(),
|
||||
UpdateDate = DateTime.Now
|
||||
};
|
||||
var item = BuildDictionaryTranslation();
|
||||
|
||||
var json = JsonConvert.SerializeObject(item);
|
||||
Debug.Print(json);
|
||||
}
|
||||
|
||||
private IDictionaryTranslation BuildDictionaryTranslation()
|
||||
{
|
||||
return _builder
|
||||
.AddLanguage()
|
||||
.WithCultureInfo("en-AU")
|
||||
.Done()
|
||||
.WithValue("colour")
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
|
||||
namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
{
|
||||
[TestFixture]
|
||||
public class LanguageBuilderTests
|
||||
{
|
||||
[Test]
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
var builder = new LanguageBuilder();
|
||||
|
||||
// Act
|
||||
var language = builder
|
||||
.WithCultureInfo("en-GB")
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("GB", language.IsoCode);
|
||||
Assert.AreEqual("en", language.CultureName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,20 +10,20 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
public void Is_Built_Correctly()
|
||||
{
|
||||
// Arrange
|
||||
const string path = "/css/styles.css";
|
||||
const string content = @"body { color:#000; } .bold {font-weight:bold;}";
|
||||
const string testPath = "/css/styles.css";
|
||||
const string testContent = @"body { color:#000; } .bold {font-weight:bold;}";
|
||||
|
||||
var builder = new StylesheetBuilder();
|
||||
|
||||
// Act
|
||||
var stylesheet = builder
|
||||
.WithPath(path)
|
||||
.WithContent(content)
|
||||
.WithPath(testPath)
|
||||
.WithContent(testContent)
|
||||
.Build();
|
||||
|
||||
// Assert
|
||||
Assert.AreEqual("\\css\\styles.css", stylesheet.Path);
|
||||
Assert.AreEqual(content, stylesheet.Content);
|
||||
Assert.AreEqual(testContent, stylesheet.Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +289,6 @@
|
||||
<Compile Include="Models\Collections\Item.cs" />
|
||||
<Compile Include="Models\Collections\OrderItem.cs" />
|
||||
<Compile Include="Models\Collections\SimpleOrder.cs" />
|
||||
<Compile Include="Models\DictionaryTranslationTests.cs" />
|
||||
<Compile Include="Web\Mvc\RenderModelBinderTests.cs" />
|
||||
<Compile Include="Web\Mvc\SurfaceControllerTests.cs" />
|
||||
<Compile Include="Web\Mvc\UmbracoViewPageTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user