Example #1
0
        private string CreateMailHeaderAndInsertIntoDb()
        {
            string uid = _randomizer.Next(1, 100).ToString();

            using (var storage = new LiteDbMailHeaderEntityStorage(_dbFilepath))
            {
                storage.Insert(new List <MailHeaderEntity>()
                {
                    new MailHeaderEntity()
                    {
                        Uid            = uid,
                        MailFromEntity = new MailFromEntity()
                        {
                            Name = "TestName", Address = "*****@*****.**"
                        }
                    }
                });
            }

            return(uid);
        }
Example #2
0
        public void TestLiteDbMailHeaderStorageMethods()
        {
            // Create first mailHeaderEntity.
            string uid1 = _randomizer.Next(1, 100).ToString();
            var    mailHeaderEntity1 = CreateMailHeader(uid1);

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

            using (var storage = new LiteDbMailHeaderEntityStorage(_dbFilepath))
            {
                // Insert.
                storage.Insert(mailHeaderEntity1);

                // Upsert.
                storage.Upsert(mailHeaderEntity2);

                // 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 newsubj = "NewSubject";
                mailHeaderEntity2[0].Subject = newsubj;

                // Update.
                storage.Update(mailHeaderEntity2);

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

                if (mheone2.Subject != newsubj)
                {
                    Assert.Fail();
                }
            }
        }