public async Task Insert()
        {
            const string key = "key";

            Assert.That(async () => await _cache.Insert(null, "value"),
                Throws.Exception
                    .TypeOf<ArgumentNullException>()
                    .With.Property("ParamName")
                    .EqualTo(key));

            var person = new Person() {Name = "john", Age = 19};
            Assert.That(async () => await _cache.Insert(key, person),
                Is.EqualTo(1));

            var restoredPerson = await _cache.Get<Person>(key);
            Assert.That(restoredPerson.Name, Is.EqualTo(person.Name));
            Assert.That(restoredPerson.Age, Is.EqualTo(person.Age));

            // re-inserting with same key overwrites old value.
            var anotherPerson = new Person() {Name = "mike", Age = 30};
            Assert.That(async () => await _cache.Insert(key, anotherPerson),
                Is.EqualTo(1));

            restoredPerson = await _cache.Get<Person>(key);
            Assert.That(restoredPerson.Name, Is.EqualTo(anotherPerson.Name));
            Assert.That(restoredPerson.Age, Is.EqualTo(anotherPerson.Age));
        }
 protected void InitializeDatabase()
 {
     var dbName = "people";
     var conn = new SQLiteAsyncConnection (dbName);
     conn.CreateTableAsync<Person> ().ContinueWith ((task) =>
     {
         foreach (var i in Enumerable.Range (0,1000)) {
             var p = new Person ("Bob");
             conn.InsertAsync (p).ContinueWith ((task2) =>
             {
                 var id = p.Id;
                 this.InvokeOnMainThread (delegate {
                     this.recordCount.Text = id.ToString ();
                     this.recordCount.SetNeedsDisplay ();
                 }
                 );
             }
             );
         }
     }
     );
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.myButton);

            string folder =  System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);

            var db = new SQLiteConnection (System. IO. Path. Combine (folder, "myDb. db"));

            button.Click  += delegate{

                Person Person = new Person{ Name = FindViewById<EditText> (Resource.Id.editText1).Text };

                int id = db.Insert(Person);

                FindViewById<TextView> (Resource.Id.textView2).Text = "Inserted with success: id "+id;

            };

            Button deleteButton = FindViewById<Button> (Resource.Id.button2);

            deleteButton.Click += delegate {

                var DeletedId = db.Delete<Person> (Convert.ToInt32(FindViewById<EditText> (Resource.Id.editText1).Text));

                FindViewById<TextView> (Resource.Id.textView2).Text = "Id " + Dele   	tedId +  "Deleted With Success";

            };

            db.Commit();
            db.Rollback();
        }
        public async Task Get()
        {

            const string key = "key";
            const string notExistingKey = "unkey";

            Assert.That(async () => await _cache.Get<Person>(key:null),
                Throws.Exception
                    .TypeOf<ArgumentNullException>()
                    .With.Property("ParamName")
                    .EqualTo(key));

            Assert.That(async () => await _cache.Get<Person>(notExistingKey),
                Throws.Exception
                    .TypeOf<KeyNotFoundException>()
                    .With.Message
                    .EqualTo(key));

            var person = new Person() {Name = "john", Age = 19};
            Assert.That(async () => await _cache.Insert(key, person),
                Is.EqualTo(1));

            var restoredPerson = await _cache.Get<Person>(key);
            Assert.That(restoredPerson.Name, Is.EqualTo(person.Name));
            Assert.That(restoredPerson.Age, Is.EqualTo(person.Age));
        }
        public async Task Vacuum()
        {

            const string vacuumMeKey1 = "key1";
            const string vacuumMeKey2 = "key2";
            const string doNotVacuumMeKey = "key3";

            Assert.That(async () => await _cache.Vacuum(), Is.EqualTo(0));

            var person = new Person() {Name = "john", Age = 19};
            await _cache.Insert(vacuumMeKey1, person, DateTime.Now);
            await _cache.Insert(vacuumMeKey2, person, DateTime.Now.AddSeconds(-1));
            await _cache.Insert(doNotVacuumMeKey, person, DateTime.Now.AddSeconds(1));

            Assert.That(async () => await _cache.Vacuum(), Is.EqualTo(2));

            Assert.That(async () => await _cache.Get<Person>(vacuumMeKey1),
                Throws.Exception
		.TypeOf<KeyNotFoundException>());

            Assert.That(async () => await _cache.Get<Person>(vacuumMeKey2),
                Throws.Exception.
		TypeOf<KeyNotFoundException>());

            Assert.That(async () => await _cache.Get<Person>(doNotVacuumMeKey), Is.Not.Null);
        }
        public async Task Invalidate()
        {
            const string key = "key";
            const string notExistingKey = "unkey";

            Assert.That(async () => await _cache.Invalidate<Person>(key:null),
                Throws.Exception
                    .TypeOf<ArgumentNullException>()
                    .With.Property("ParamName")
                    .EqualTo(key));

            Assert.That(async () => await _cache.Invalidate<Person>(notExistingKey),
                Throws.Exception
                    .TypeOf<KeyNotFoundException>()
                    .With.Message
                    .EqualTo(key));

            var person = new Person() {Name = "john", Age = 19};
            Assert.That(async () => await _cache.Insert(key, person),
                Is.EqualTo(1));

            Assert.That(async () => await _cache.Invalidate<Address>(key),
                Throws.TypeOf<SimpleObjectCacheTypeMismatchException>());

            var deleted = await _cache.Invalidate<Person>(key);
            Assert.That(deleted, Is.EqualTo(1));

            Assert.That(async () => await _cache.Get<Person>(key),
                Throws.Exception
                    .TypeOf<KeyNotFoundException>()
                    .With.Message
                    .EqualTo(key));
        }
        public async Task GetCreatedAt()
        {

            const string key = "key";
            const string notExistingKey = "unkey";

            Assert.That(async () => await _cache.GetCreatedAt(key:null),
                Throws.Exception
                    .TypeOf<ArgumentNullException>()
                    .With.Property("ParamName")
                    .EqualTo(key));

            var person = new Person() {Name = "john", Age = 19};
            Assert.That(async () => await _cache.Insert(key, person),
                Is.EqualTo(1));

            var createdAt = await _cache.GetCreatedAt(key);
            Assert.That(createdAt.Value.UtcDateTime, Is.EqualTo(DateTimeOffset.Now.UtcDateTime).Within(1).Seconds);

            Assert.That(async () => await _cache.GetCreatedAt(notExistingKey),
                Is.Null);
        }