Exemplo n.º 1
0
        public void DeleteAll_Method()
        {
            using (var repository = new NHibernateRepository <TestEntity>(this.configuration))
            {
                repository.Transaction(() => Assert.True(ReferenceEquals(repository.DeleteAll(), repository)));
                Assert.False(repository.Any());

                repository.Transaction(() => repository.Persist(new TestEntity()).Persist(new TestEntity()));
                Assert.Equal(2, repository.Count());

                repository.Transaction(() => repository.DeleteAll());
                Assert.False(repository.Any());
            }
        }
Exemplo n.º 2
0
        public void Persist_Method()
        {
            Assert.Throws <ArgumentNullException>(() => new NHibernateRepository <TestEntity>(this.configuration).Persist(null));

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

            using (var repository = new NHibernateRepository <TestEntity>(this.configuration))
            {
                Assert.False(repository.Any());

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

                entity.Name = "second";
                repository.Transaction(() => repository.Persist(entity));
                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);
            }
        }
Exemplo n.º 3
0
        public void Commit_Method()
        {
            var entity = new TestEntity();

            using (var repository = new NHibernateRepository <TestEntity>(this.configuration))
            {
                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());
            }
        }
Exemplo n.º 4
0
        public void Delete_Method()
        {
            Assert.Throws <ArgumentNullException>(() => new NHibernateRepository <TestEntity>(this.configuration).Delete(null));

            var entity = new TestEntity();

            using (var repository = new NHibernateRepository <TestEntity>(this.configuration))
            {
                repository.Transaction(() => Assert.True(ReferenceEquals(repository.Delete(entity), repository)));

                repository.Transaction(() => repository.Persist(entity));
                repository.Transaction(() => repository.Delete(new TestEntity()));
                Assert.True(ReferenceEquals(repository.Single(), entity));

                repository.Transaction(() => repository.Delete(entity));
                Assert.False(repository.Any());
            }
        }