Inheritance: MvxBaseSQLiteConnectionFactory
Exemple #1
0
        public void Load()
        {
            var factory = new MvxTouchSQLiteConnectionFactory();

            Mvx.RegisterSingleton <ISQLiteConnectionFactory>(factory);
            Mvx.RegisterSingleton <ISQLiteConnectionFactoryEx>(factory);
        }
        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);
            }
        }
        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();

            }
        }
        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();
            }
        }
        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();
            }
        }
Exemple #6
0
 public void Load()
 {
     var factory = new MvxTouchSQLiteConnectionFactory();
     Mvx.RegisterSingleton<ISQLiteConnectionFactory>(factory);
     Mvx.RegisterSingleton<ISQLiteConnectionFactoryEx>(factory);
 }