Beispiel #1
0
        public void JustCreateTheDatabase()
        {
            using var serviceProvider = InfrastructureTestsUtils.CreateServiceCollection().BuildServiceProvider();
            var       instance = serviceProvider.GetService <IGaleryDatabase>();
            DbContext context  = instance as DbContext;

            context.Database.EnsureCreated();
        }
        private void RemoveTestDataFromDb()
        {
            using var serviceProvider = InfrastructureTestsUtils.CreateServiceCollection().BuildServiceProvider();
            var database = serviceProvider.GetService <IGaleryDatabase>();

            database.DatabaseInfo.Remove(_info);
            database.SaveChanges();
            database.DetachAllEntities();
        }
        private void RemoveTestHashedEntityFromDb()
        {
            using var serviceProvider = InfrastructureTestsUtils.CreateServiceCollection().BuildServiceProvider();
            var database = serviceProvider.GetService <IGaleryDatabase>();

            database.Binders.Remove(_binder);
            database.Contents.Remove(_content);
            database.Binders.Remove(_dirBinder);
            database.SaveChanges();
            database.DetachAllEntities();
        }
        public void GetExistingHashedElement_WillReturnIt()
        {
            using var serviceProvider = InfrastructureTestsUtils.CreateServiceCollection().BuildServiceProvider();
            var database = serviceProvider.GetService <IGaleryDatabase>();
            var repo     = new ContentEntitiesRepository(database);
            var fromDb   = repo.Get(TestContentElementHash);

            Assert.That(fromDb, Is.Not.Null, "Returned element is null");
            Assert.That(fromDb.Hash.Trim(), Is.EqualTo(TestContentElementHash), "Hash is not equal");
            Assert.That(fromDb.Binders, Is.Not.Null, "Binders is null");
            Assert.That(fromDb.AttributedBinders, Is.Not.Null, "AttributedBinders is null");
            var binder = fromDb.Binders.First().Binder;

            Assert.That(binder, Is.Not.Null, "First Binder is null");
            Assert.That(binder.Label, Is.Not.Empty, "Binder Lable is empty");
            var dirBinderHolder = fromDb.AttributedBinders.First();

            Assert.That(dirBinderHolder, Is.Not.Null, "First Dir Binder is null");
            Assert.That(dirBinderHolder.Attribute, Is.Not.Empty, "Dir binder attribute is empty");
            var dirBinder = dirBinderHolder.Binder;

            Assert.That(dirBinder, Is.Not.Null, "Dir Binder is null");
            Assert.That(dirBinder.Label, Is.Not.Empty, "Dir binder label is empty");
        }