Beispiel #1
0
 public WhereTest()
 {
     _db = new SQLiteDb();
     _db.DataTable.Insert(Enumerable.Range(0, RowCount).Select(i => new Data {
         TextValue = $"Some Text {i}"
     }));
 }
Beispiel #2
0
 public AggregateTest()
 {
     _db = new SQLiteDb <string>();
     _db.DataTable.Insert(Enumerable.Range(0, RowCount).Select(i => new Data <string> {
         Value = $"Some Text {i}"
     }));
 }
Beispiel #3
0
 public StringTest()
 {
     _db = new SQLiteDb <string>();
     _db.DataTable.Insert(new Data <string> {
         Value = TestString
     });
 }
Beispiel #4
0
 public DateTimeTest()
 {
     _db = new SQLiteDb <DateTime>();
     _db.DataTable.Insert(new Data <DateTime> {
         Value = _testDate
     });
 }
 public TimeSpanTest()
 {
     _db = new SQLiteDb <TimeSpan>();
     _db.DataTable.Insert(new Data <TimeSpan> {
         Value = _testTimeSpan
     });
 }
Beispiel #6
0
        public void TestFirstOrDefault()
        {
            using (var db = new SQLiteDb <string>())
            {
                Assert.Null(db.DataTable.FirstOrDefault());

                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text"
                });
                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text 2"
                });

                var result = db.DataTable.FirstOrDefault();
                Assert.NotNull(result);
                Assert.Equal(1, result.Id);
                Assert.Equal("Random Text", result.Value);

                result = db.DataTable.FirstOrDefault(d => d.Id == 2);
                Assert.NotNull(result);
                Assert.Equal(2, result.Id);
                Assert.Equal("Random Text 2", result.Value);

                Assert.Null(db.DataTable.FirstOrDefault(d => d.Id == 3));
            }
        }
Beispiel #7
0
        public void TestFirst()
        {
            using (var db = new SQLiteDb <string>())
            {
                Assert.Throws <InvalidOperationException>(() => db.DataTable.First());

                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text"
                });
                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text 2"
                });

                var result = db.DataTable.First();
                Assert.Equal(1, result.Id);
                Assert.Equal("Random Text", result.Value);

                result = db.DataTable.First(d => d.Id == 2);
                Assert.Equal(2, result.Id);
                Assert.Equal("Random Text 2", result.Value);

                Assert.Throws <InvalidOperationException>(() => db.DataTable.First(d => d.Id == 3));
            }
        }
Beispiel #8
0
        public void TestAny()
        {
            using (var db = new SQLiteDb <string>())
            {
                Assert.False(db.DataTable.Any());

                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text"
                });
                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text 2"
                });

                Assert.True(db.DataTable.Any());

                Assert.True(db.DataTable.Any(d => d.Id == 1));
                Assert.True(db.DataTable.Any(d => d.Id == 2));
                Assert.False(db.DataTable.Any(d => d.Id == 3));

                Assert.True(db.DataTable.Any(d => d.Value == "Random Text"));
                Assert.True(db.DataTable.Any(d => d.Value == "Random Text 2"));
                Assert.False(db.DataTable.Any(d => d.Value == "Other Text"));
            }
        }
Beispiel #9
0
        private static void SimpleTest <T>(T value)
        {
            using (var db = new SQLiteDb <T>())
            {
                db.DataTable.Insert(new Data <T> {
                    Value = value
                });

                Assert.Equal(value, db.DataTable.Single().Value);
            }
        }
Beispiel #10
0
        public void TestContains()
        {
            using (var db = new SQLiteDb <string>())
            {
                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text"
                });
                db.DataTable.Insert(new Data <string>()
                {
                    Value = "Random Text 2"
                });

                Assert.True(db.DataTable.Select(d => d.Id).Contains(1));
                Assert.True(db.DataTable.Select(d => d.Id).Contains(2));
                Assert.False(db.DataTable.Select(d => d.Id).Contains(3));

                Assert.True(db.DataTable.Select(d => d.Value).Contains("Random Text"));
                Assert.True(db.DataTable.Select(d => d.Value).Contains("Random Text 2"));
                Assert.False(db.DataTable.Select(d => d.Value).Contains("Other Text"));
            }
        }