Esempio n. 1
0
        public void Persist_Method()
        {
            Assert.Throws <ArgumentNullException>(() => new LinqToSqlRepository <TestEntity>(this.Connection()).Persist(null));

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

            using (var repository = new LinqToSqlRepository <TestEntity>(this.Connection()))
            {
                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);
            }
        }
Esempio n. 2
0
        public void Commit_Method()
        {
            var entity = new TestEntity();

            using (var repository = new LinqToSqlRepository <TestEntity>(this.Connection()))
            {
                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());
            }
        }