コード例 #1
0
        public App()
        {
            InitializeComponent();

            switch (datastore)
            {
            case DataStoreTypes.Mock:
                DependencyService.Register <MockDataStore>();
                break;

            case DataStoreTypes.Azure:
                //AzureBackendUrl = DeviceInfo.Platform == DevicePlatform.Android ? "https://10.0.2.2:44379" : "https://localhost:44379";
                AzureBackendUrl = "https://crossplatformpoc.azurewebsites.net";
                DependencyService.Register <AzureDataStore>();
                break;

            case DataStoreTypes.Sqlite:
                Debug.WriteLine($"Database located at: {SqliteDbPath}");
                Repository = new PocRepository(SqliteDbPath);
                DependencyService.Register <SqliteDataStore>();
                break;

            default:
                break;
            }


            MainPage = new MainPage();
        }
コード例 #2
0
        public void TestAll()
        {
            #region Add Permission
            var permiId        = Guid.NewGuid();
            var pocFile        = new PocFile <Schema>();
            var repoPermission = new PocRepository <Schema, Permission>(pocFile);
            var permission     = new Permission {
                Id = permiId, Name = "Perm1"
            };
            repoPermission.Insert(permission);

            var permission2 = new Permission {
                Name = "Perm2"
            };

            try
            {
                repoPermission.Insert(permission);
                Assert.Fail("Expect exception");
            }
            catch { }

            repoPermission.Insert(permission2);


            pocFile.Save();
            #endregion

            #region Add Customer
            pocFile = new PocFile <Schema>();
            var repo  = pocFile.GetRepository <Customer>();
            var order = new Order {
                Name = "My first order"
            };
            var user = new User()
            {
                Name = "User1"
            };
            var permissions = new List <Permission>();
            permissions.Add(permission);
            user.Permissions = permissions;

            var customer = new Customer
            {
                Name  = "John Doe",
                Order = order,
                User  = user
            };

            repo.Insert(customer);
            pocFile.Save();
            #endregion

            #region Test
            pocFile = new PocFile <Schema>();
            var getPermission = pocFile.GetRepository <Permission>().GetById(permiId);
            var getCustomer   = pocFile.GetRepository <Customer>().GetById(customer.Id);
            var allCustomer   = pocFile.GetRepository <Customer>().GetAll();
            var allPermission = pocFile.GetRepository <Permission>().GetAll();

            Assert.IsTrue(permission.Id == getPermission.Id);
            Assert.IsTrue(allCustomer.Count() == 1);
            Assert.IsTrue(allPermission.Count() == 2);
            Assert.IsTrue(customer.Id == getCustomer.Id);
            #endregion

            #region Edit and delete

            pocFile = new PocFile <Schema>();
            var repoPerm = pocFile.GetRepository <Permission>();
            var repoCust = pocFile.GetRepository <Customer>();
            getCustomer.Name      = "Edited";
            getCustomer.User.Name = "User edited";
            repoCust.Update(getCustomer);
            repoPerm.Delete(permission2);
            pocFile.Save();
            #endregion

            #region Test
            pocFile       = new PocFile <Schema>();
            getCustomer   = pocFile.GetRepository <Customer>().Get(f => f.Id == customer.Id).First();
            allPermission = pocFile.GetRepository <Permission>().GetAll();

            Assert.IsTrue(allCustomer.Count() == 1);
            Assert.IsTrue(allPermission.Count() == 1);
            Assert.IsTrue(getCustomer.Id == customer.Id);
            Assert.IsTrue(getCustomer.Name == "Edited");
            Assert.IsTrue(getCustomer.User.Name == "User edited");
            #endregion

            pocFile = new PocFile <Schema>();
            pocFile.Truncate();
        }
コード例 #3
0
 public Repository(PocFile <Schema> pocFile)
 {
     this.pocFile    = pocFile;
     this.repository = this.pocFile.GetRepository <T>();
 }