Migrated EntityXmlSerializerTests. Also aligned namespaces and update LocalizationServiceTests to use test model builders.
This commit is contained in:
@@ -202,10 +202,10 @@ namespace Umbraco.Tests.Common.Builders.Extensions
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static T WithCultureInfo<T>(this T builder, string name)
|
||||
public static T WithCultureInfo<T>(this T builder, string cultureCode)
|
||||
where T : IWithCultureInfoBuilder
|
||||
{
|
||||
builder.CultureInfo = CultureInfo.GetCultureInfo(name);
|
||||
builder.CultureInfo = CultureInfo.GetCultureInfo(cultureCode);
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
private DateTime? _createDate;
|
||||
private CultureInfo _cultureInfo;
|
||||
private string _cultureName;
|
||||
private DateTime? _deleteDate;
|
||||
private int? _fallbackLanguageId;
|
||||
private int? _id;
|
||||
@@ -36,6 +37,12 @@ namespace Umbraco.Tests.Common.Builders
|
||||
{
|
||||
}
|
||||
|
||||
public LanguageBuilder<TParent> WithCultureName(string cultureName)
|
||||
{
|
||||
_cultureName = cultureName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LanguageBuilder<TParent> WithIsDefault(bool isDefault)
|
||||
{
|
||||
_isDefault = isDefault;
|
||||
@@ -57,6 +64,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
public override ILanguage Build()
|
||||
{
|
||||
var cultureInfo = _cultureInfo ?? CultureInfo.GetCultureInfo("en-US");
|
||||
var cultureName = _cultureName ?? cultureInfo.EnglishName;
|
||||
var globalSettings = new GlobalSettings { DefaultUILanguage = cultureInfo.Name };
|
||||
var key = _key ?? Guid.NewGuid();
|
||||
var createDate = _createDate ?? DateTime.Now;
|
||||
@@ -69,7 +77,7 @@ namespace Umbraco.Tests.Common.Builders
|
||||
return new Language(globalSettings, cultureInfo.Name)
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
CultureName = cultureInfo.EnglishName,
|
||||
CultureName = cultureName,
|
||||
IsoCode = cultureInfo.Name,
|
||||
Key = key,
|
||||
CreateDate = createDate,
|
||||
|
||||
@@ -6,7 +6,7 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering the DataTypeService with cache enabled
|
||||
|
||||
@@ -11,7 +11,7 @@ using Umbraco.Tests.Testing;
|
||||
|
||||
// ReSharper disable CommentTypo
|
||||
// ReSharper disable StringLiteralTypo
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)]
|
||||
|
||||
@@ -7,10 +7,9 @@ using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering the DataTypeService
|
||||
|
||||
@@ -13,7 +13,7 @@ using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering the EntityService
|
||||
|
||||
@@ -3,35 +3,32 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Services.Importing;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Integration.Services.Importing;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class EntityXmlSerializerTests : TestWithSomeContentBase
|
||||
public class EntityXmlSerializerTests : UmbracoIntegrationTest
|
||||
{
|
||||
private IEntityXmlSerializer Serializer => Factory.GetInstance<IEntityXmlSerializer>();
|
||||
private GlobalSettings _globalSettings;
|
||||
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
_globalSettings = new GlobalSettings();
|
||||
}
|
||||
private IEntityXmlSerializer Serializer => GetRequiredService<IEntityXmlSerializer>();
|
||||
|
||||
[Test]
|
||||
public void Can_Export_Macro()
|
||||
{
|
||||
// Arrange
|
||||
var macro = new Macro(ShortStringHelper, "test1", "Test", "~/views/macropartials/test.cshtml");
|
||||
ServiceContext.MacroService.Save(macro);
|
||||
var macroService = GetRequiredService<IMacroService>();
|
||||
var macro = new MacroBuilder()
|
||||
.WithAlias("test1")
|
||||
.WithName("Test")
|
||||
.Build();
|
||||
macroService.Save(macro);
|
||||
|
||||
// Act
|
||||
var element = Serializer.Serialize(macro);
|
||||
@@ -48,7 +45,8 @@ namespace Umbraco.Tests.Services
|
||||
{
|
||||
// Arrange
|
||||
CreateDictionaryData();
|
||||
var dictionaryItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Parent");
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
var dictionaryItem = localizationService.GetDictionaryItemByKey("Parent");
|
||||
|
||||
var newPackageXml = XElement.Parse(ImportResources.Dictionary_Package);
|
||||
var dictionaryItemsElement = newPackageXml.Elements("DictionaryItems").First();
|
||||
@@ -64,11 +62,18 @@ namespace Umbraco.Tests.Services
|
||||
public void Can_Export_Languages()
|
||||
{
|
||||
// Arrange
|
||||
var languageNbNo = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian" };
|
||||
ServiceContext.LocalizationService.Save(languageNbNo);
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
var languageEnGb = new Language(_globalSettings, "en-GB") { CultureName = "English (United Kingdom)" };
|
||||
ServiceContext.LocalizationService.Save(languageEnGb);
|
||||
var languageNbNo = new LanguageBuilder()
|
||||
.WithCultureInfo("nb-NO")
|
||||
.WithCultureName("Norwegian")
|
||||
.Build();
|
||||
localizationService.Save(languageNbNo);
|
||||
|
||||
var languageEnGb = new LanguageBuilder()
|
||||
.WithCultureInfo("en-GB")
|
||||
.Build();
|
||||
localizationService.Save(languageEnGb);
|
||||
|
||||
var newPackageXml = XElement.Parse(ImportResources.Dictionary_Package);
|
||||
var languageItemsElement = newPackageXml.Elements("Languages").First();
|
||||
@@ -82,11 +87,18 @@ namespace Umbraco.Tests.Services
|
||||
|
||||
private void CreateDictionaryData()
|
||||
{
|
||||
var languageNbNo = new Language(_globalSettings, "nb-NO") { CultureName = "nb-NO" };
|
||||
ServiceContext.LocalizationService.Save(languageNbNo);
|
||||
var localizationService = GetRequiredService<ILocalizationService>();
|
||||
|
||||
var languageEnGb = new Language(_globalSettings, "en-GB") { CultureName = "en-GB" };
|
||||
ServiceContext.LocalizationService.Save(languageEnGb);
|
||||
var languageNbNo = new LanguageBuilder()
|
||||
.WithCultureInfo("nb-NO")
|
||||
.WithCultureName("Norwegian")
|
||||
.Build();
|
||||
localizationService.Save(languageNbNo);
|
||||
|
||||
var languageEnGb = new LanguageBuilder()
|
||||
.WithCultureInfo("en-GB")
|
||||
.Build();
|
||||
localizationService.Save(languageEnGb);
|
||||
|
||||
var parentItem = new DictionaryItem("Parent");
|
||||
var parentTranslations = new List<IDictionaryTranslation>
|
||||
@@ -95,7 +107,7 @@ namespace Umbraco.Tests.Services
|
||||
new DictionaryTranslation(languageEnGb, "ParentValue")
|
||||
};
|
||||
parentItem.Translations = parentTranslations;
|
||||
ServiceContext.LocalizationService.Save(parentItem);
|
||||
localizationService.Save(parentItem);
|
||||
|
||||
var childItem = new DictionaryItem(parentItem.Key, "Child");
|
||||
var childTranslations = new List<IDictionaryTranslation>
|
||||
@@ -104,7 +116,7 @@ namespace Umbraco.Tests.Services
|
||||
new DictionaryTranslation(languageEnGb, "ChildValue")
|
||||
};
|
||||
childItem.Translations = childTranslations;
|
||||
ServiceContext.LocalizationService.Save(childItem);
|
||||
localizationService.Save(childItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
@@ -7,7 +6,7 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<umbPackage>
|
||||
<files />
|
||||
<info>
|
||||
<package>
|
||||
<name>Dictionary-Package</name>
|
||||
<version>1.0</version>
|
||||
<license url="http://www.opensource.org/licenses/mit-license.php">MIT license</license>
|
||||
<url>http://not.available</url>
|
||||
<requirements>
|
||||
<major>3</major>
|
||||
<minor>0</minor>
|
||||
<patch>0</patch>
|
||||
</requirements>
|
||||
</package>
|
||||
<author>
|
||||
<name>Test</name>
|
||||
<website>http://not.available</website>
|
||||
</author>
|
||||
<readme><![CDATA[]]></readme>
|
||||
</info>
|
||||
<DictionaryItems>
|
||||
<DictionaryItem Key="Parent">
|
||||
<Value LanguageId="2" LanguageCultureAlias="nb-NO"><![CDATA[ForelderVerdi]]></Value>
|
||||
<Value LanguageId="3" LanguageCultureAlias="en-GB"><![CDATA[ParentValue]]></Value>
|
||||
<DictionaryItem Key="Child">
|
||||
<Value LanguageId="2" LanguageCultureAlias="nb-NO"><![CDATA[BarnVerdi]]></Value>
|
||||
<Value LanguageId="3" LanguageCultureAlias="en-GB"><![CDATA[ChildValue]]></Value>
|
||||
</DictionaryItem>
|
||||
</DictionaryItem>
|
||||
</DictionaryItems>
|
||||
<Languages>
|
||||
<Language Id="2" CultureAlias="nb-NO" FriendlyName="Norwegian" />
|
||||
<Language Id="3" CultureAlias="en-GB" FriendlyName="English (United Kingdom)" />
|
||||
</Languages>
|
||||
</umbPackage>
|
||||
89
src/Umbraco.Tests.Integration/Services/Importing/ImportResources.Designer.cs
generated
Normal file
89
src/Umbraco.Tests.Integration/Services/Importing/ImportResources.Designer.cs
generated
Normal file
@@ -0,0 +1,89 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Umbraco.Tests.Integration.Services.Importing {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class ImportResources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal ImportResources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Umbraco.Tests.Integration.Services.Importing.ImportResources", typeof(ImportResources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8" ?>
|
||||
///<umbPackage>
|
||||
/// <files />
|
||||
/// <info>
|
||||
/// <package>
|
||||
/// <name>Dictionary-Package</name>
|
||||
/// <version>1.0</version>
|
||||
/// <license url="http://www.opensource.org/licenses/mit-license.php">MIT license</license>
|
||||
/// <url>http://not.available</url>
|
||||
/// <requirements>
|
||||
/// <major>3</major>
|
||||
/// <minor>0</minor>
|
||||
/// <patch>0</patch>
|
||||
/// </requirements>
|
||||
/// </package>
|
||||
/// <author>
|
||||
/// <name>Test</name>
|
||||
/// <website>http://not.available</w [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string Dictionary_Package {
|
||||
get {
|
||||
return ResourceManager.GetString("Dictionary_Package", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="Dictionary_Package" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>dictionary-package.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -4,12 +4,10 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
namespace Umbraco.Tests.Services
|
||||
namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests covering methods in the KeyValueService class.
|
||||
/// This is more of an integration test as it involves multiple layers
|
||||
/// as well as configuration.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
|
||||
@@ -4,10 +4,11 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Configuration.Models;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.Common.Builders;
|
||||
using Umbraco.Tests.Common.Builders.Extensions;
|
||||
using Umbraco.Tests.Integration.Testing;
|
||||
using Umbraco.Tests.Testing;
|
||||
|
||||
@@ -30,13 +31,11 @@ namespace Umbraco.Tests.Integration.Services
|
||||
private int _danishLangId;
|
||||
private int _englishLangId;
|
||||
|
||||
private GlobalSettings _globalSettings;
|
||||
private ILocalizationService LocalizationService => GetRequiredService<ILocalizationService>();
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_globalSettings = new GlobalSettings();
|
||||
CreateTestData();
|
||||
}
|
||||
|
||||
@@ -191,12 +190,14 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Can_Delete_Language()
|
||||
{
|
||||
var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian" };
|
||||
LocalizationService.Save(norwegian, 0);
|
||||
Assert.That(norwegian.HasIdentity, Is.True);
|
||||
var languageId = norwegian.Id;
|
||||
var languageNbNo = new LanguageBuilder()
|
||||
.WithCultureInfo("nb-NO")
|
||||
.Build();
|
||||
LocalizationService.Save(languageNbNo, 0);
|
||||
Assert.That(languageNbNo.HasIdentity, Is.True);
|
||||
var languageId = languageNbNo.Id;
|
||||
|
||||
LocalizationService.Delete(norwegian);
|
||||
LocalizationService.Delete(languageNbNo);
|
||||
|
||||
var language = LocalizationService.GetLanguageById(languageId);
|
||||
Assert.Null(language);
|
||||
@@ -205,12 +206,15 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Can_Delete_Language_Used_As_Fallback()
|
||||
{
|
||||
var danish = LocalizationService.GetLanguageByIsoCode("da-DK");
|
||||
var norwegian = new Language(_globalSettings, "nb-NO") { CultureName = "Norwegian", FallbackLanguageId = danish.Id };
|
||||
LocalizationService.Save(norwegian, 0);
|
||||
var languageId = danish.Id;
|
||||
var languageDaDk = LocalizationService.GetLanguageByIsoCode("da-DK");
|
||||
var languageNbNo = new LanguageBuilder()
|
||||
.WithCultureInfo("nb-NO")
|
||||
.WithFallbackLanguageId(languageDaDk.Id)
|
||||
.Build();
|
||||
LocalizationService.Save(languageNbNo, 0);
|
||||
var languageId = languageDaDk.Id;
|
||||
|
||||
LocalizationService.Delete(danish);
|
||||
LocalizationService.Delete(languageDaDk);
|
||||
|
||||
var language = LocalizationService.GetLanguageById(languageId);
|
||||
Assert.Null(language);
|
||||
@@ -350,10 +354,12 @@ namespace Umbraco.Tests.Integration.Services
|
||||
{
|
||||
// Arrange
|
||||
var isoCode = "en-AU";
|
||||
var language = new Core.Models.Language(_globalSettings, isoCode);
|
||||
var languageEnAu = new LanguageBuilder()
|
||||
.WithCultureInfo(isoCode)
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
LocalizationService.Save(language);
|
||||
LocalizationService.Save(languageEnAu);
|
||||
var result = LocalizationService.GetLanguageByIsoCode(isoCode);
|
||||
|
||||
// Assert
|
||||
@@ -363,12 +369,14 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Save_Language_And_GetLanguageById()
|
||||
{
|
||||
var isoCode = "en-AU";
|
||||
var language = new Core.Models.Language(_globalSettings, isoCode);
|
||||
// Arrange
|
||||
var languageEnAu = new LanguageBuilder()
|
||||
.WithCultureInfo("en-AU")
|
||||
.Build();
|
||||
|
||||
// Act
|
||||
LocalizationService.Save(language);
|
||||
var result = LocalizationService.GetLanguageById(language.Id);
|
||||
LocalizationService.Save(languageEnAu);
|
||||
var result = LocalizationService.GetLanguageById(languageEnAu.Id);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
@@ -377,17 +385,24 @@ namespace Umbraco.Tests.Integration.Services
|
||||
[Test]
|
||||
public void Set_Default_Language()
|
||||
{
|
||||
var language = new Language(_globalSettings, "en-AU") {IsDefault = true};
|
||||
LocalizationService.Save(language);
|
||||
var result = LocalizationService.GetLanguageById(language.Id);
|
||||
var languageEnAu = new LanguageBuilder()
|
||||
.WithCultureInfo("en-AU")
|
||||
.WithIsDefault(true)
|
||||
.Build();
|
||||
LocalizationService.Save(languageEnAu);
|
||||
var result = LocalizationService.GetLanguageById(languageEnAu.Id);
|
||||
|
||||
Assert.IsTrue(result.IsDefault);
|
||||
|
||||
var language2 = new Language(_globalSettings, "en-NZ") {IsDefault = true};
|
||||
LocalizationService.Save(language2);
|
||||
var result2 = LocalizationService.GetLanguageById(language2.Id);
|
||||
var languageEnNz = new LanguageBuilder()
|
||||
.WithCultureInfo("en-NZ")
|
||||
.WithIsDefault(true)
|
||||
.Build();
|
||||
LocalizationService.Save(languageEnNz);
|
||||
var result2 = LocalizationService.GetLanguageById(languageEnNz.Id);
|
||||
|
||||
//re-get
|
||||
result = LocalizationService.GetLanguageById(language.Id);
|
||||
result = LocalizationService.GetLanguageById(languageEnAu.Id);
|
||||
|
||||
Assert.IsTrue(result2.IsDefault);
|
||||
Assert.IsFalse(result.IsDefault);
|
||||
@@ -397,11 +412,13 @@ namespace Umbraco.Tests.Integration.Services
|
||||
public void Deleted_Language_Should_Not_Exist()
|
||||
{
|
||||
var isoCode = "en-AU";
|
||||
var language = new Core.Models.Language(_globalSettings, isoCode);
|
||||
LocalizationService.Save(language);
|
||||
var languageEnAu = new LanguageBuilder()
|
||||
.WithCultureInfo(isoCode)
|
||||
.Build();
|
||||
LocalizationService.Save(languageEnAu);
|
||||
|
||||
// Act
|
||||
LocalizationService.Delete(language);
|
||||
LocalizationService.Delete(languageEnAu);
|
||||
var result = LocalizationService.GetLanguageByIsoCode(isoCode);
|
||||
|
||||
// Assert
|
||||
@@ -410,20 +427,25 @@ namespace Umbraco.Tests.Integration.Services
|
||||
|
||||
public void CreateTestData()
|
||||
{
|
||||
var danish = new Language(_globalSettings, "da-DK") { CultureName = "Danish" };
|
||||
var english = new Language(_globalSettings, "en-GB") { CultureName = "English" };
|
||||
LocalizationService.Save(danish, 0);
|
||||
LocalizationService.Save(english, 0);
|
||||
_danishLangId = danish.Id;
|
||||
_englishLangId = english.Id;
|
||||
var languageDaDk = new LanguageBuilder()
|
||||
.WithCultureInfo("da-DK")
|
||||
.Build();
|
||||
var languageEnGb = new LanguageBuilder()
|
||||
.WithCultureInfo("en-GB")
|
||||
.Build();
|
||||
|
||||
LocalizationService.Save(languageDaDk, 0);
|
||||
LocalizationService.Save(languageEnGb, 0);
|
||||
_danishLangId = languageDaDk.Id;
|
||||
_englishLangId = languageEnGb.Id;
|
||||
|
||||
var parentItem = new DictionaryItem("Parent")
|
||||
{
|
||||
Translations = new List<IDictionaryTranslation>
|
||||
{
|
||||
new DictionaryTranslation(english, "ParentValue"),
|
||||
new DictionaryTranslation(danish, "ForældreVærdi")
|
||||
}
|
||||
{
|
||||
new DictionaryTranslation(languageEnGb, "ParentValue"),
|
||||
new DictionaryTranslation(languageDaDk, "ForældreVærdi")
|
||||
}
|
||||
};
|
||||
LocalizationService.Save(parentItem);
|
||||
_parentItemGuidId = parentItem.Key;
|
||||
@@ -432,10 +454,10 @@ namespace Umbraco.Tests.Integration.Services
|
||||
var childItem = new DictionaryItem(parentItem.Key, "Child")
|
||||
{
|
||||
Translations = new List<IDictionaryTranslation>
|
||||
{
|
||||
new DictionaryTranslation(english, "ChildValue"),
|
||||
new DictionaryTranslation(danish, "BørnVærdi")
|
||||
}
|
||||
{
|
||||
new DictionaryTranslation(languageEnGb, "ChildValue"),
|
||||
new DictionaryTranslation(languageDaDk, "BørnVærdi")
|
||||
}
|
||||
};
|
||||
LocalizationService.Save(childItem);
|
||||
_childItemGuidId = childItem.Key;
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
<None Remove="Views\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Services\Importing\Dictionary-Package.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Services\Importing\Dictionary-Package.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Examine.Lucene" Version="2.0.0-alpha.20200128.15" />
|
||||
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.3.3" />
|
||||
@@ -59,4 +67,20 @@
|
||||
<Folder Include="Umbraco\logs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Services\Importing\ImportResources.Designer.cs">
|
||||
<DependentUpon>ImportResources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Services\Importing\ImportResources.resx">
|
||||
<SubType>Designer</SubType>
|
||||
<LastGenOutput>ImportResources.Designer.cs</LastGenOutput>
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Umbraco.Tests.UnitTests.Umbraco.Tests.Common.Builders
|
||||
var builder = new LanguageBuilder();
|
||||
|
||||
var expected = CultureInfo.GetCultureInfo("en-GB");
|
||||
|
||||
// Act
|
||||
var language = builder
|
||||
.WithCultureInfo(expected.Name)
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
</DictionaryItem>
|
||||
</DictionaryItems>
|
||||
<Languages>
|
||||
<Language Id="2" CultureAlias="nb-NO" FriendlyName="Norwegian" />
|
||||
<Language Id="2" CultureAlias="nb-NO" FriendlyName="Norwegian Bokmål (Norway)" />
|
||||
<Language Id="3" CultureAlias="en-GB" FriendlyName="English (United Kingdom)" />
|
||||
</Languages>
|
||||
</umbPackage>
|
||||
</umbPackage>
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
@@ -171,7 +171,6 @@
|
||||
<Compile Include="Routing\GetContentUrlsTests.cs" />
|
||||
<Compile Include="Services\ContentServiceTagsTests.cs" />
|
||||
<Compile Include="Services\ContentTypeServiceVariantsTests.cs" />
|
||||
<Compile Include="Services\EntityXmlSerializerTests.cs" />
|
||||
<Compile Include="Services\MemberGroupServiceTests.cs" />
|
||||
<Compile Include="Services\MediaTypeServiceTests.cs" />
|
||||
<Compile Include="TestHelpers\RandomIdRamDirectory.cs" />
|
||||
@@ -486,4 +485,4 @@
|
||||
<Message Text="NuGetPackageFolders: $(NuGetPackageFolders)" Importance="high" />
|
||||
<Message Text="NuGetPackages: $(NuGetPackages)" Importance="high" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user