Example #1
0
        public void Delete_Localizable_Entity_In_Default_Language_Delete_AllLocalizations_And_Entity()
        {
            using (var db = new TestDataContext())
            {
                db.ReCreate();
                var entity = new LocalizedEntity {
                    NotLocalizedText = "NotLocalizedText", LocalizedText = "LocalizedText"
                };
                db.LocalizedEntities.Add(entity);
                db.SaveChanges();
                entity = db.LocalizedEntities.First();
                entity.LanguageCode  = "cs";
                entity.LocalizedText = "new localized text";
                db.SaveChanges();
            }
            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.First();
                entity.ArchivedOnUtc = DateTime.Now;                 // force delete
                db.LocalizedEntities.Remove(entity);
                db.SaveChanges();
            }

            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.FirstOrDefault();

                Assert.IsNull(entity);
                Assert.IsTrue(!db.Localizations.Any());
            }
        }
Example #2
0
        public void Delete_Localizable_Entity_In_NonDefault_Language_Delete_Only_Specific_Localizations()
        {
            using (var db = new TestDataContext())
            {
                db.ReCreate();
                var entity = new LocalizedEntity {
                    NotLocalizedText = "NotLocalizedText", LocalizedText = "LocalizedText"
                };
                db.LocalizedEntities.Add(entity);
                db.SaveChanges();
                entity = db.LocalizedEntities.First();
                entity.LanguageCode  = "cs";
                entity.LocalizedText = "new localized text";
                db.SaveChanges();
            }
            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.First();
                entity.LanguageCode  = "cs";
                entity.ArchivedOnUtc = DateTime.Now;
                db.LocalizedEntities.Remove(entity);
                db.SaveChanges();
            }

            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.First();

                Assert.AreEqual(1, entity.Id);
                Assert.AreEqual("NotLocalizedText", entity.NotLocalizedText);
                Assert.AreEqual("LocalizedText", entity.LocalizedText);
                Assert.IsTrue(!db.Localizations.Any());
            }
        }
Example #3
0
        public void Add_Localizable_Entity_Preserve_Original_And_Loads_Localized()
        {
            using (var db = new TestDataContext())
            {
                db.ReCreate();
                var entity = new LocalizedEntity {
                    NotLocalizedText = "NotLocalizedText", LocalizedText = "LocalizedText"
                };

                db.LocalizedEntities.Add(entity);
                db.SaveChanges();
            }

            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.First();
                entity.LanguageCode  = "cs";
                entity.LocalizedText = "new localized text";
                db.SaveChanges();
            }

            using (var db = new TestDataContext())
            {
                var entity = db.LocalizeEntity(db.LocalizedEntities.First(), "cs");

                Assert.AreEqual(1, entity.Id);
                Assert.AreEqual("NotLocalizedText", entity.NotLocalizedText);
                Assert.AreEqual("new localized text", entity.LocalizedText);
            }
        }
Example #4
0
        public void Add_Localizable_Entity_Does_Add_Localizations()
        {
            using (var db = new TestDataContext())
            {
                db.ReCreate();
                var entity = new LocalizedEntity {
                    NotLocalizedText = "NotLocalizedText", LocalizedText = "LocalizedText"
                };

                db.LocalizedEntities.Add(entity);
                db.SaveChanges();
            }

            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.First();
                entity.LanguageCode  = "cs";
                entity.LocalizedText = "new localized text";
                db.SaveChanges();
            }

            using (var db = new TestDataContext())
            {
                var entity = db.LocalizedEntities.First();

                Assert.IsTrue(db.LocalizedEntities.Count() == 1);
                Assert.IsTrue(db.Localizations.Count() == 1);
                Assert.IsTrue(db.Localizations.Count(x => x.EntityName == typeof(LocalizedEntity).FullName && x.EntityPkValue == entity.Id) == 1);
                Assert.IsTrue(db.Localizations.Single(x => x.EntityName == typeof(LocalizedEntity).FullName && x.EntityPkValue == entity.Id && x.EntityPropertyName == "LocalizedText").Text == "new localized text");
                Assert.AreEqual("NotLocalizedText", entity.NotLocalizedText);
                Assert.AreEqual("LocalizedText", entity.LocalizedText);
                Assert.AreEqual(1, entity.Id);
            }
        }
Example #5
0
        public void Add_Localizable_Entity_In_NonDefault_Language_Throws_NotSupportedException()
        {
            using (var db = new TestDataContext())
            {
                db.ReCreate();
                var entity = new LocalizedEntity {
                    NotLocalizedText = "NotLocalizedText", LocalizedText = "LocalizedText", LanguageCode = "cs"
                };

                db.LocalizedEntities.Add(entity);
                db.SaveChanges();                 // -> shoud throw exception...
            }
        }
Example #6
0
        public void Add_Localizable_Entity_In_Default_Language_Does_Not_Add_Localizations()
        {
            using (var db = new TestDataContext())
            {
                db.ReCreate();
                var entity = new LocalizedEntity {
                    NotLocalizedText = "NotLocalizedText", LocalizedText = "LocalizedText"
                };

                db.LocalizedEntities.Add(entity);
                var entityLoaded = db.SaveAndLoadLocalizedEntity(entity);

                Assert.AreSame(entity, entityLoaded);
                Assert.IsTrue(!db.Localizations.Any());
            }
        }