public void MainDbTests()
		{
			var dbFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "mysequredb.db3");
			var platform = new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS();
			ISecureDatabase database = new MyDatabase(platform, dbFilePath);
			var keySeed = "my very very secure key seed. You should use PCLCrypt strong random generator for this";

			var user = new SampleUser()
			{
				Name = "Has AlTaiar",
				Password = "******",
				Bio = "Very cool guy :) ",
				Id = Guid.NewGuid().ToString()
			};

			var inserted = database.SecureInsert<SampleUser>(user, keySeed);
			Assert.AreEqual(1, inserted);
			Assert.AreNotEqual("very secure password :)", user.Password);


			var userFromDb = database.SecureGet<SampleUser>(user.Id, keySeed);
			Assert.IsNotNull(userFromDb);
			Assert.AreEqual("Has AlTaiar",  userFromDb.Name);
			Assert.AreEqual("very secure password :)", userFromDb.Password);


			var directAccessDb = (SQLiteConnection)database;
			var userAccessedDirectly = directAccessDb.Query<SampleUser>("SELECT * FROM SampleUser").FirstOrDefault();

			Assert.IsNotNull(userAccessedDirectly);
			Assert.AreEqual("Has AlTaiar", userAccessedDirectly.Name);
			Assert.AreNotEqual("very secure password :)", userAccessedDirectly.Password);
		}
Esempio n. 2
0
        public void MainDbTests()
        {
            var             dbFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "mysequredb.db3");
            var             platform   = new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS();
            ISecureDatabase database   = new MyDatabase(platform, dbFilePath);
            var             keySeed    = "my very very secure key seed. You should use PCLCrypt strong random generator for this";

            var user = new SampleUser()
            {
                Name     = "Has AlTaiar",
                Password = "******",
                Bio      = "Very cool guy :) ",
                Id       = Guid.NewGuid().ToString()
            };

            var inserted = database.SecureInsert <SampleUser>(user, keySeed);

            Assert.AreEqual(1, inserted);
            Assert.AreNotEqual("very secure password :)", user.Password);


            var userFromDb = database.SecureGet <SampleUser>(user.Id, keySeed);

            Assert.IsNotNull(userFromDb);
            Assert.AreEqual("Has AlTaiar", userFromDb.Name);
            Assert.AreEqual("very secure password :)", userFromDb.Password);


            var directAccessDb       = (SQLiteConnection)database;
            var userAccessedDirectly = directAccessDb.Query <SampleUser>("SELECT * FROM SampleUser").FirstOrDefault();

            Assert.IsNotNull(userAccessedDirectly);
            Assert.AreEqual("Has AlTaiar", userAccessedDirectly.Name);
            Assert.AreNotEqual("very secure password :)", userAccessedDirectly.Password);
        }