Пример #1
0
        private string CreateMailContentAndInsertIntoDb(string uid = null)
        {
            if (uid == null)
            {
                uid = _randomizer.Next(101, 200).ToString();
            }

            using (var storage = new LiteDbMailContentEntityStorage(_dbFilepath))
            {
                storage.Insert(new List <MailContentEntity>()
                {
                    new MailContentEntity()
                    {
                        Uid        = uid,
                        Date       = DateTime.Now,
                        Text       = "Test email text.",
                        Html       = "<html><body><b>Test email html text.</b></body></html>",
                        IsComplete = true,
                    }
                });
            }

            return(uid);
        }
Пример #2
0
        public void TestLiteDbMailContentStorageMethods()
        {
            // Create first mailHeaderEntity.
            string uid1 = _randomizer.Next(1, 100).ToString();
            var    mailContentEntity1 = CreateMailContent(uid1);

            // Create second mailHeaderEntity.
            string uid2 = _randomizer.Next(1, 100).ToString();
            var    mailContentEntity2 = CreateMailContent(uid2);

            using (var storage = new LiteDbMailContentEntityStorage(_dbFilepath))
            {
                // Insert.
                storage.Insert(mailContentEntity1);

                // Upsert.
                storage.Upsert(mailContentEntity2);

                // Check count == 2.
                if (storage.Count() != 2)
                {
                    Assert.Fail();
                }

                // Find.
                var mhe = storage.FindOne(x => x.Uid == uid1);

                // Check if found and with correct uid.
                if (mhe == null || mhe.Uid != uid1)
                {
                    Assert.Fail();
                }

                // Test find many should be two.
                var mhemany = storage.FindMany(x => x.Uid == uid1 || x.Uid == uid2).ToList();
                if (mhemany.Count != 2)
                {
                    Assert.Fail();
                }

                // Try to delete.
                storage.Delete(x => x.Uid == uid1);

                // Check if delete and not found.
                var mheone = storage.FindOne(x => x.Uid == uid1);
                if (mheone != null)
                {
                    Assert.Fail();
                }

                // Check count == 1.
                if (storage.Count() != 1)
                {
                    Assert.Fail();
                }

                var mheall = storage.FindAll().ToList();
                if (mheall.Count != 1)
                {
                    Assert.Fail();
                }

                if (!storage.Exists(x => x.Uid == uid2))
                {
                    Assert.Fail();
                }

                // Change subject to a new one.
                string newtxt = "NewText";
                mailContentEntity2[0].Text = newtxt;

                // Update.
                storage.Update(mailContentEntity2);

                var mheone2 = storage.FindOne(x => x.Uid == uid2);
                if (mheone2 == null)
                {
                    Assert.Fail();
                }

                if (mheone2.Text != newtxt)
                {
                    Assert.Fail();
                }
            }
        }