Exemplo n.º 1
0
        /// <summary>
        /// Convert a language into CSV format (e.g. for export)
        /// </summary>
        /// <param name="language"></param>
        /// <returns></returns>
        public string ToCsv(Language language)
        {
            var csv = new StringBuilder();

            foreach (var resource in _localizationRepository.AllLanguageResources(language.Id))
            {
                csv.AppendFormat("{0},{1}", resource.LocaleResourceKey.Name, resource.ResourceValue);
                csv.AppendLine();
            }

            return(csv.ToString());
        }
Exemplo n.º 2
0
        public void ExportCsv()
        {
            var testGuid = Guid.NewGuid();

            var resourceKey1 = new LocaleResourceKey
            {
                DateAdded = DateTime.UtcNow,
                Id        = Guid.NewGuid(),
                Name      = "testKey1",
                Notes     = "test notes"
            };

            var resourceValue1 = new LocaleStringResource
            {
                LocaleResourceKey = resourceKey1,
                ResourceValue     = "testValue1"
            };

            var resourceKey2 = new LocaleResourceKey
            {
                DateAdded = DateTime.UtcNow,
                Id        = Guid.NewGuid(),
                Name      = "testKey2",
                Notes     = "test notes"
            };

            var resourceValue2 = new LocaleStringResource
            {
                LocaleResourceKey = resourceKey2,
                ResourceValue     = "testValue2"
            };

            var language = new Language {
                Id = testGuid, LanguageCulture = "en-GB", Name = "TestLanguage"
            };

            _localizationRepositorySub.AllLanguageResources(testGuid).Returns(new List <LocaleStringResource> {
                resourceValue1, resourceValue2
            });
            _localizationRepositorySub.Get(testGuid).Returns(language);

            var csv = _localizationService.ToCsv(language);

            Assert.AreEqual(csv, "testKey1,testValue1\r\ntestKey2,testValue2\r\n");
        }