Kooboo.Commerce.Multilingual.Storage.CachedTranslactionStore.AddOrUpdate C# (CSharp) Méthode

AddOrUpdate() public méthode

public AddOrUpdate ( System culture, EntityKey key, IEnumerable propertyTranslations ) : void
culture System
key EntityKey
propertyTranslations IEnumerable
Résultat void
        public void AddOrUpdate(System.Globalization.CultureInfo culture, EntityKey key, IEnumerable<PropertyTranslation> propertyTranslations)
        {
            _underlyingStore.AddOrUpdate(culture, key, propertyTranslations);
            UpdateCache(culture, new List<EntityTransaltion> { new EntityTransaltion(culture.Name, key, propertyTranslations) });
        }

Usage Example

        public void should_refresh_cache_on_update()
        {
            var zh_CN = CultureInfo.GetCultureInfo("zh-CN");
            var translationsInDb = new [] { CreateBrandTranslation(1, zh_CN, "Translated Brand1") };

            var underlyingStoreMock = new Mock<ITranslationStore>();
            underlyingStoreMock.Setup(it => it.Find(zh_CN, new[] { EntityKey.Create<Brand>(1) }))
                               .Returns(translationsInDb);

            underlyingStoreMock.Setup(it => it.AddOrUpdate(zh_CN, EntityKey.Create<Brand>(1), It.IsAny<IEnumerable<PropertyTranslation>>()))
                               .Callback(() =>
                               {
                                   translationsInDb[0].PropertyTranslations[0].TranslatedText = "Translated Brand1 (Update)";
                               });

            var store = new CachedTranslactionStore(underlyingStoreMock.Object, new [] { typeof(Brand) });

            var translation = store.Find(zh_CN, EntityKey.Create<Brand>(1));
            Assert.Equal("Translated Brand1", translation.PropertyTranslations[0].TranslatedText);

            store.AddOrUpdate(zh_CN, EntityKey.Create<Brand>(1), new List<PropertyTranslation>
            {
                new PropertyTranslation("Name", "Brand1", "Translated Brand1 (Update)")
            });

            Assert.Equal("Translated Brand1 (Update)", translationsInDb[0].PropertyTranslations[0].TranslatedText);

            translation = store.Find(zh_CN, EntityKey.Create<Brand>(1));
            Assert.Equal("Translated Brand1 (Update)", translation.PropertyTranslations[0].TranslatedText);
        }