コード例 #1
0
 public void TestGetNonExistantCollectionInReadOnlyDatabase()
 {
     using (var connection = CreateConnection())
         using (var db = new IsabelDb(connection, null, NoCustomTypes, false, isReadOnly: true))
         {
             new Action(() => GetCollection((IDatabase)db, "Stuff"))
             .Should().Throw <NoSuchCollectionException>()
             .WithMessage("Unable to find a collection named 'Stuff'");
         }
 }
コード例 #2
0
 public void TestCollectionName()
 {
     using (var connection = CreateConnection())
     {
         using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
         {
             var collection = CreateCollection(db, "For The Fallen Dreams");
             collection.Name.Should().Be("For The Fallen Dreams");
             collection.Type.Should().Be(CollectionType);
         }
     }
 }
コード例 #3
0
 public void TestGetCollections()
 {
     using (var connection = CreateConnection())
     {
         using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
         {
             db.Collections.Should().BeEmpty();
             var collection = CreateCollection(db, "Stuff");
             db.Collections.Should().Equal(collection);
         }
     }
 }
コード例 #4
0
 public void TestPutManyRemoved()
 {
     using (var connection = CreateConnection())
         using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
         {
             var collection = db.GetOrCreateMultiValueDictionary <int, string>("Blessthefall");
             collection.Put(1, "Wishful Sinking");
             db.Remove(collection);
             new Action(() => collection.PutMany(2, new[] { "Find Yourself", "Sakura Blues" }))
             .Should().Throw <InvalidOperationException>()
             .WithMessage("This collection (\"Blessthefall\") has been removed from the database and may no longer be used");
         }
 }
コード例 #5
0
        public void TestGetCollectionsAfterReopen()
        {
            using (var connection = CreateConnection())
            {
                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
                {
                    db.Collections.Should().BeEmpty();
                    var collection = CreateCollection(db, "Stuff");
                    db.Collections.Should().Equal(collection);
                }

                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, isReadOnly: true))
                {
                    db.Collections.Should().HaveCount(1);
                    var collection       = db.Collections.First();
                    var actualCollection = GetCollection(db, "Stuff");
                    collection.Should().BeSameAs(actualCollection);
                }
            }
        }
コード例 #6
0
        public void TestRemoveReadOnlyDatabase()
        {
            using (var connection = CreateConnection())
            {
                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
                {
                    var collection = CreateCollection(db, "Stuff");
                    Put(collection, "One");
                }

                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, isReadOnly: true))
                {
                    var collection = GetCollection(db, "Stuff");
                    collection.GetAllValues().Should().Equal("One");

                    new Action(() => RemoveLastPutValue(collection))
                    .Should().Throw <InvalidOperationException>()
                    .WithMessage("The database has been opened read-only and therefore may not be modified");

                    collection.GetAllValues().Should().Equal("One");
                }
            }
        }
コード例 #7
0
        public void TestRemoveIntervalReadOnlyDatabase()
        {
            using (var connection = CreateConnection())
            {
                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
                {
                    var collection = db.GetOrCreateIntervalCollection <int, string>("Stuff");
                    collection.Put(Interval.Create(1), "One");
                }

                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, isReadOnly: true))
                {
                    var collection = db.GetOrCreateIntervalCollection <int, string>("Stuff");
                    collection.GetAllValues().Should().Equal("One");

                    new Action(() => collection.Remove(Interval.Create(1)))
                    .Should().Throw <InvalidOperationException>()
                    .WithMessage("The database has been opened read-only and therefore may not be modified");

                    collection.GetAllValues().Should().Equal("One");
                }
            }
        }
コード例 #8
0
        public void TestPutMany2ReadOnlyDatabase()
        {
            using (var connection = CreateConnection())
            {
                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, false))
                {
                    var collection = db.GetOrCreateMultiValueDictionary <int, string>("Stuff");
                    collection.Put(1, "One");
                    collection.Put(1, "Two");
                }

                using (var db = new IsabelDb(connection, null, NoCustomTypes, false, isReadOnly: true))
                {
                    var collection = db.GetOrCreateMultiValueDictionary <int, string>("Stuff");
                    collection.GetAllValues().Should().Equal("One", "Two");

                    new Action(() => collection.PutMany(1, new [] { "Three" }))
                    .Should().Throw <InvalidOperationException>()
                    .WithMessage("The database has been opened read-only and therefore may not be modified");

                    collection.GetAllValues().Should().Equal("One", "Two");
                }
            }
        }