public void Using_XDocument_Gets_All_Stored_Values()
        {
            var culture    = CultureInfo.GetCultureInfo("en-US");
            var txtService = new LocalizedTextService(
                new Dictionary <CultureInfo, Lazy <XDocument> >
            {
                {
                    culture, new Lazy <XDocument>(() => new XDocument(
                                                      new XElement(
                                                          "language",
                                                          new XElement("area", new XAttribute("alias", "testArea1"),
                                                                       new XElement("key", new XAttribute("alias", "testKey1"), "testValue1"),
                                                                       new XElement("key", new XAttribute("alias", "testKey2"), "testValue2")),
                                                          new XElement("area", new XAttribute("alias", "testArea2"),
                                                                       new XElement("key", new XAttribute("alias", "blah1"), "blahValue1"),
                                                                       new XElement("key", new XAttribute("alias", "blah2"), "blahValue2")))))
                }
            }, s_loggerFactory.CreateLogger <LocalizedTextService>());

            IDictionary <string, string> result = txtService.GetAllStoredValues(culture);

            Assert.AreEqual(4, result.Count());
            Assert.AreEqual("testArea1/testKey1", result.ElementAt(0).Key);
            Assert.AreEqual("testArea1/testKey2", result.ElementAt(1).Key);
            Assert.AreEqual("testArea2/blah1", result.ElementAt(2).Key);
            Assert.AreEqual("testArea2/blah2", result.ElementAt(3).Key);
            Assert.AreEqual("testValue1", result["testArea1/testKey1"]);
            Assert.AreEqual("testValue2", result["testArea1/testKey2"]);
            Assert.AreEqual("blahValue1", result["testArea2/blah1"]);
            Assert.AreEqual("blahValue2", result["testArea2/blah2"]);
        }
示例#2
0
 public void OptimizedDictGetAll()
 {
     for (int i = 0; i < 10000; i++)
     {
         var result = _optimizedDict.GetAllStoredValues(culture);
     }
 }
示例#3
0
 public void Setup()
 {
     culture            = CultureInfo.GetCultureInfo("en-US");
     _dictionaryService = GetDictionaryLocalizedTextService(culture);
     _xmlService        = GetXmlService(culture);
     _optimized         = GetOptimizedService(culture);
     _optimizedDict     = GetOptimizedServiceDict(culture);
     var result1 = _dictionaryService.Localize("language", culture);
     var result2 = _xmlService.Localize("language", culture);
     var result3 = _dictionaryService.GetAllStoredValues(culture);
     var result4 = _xmlService.GetAllStoredValues(culture);
     var result5 = _optimized.GetAllStoredValues(culture);
     var result6 = _xmlService.GetAllStoredValues(culture);
     var result7 = _optimized.GetAllStoredValuesByAreaAndAlias(culture);
 }
示例#4
0
        public void Using_XDocument_Gets_All_Stored_Values_With_Duplicates()
        {
            var culture    = CultureInfo.GetCultureInfo("en-US");
            var txtService = new LocalizedTextService(
                new Dictionary <CultureInfo, Lazy <XDocument> >
            {
                {
                    culture, new Lazy <XDocument>(() => new XDocument(
                                                      new XElement("language",
                                                                   new XElement("area", new XAttribute("alias", "testArea1"),
                                                                                new XElement("key", new XAttribute("alias", "testKey1"), "testValue1"),
                                                                                new XElement("key", new XAttribute("alias", "testKey1"), "testValue1")))))
                }
            }, Mock.Of <ILogger>());

            var result = txtService.GetAllStoredValues(culture);

            Assert.AreEqual(1, result.Count());
        }
    public void Using_Dictionary_Gets_All_Stored_Values()
    {
        var culture    = CultureInfo.GetCultureInfo("en-US");
        var txtService = new LocalizedTextService(
            new Dictionary <CultureInfo, Lazy <IDictionary <string, IDictionary <string, string> > > >
        {
            {
                culture,
                new Lazy <IDictionary <string, IDictionary <string, string> > >(() =>
                                                                                new Dictionary <string, IDictionary <string, string> >
                {
                    {
                        "testArea1",
                        new Dictionary <string, string> {
                            { "testKey1", "testValue1" }, { "testKey2", "testValue2" }
                        }
                    },
                    {
                        "testArea2",
                        new Dictionary <string, string> {
                            { "blah1", "blahValue1" }, { "blah2", "blahValue2" }
                        }
                    },
                })
            },
        },
            s_loggerFactory.CreateLogger <LocalizedTextService>());

        var result = txtService.GetAllStoredValues(culture);

        Assert.AreEqual(4, result.Count);
        Assert.AreEqual("testArea1/testKey1", result.ElementAt(0).Key);
        Assert.AreEqual("testArea1/testKey2", result.ElementAt(1).Key);
        Assert.AreEqual("testArea2/blah1", result.ElementAt(2).Key);
        Assert.AreEqual("testArea2/blah2", result.ElementAt(3).Key);
        Assert.AreEqual("testValue1", result["testArea1/testKey1"]);
        Assert.AreEqual("testValue2", result["testArea1/testKey2"]);
        Assert.AreEqual("blahValue1", result["testArea2/blah1"]);
        Assert.AreEqual("blahValue2", result["testArea2/blah2"]);
    }