コード例 #1
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();
                }
            }
        }
コード例 #2
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();
                }
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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();
                }
            }
        }