Example #1
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);
            }
        }
Example #2
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());
            }
        }
Example #3
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();
            }
        }
Example #4
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());
            }
        }
Example #5
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());
            }
        }
Example #6
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());
            }
        }
Example #7
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);
            }
        }