コード例 #1
0
ファイル: Plugin.cs プロジェクト: ronysteel/MvvmCross-SQLite
        public void Load()
        {
            var factory = new MvxWpfSQLiteConnectionFactory();

            Mvx.RegisterSingleton <ISQLiteConnectionFactory>(factory);
            Mvx.RegisterSingleton <ISQLiteConnectionFactoryEx>(factory);
        }
コード例 #2
0
        public void ShouldCreateFileDatabase()
        {
            // Items Needing Cleanup
            ISQLiteConnection conn = null;
            string expectedFilePath = null;
            try
            {
                // Arrange
            #if __IOS__
                ISQLiteConnectionFactory factory = new MvxTouchSQLiteConnectionFactory();
            #elif __ANDROID__
                ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory();
            #else
                ISQLiteConnectionFactory factory = new MvxWpfSQLiteConnectionFactory();
            #endif

                string filename = Guid.NewGuid().ToString() + ".db";
            #if __IOS__ || __ANDROID__
                expectedFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename);
            #else
                expectedFilePath = Path.Combine(Directory.GetCurrentDirectory(), filename);
            #endif

                // Act
                conn = factory.Create(filename);
                conn.CreateTable<Person>();
                conn.Insert(new Person() { FirstName = "Bob", LastName = "Smith" });
                Person expected = conn.Table<Person>().FirstOrDefault();

                // Asset
                Assert.That(File.Exists(expectedFilePath), Is.True);
                Assert.That(expected.FirstName, Is.EqualTo("Bob"));
                Assert.That(expected.LastName, Is.EqualTo("Smith"));
            }
            finally // Cleanup in Finally
            {
                if (conn != null)
                    conn.Close();

                if (!string.IsNullOrWhiteSpace(expectedFilePath) && File.Exists(expectedFilePath))
                    File.Delete(expectedFilePath);
            }
        }
コード例 #3
0
        public void ShouldCreateInMemoryDatabase()
        {
            // Items Needing Cleanup
            ISQLiteConnection conn = null;

            try
            {
                // Arrange
            #if __IOS__
                ISQLiteConnectionFactory factory = new MvxTouchSQLiteConnectionFactory();
            #elif __ANDROID__
                ISQLiteConnectionFactory factory = new MvxDroidSQLiteConnectionFactory();
            #else
                ISQLiteConnectionFactory factory = new MvxWpfSQLiteConnectionFactory();
            #endif

                // Act
                conn = factory.CreateInMemory();
                conn.CreateTable<Person>();
                conn.Insert(new Person() { FirstName = "Bob", LastName = "Smith" });
                Person expected = conn.Table<Person>().FirstOrDefault();

                // Asset
                Assert.That(expected.FirstName, Is.EqualTo("Bob"));
                Assert.That(expected.LastName, Is.EqualTo("Smith"));
            }
            finally // Cleanup in Finally
            {
                if (conn != null)
                    conn.Close();

            }
        }
コード例 #4
0
        public void ShouldThrowArgumentNullExceptionOnCreateGivenNullOptions()
        {
            // Items Needing Cleanup
            ISQLiteConnection conn = null;

            try
            {
                // Arrange
            #if __IOS__
                ISQLiteConnectionFactoryEx factory = new MvxTouchSQLiteConnectionFactory();
            #elif __ANDROID__
                ISQLiteConnectionFactoryEx factory = new MvxDroidSQLiteConnectionFactory();
            #else
                ISQLiteConnectionFactoryEx factory = new MvxWpfSQLiteConnectionFactory();
            #endif

                // Act
                conn = factory.CreateEx(null);
            }
            finally // Cleanup in Finally
            {
                if (conn != null) // In case test fails and connection was created
                    conn.Close();
            }
        }
コード例 #5
0
        public void ShouldThrowArgumentExceptionOnCreateGivenOptionsWithNullAddressAndTypeFile()
        {
            // Items Needing Cleanup
            ISQLiteConnection conn = null;

            try
            {
                // Arrange
            #if __IOS__
                ISQLiteConnectionFactoryEx factory = new MvxTouchSQLiteConnectionFactory();
            #elif __ANDROID__
                ISQLiteConnectionFactoryEx factory = new MvxDroidSQLiteConnectionFactory();
            #else
                ISQLiteConnectionFactoryEx factory = new MvxWpfSQLiteConnectionFactory();
            #endif
                SQLiteConnectionOptions options = new SQLiteConnectionOptions { Address = null, Type = SQLiteConnectionOptions.DatabaseType.File };

                // Act
                conn = factory.CreateEx(options);
            }
            finally // Cleanup in Finally
            {
                if (conn != null) // In case test fails and connection was created
                    conn.Close();
            }
        }
コード例 #6
0
 public void Load()
 {
     var factory = new MvxWpfSQLiteConnectionFactory();
     Mvx.RegisterSingleton<ISQLiteConnectionFactory>(factory);
     Mvx.RegisterSingleton<ISQLiteConnectionFactoryEx>(factory);
 }