Пример #1
0
 public void Provider_Property()
 {
     using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
     {
         Assert.Equal(repository.ObjectContext.CreateObjectSet <EFModelEntity>().AsQueryable().Provider.ToString(), repository.Provider.ToString());
     }
 }
Пример #2
0
 public void Dispose()
 {
     using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
     {
         repository.DeleteAll().Commit();
     }
 }
Пример #3
0
 public void ElementType_Property()
 {
     using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
     {
         Assert.True(ReferenceEquals(repository.ObjectContext.CreateObjectSet <EFModelEntity>().AsQueryable().ElementType, repository.ElementType));
     }
 }
Пример #4
0
 public void Transaction_Method()
 {
     using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
     {
         Assert.NotNull(repository.Transaction());
     }
 }
Пример #5
0
        public void Persist_Method()
        {
            Assert.Throws <ArgumentNullException>(() => new EFModelRepository <EFModelEntity>(this.connectionString).Persist(null));

            var entity = new EFModelEntity {
                Name = "first"
            };

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.False(repository.Any());

                Assert.True(ReferenceEquals(repository.Persist(entity), repository));
                repository.Commit();
                entity = repository.Single();
                Assert.NotEqual(0, entity.Id);
                Assert.Equal("first", entity.Name);

                entity.Name = "second";
                repository.Commit();
                entity = repository.Single();
                Assert.NotEqual(0, entity.Id);
                Assert.Equal("second", entity.Name);
                Assert.Equal(1, repository.Count(x => x.Name == "second"));
                Assert.Equal("second", repository.Single(x => x.Name == "second").Name);
            }
        }
Пример #6
0
        public void Delete_Method()
        {
            Assert.Throws <ArgumentNullException>(() => new EFModelRepository <EFModelEntity>(this.connectionString).Delete(null));

            var entity = new EFModelEntity();

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.Throws <InvalidOperationException>(() => repository.Delete(entity));
                Assert.False(repository.Persist(entity).Delete(entity).Commit().Any());
            }
        }
Пример #7
0
        public void Dispose_Method()
        {
            var entity = new EFModelEntity();

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                repository.Persist(entity).Dispose();
                Assert.Throws <ObjectDisposedException>(() => repository.Single());

                repository.Dispose();
            }
        }
Пример #8
0
        public void DeleteAll_Method()
        {
            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.True(ReferenceEquals(repository.DeleteAll(), repository));
                Assert.False(repository.Commit().Any());

                repository.Persist(new EFModelEntity()).Persist(new EFModelEntity());
                Assert.Equal(2, repository.Commit().Count());

                repository.DeleteAll();
                Assert.False(repository.Commit().Any());
            }
        }
Пример #9
0
        public void GetEnumerator_Method()
        {
            var entity = new EFModelEntity();

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.False(repository.GetEnumerator().MoveNext());

                repository.Persist(entity).Commit();
                var enumerator = repository.GetEnumerator();
                Assert.True(enumerator.MoveNext());
                Assert.False(enumerator.MoveNext());
            }
        }
Пример #10
0
        public void Commit_Method()
        {
            var entity = new EFModelEntity();

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.False(repository.Any());

                Assert.True(ReferenceEquals(repository.Persist(entity).Commit(), repository));
                Assert.True(ReferenceEquals(repository.Single(), entity));

                repository.Delete(entity);
                Assert.True(ReferenceEquals(repository.Single(), entity));

                repository.Commit();
                Assert.False(repository.Any());
            }
        }
Пример #11
0
        public void Refresh_Method()
        {
            Assert.Throws <ArgumentNullException>(() => new EFModelRepository <EFModelEntity>(this.connectionString).Refresh(null));

            var entity = new EFModelEntity {
                Name = "first"
            };

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.Throws <InvalidOperationException>(() => repository.Refresh(entity));

                repository.Persist(entity).Commit();
                var originalId   = entity.Id;
                var originalName = entity.Name;

                entity.Name = "second";
                Assert.True(ReferenceEquals(repository.Refresh(entity), repository));
                Assert.Equal(originalId, entity.Id);
                Assert.Equal(originalName, entity.Name);
            }
        }
Пример #12
0
        public void Constructors()
        {
            Assert.Throws <ArgumentNullException>(() => new EFModelRepository <EFModelEntity>((ObjectContext)null));
            Assert.Throws <ArgumentNullException>(() => new EFModelRepository <EFModelEntity>((string)null));
            Assert.Throws <ArgumentException>(() => new EFModelRepository <EFModelEntity>(string.Empty));

            var objectContext = new ObjectContext(this.connectionString);

            using (var repository = new EFModelRepository <EFModelEntity>(objectContext))
            {
                Assert.True(ReferenceEquals(repository.ObjectContext, objectContext));
                Assert.True(ReferenceEquals(repository.Field("objectSet").To <ObjectSet <EFModelEntity> >().Context, repository.Field("objectContext").To <ObjectContext>()));
                Assert.False(repository.Field("ownsContext").To <bool>());
            }

            using (var repository = new EFModelRepository <EFModelEntity>(this.connectionString))
            {
                Assert.False(ReferenceEquals(repository.ObjectContext, objectContext));
                Assert.Equal(this.connectionString, repository.ObjectContext.Connection.ConnectionString);
                Assert.True(ReferenceEquals(repository.Field("objectSet").To <ObjectSet <EFModelEntity> >().Context, repository.Field("objectContext").To <ObjectContext>()));
                Assert.True(repository.Field("ownsContext").To <bool>());
            }
        }