Adding Export of DictionaryItems including test

This commit is contained in:
Morten Christensen
2014-01-10 13:08:33 +01:00
parent 6b205bd725
commit 6e344f335e
2 changed files with 95 additions and 28 deletions

View File

@@ -1,41 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Tests.Services.Importing;
using Umbraco.Tests.TestHelpers.Entities;
namespace Umbraco.Tests.Services
{
//[TestFixture]
//public class PackagingServiceTests : BaseServiceTest
//{
// [Test]
// public void Export_Content()
// {
// var yesNo = DataTypesResolver.Current.GetById(new Guid(Constants.PropertyEditors.TrueFalse));
// var txtField = DataTypesResolver.Current.GetById(new Guid(Constants.PropertyEditors.Textbox));
[TestFixture]
public class PackagingServiceTests : BaseServiceTest
{
[SetUp]
public override void Initialize()
{
base.Initialize();
}
// var contentWithDataType = MockedContentTypes.CreateSimpleContentType(
// "test",
// "Test",
// new PropertyTypeCollection(
// new PropertyType[]
// {
// new PropertyType(new DataTypeDefinition(-1, txtField.Id)
// {
// Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext
// }),
// new PropertyType(new DataTypeDefinition(-1, yesNo.Id)
// {
// Name = "Testing intfield", DatabaseType = DataTypeDatabaseType.Integer
// })
// }));
[TearDown]
public override void TearDown()
{
base.TearDown();
}
// var content = MockedContent.CreateSimpleContent(contentWithDataType);
// content.Name = "Test";
[Test]
public void PackagingService_Can_Export_DictionaryItems()
{
// Arrange
CreateTestData();
var dictionaryItem = ServiceContext.LocalizationService.GetDictionaryItemByKey("Parent");
// var exported = ServiceContext.PackagingService.Export(content);
var newPackageXml = XElement.Parse(ImportResources.Dictionary_Package);
var dictionaryItemsElement = newPackageXml.Elements("DictionaryItems").First();
// }
//}
// Act
var xml = ServiceContext.PackagingService.Export(new []{dictionaryItem});
// Assert
Assert.That(xml.ToString(), Is.EqualTo(dictionaryItemsElement.ToString()));
}
public void CreateTestData()
{
var languageNbNo = new Language("nb-NO") { CultureName = "nb-NO" };
ServiceContext.LocalizationService.Save(languageNbNo);
var languageEnGb = new Language("en-GB") { CultureName = "en-GB" };
ServiceContext.LocalizationService.Save(languageEnGb);
var parentItem = new DictionaryItem("Parent");
var parentTranslations = new List<IDictionaryTranslation>
{
new DictionaryTranslation(languageNbNo, "ForelderVerdi"),
new DictionaryTranslation(languageEnGb, "ParentValue")
};
parentItem.Translations = parentTranslations;
ServiceContext.LocalizationService.Save(parentItem);
var childItem = new DictionaryItem(parentItem.Key, "Child");
var childTranslations = new List<IDictionaryTranslation>
{
new DictionaryTranslation(languageNbNo, "BarnVerdi"),
new DictionaryTranslation(languageEnGb, "ChildValue")
};
childItem.Translations = childTranslations;
ServiceContext.LocalizationService.Save(childItem);
}
}
}