Exemplo n.º 1
0
        public void Initialize()
        {
            Insight.Instance = new TestInsight();
            int i = 0;

            while (i < 10) // Will always delete the first 10 databases no matter what
            {
                while (ChadderSQLMainDB.Exists(i++).Result)
                {
                    ChadderSQLMainDB.clearData(i - 1).Wait();
                }
            }
        }
Exemplo n.º 2
0
        public async Task TestSplashScreen()
        {
            await ChadderSQLMainDB.clearData(0);

            var random  = new Random();
            var source1 = CreateSource(0);
            var name    = string.Format("AutoTest{0}", random.Next());

            Assert.AreEqual(ChadderError.OK, await source1.CreateUser(name));

            var source2 = CreateSource(0);
            var defUser = await source2.GetDefaultUser();

            Assert.IsNotNull(defUser);
            Assert.AreEqual(defUser.UserId, source1.db.LocalUser.UserId);
            Assert.AreEqual(ChadderError.OK, await source2.StartUser(defUser));
            Assert.AreEqual(ChadderError.OK, await source2.LoadUser(null));
        }
Exemplo n.º 3
0
        public async Task <ChadderError> DeleteDevice()
        {
            if (await DeviceExists() == false)
            {
                return(ChadderError.OK);
            }
            var request = new DeleteDeviceParameter()
            {
                DeviceId = db.LocalDevice.DeviceId
            };
            await request.Sign(db.LocalDevice.PrivateKeyBook.GetMaster());

            var result = await Session.PostRequestAPI <BasicResponse>(Urls.DeleteDevice, request);

            if (result.Error == ChadderError.OK)
            {
                await ChadderSQLMainDB.clearData(InstanceId);
            }
            return(result.Error);
        }
Exemplo n.º 4
0
        public async Task MainSqlDatabase()
        {
            var factory    = new Chadder.Data.Keys.ECDSASimpleFactory();
            var deviceInfo = new ChadderLocalDeviceInfo()
            {
                DeviceId           = Guid.NewGuid().ToString(),
                NotificationHandle = Guid.NewGuid().ToString(),
                PrivateKeyBookData = (await factory.GenerateBook()).Serialize()
            };
            var user = new ChadderLocalUserRecord()
            {
                Name        = "Test name",
                UserId      = Guid.NewGuid().ToString(),
                DatabaseKey = await CryptoHelper.CreateRandomData(32)
            };

            using (var mainSql = await ChadderSQLMainDB.GetDatabase(0))
            {
                await mainSql.InsertAsync(deviceInfo);

                await mainSql.InsertAsync(user);
            }
            using (var mainSql = await ChadderSQLMainDB.GetDatabase(0))
            {
                var device2 = await mainSql.GetDevice();

                Assert.AreEqual(deviceInfo.DeviceId, device2.DeviceId);
                Assert.AreEqual(deviceInfo.NotificationHandle, device2.NotificationHandle);
                Assert.IsTrue(deviceInfo.PrivateKeyBookData.SequenceEqual(device2.PrivateKeyBookData));

                var user2 = await mainSql.Table <ChadderLocalUserRecord>().FirstOrDefaultAsync();

                Assert.AreEqual(user.Name, user2.Name);
                Assert.AreEqual(user.UserId, user2.UserId);
                Assert.IsTrue(user.DatabaseKey.SequenceEqual(user2.DatabaseKey));
            }
            await ChadderSQLMainDB.clearData(0);

            System.IO.File.Delete(ChadderSQLMainDB.GetFilePath(0));
            Assert.IsFalse(System.IO.File.Exists(ChadderSQLMainDB.GetFilePath(0)));
        }