示例#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);
            }
        }
示例#2
0
        /// <summary>
        /// Create a new EFModelEntity object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        public static EFModelEntity CreateEFModelEntity(global::System.Int64 id)
        {
            EFModelEntity eFModelEntity = new EFModelEntity();

            eFModelEntity.Id = id;
            return(eFModelEntity);
        }
    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());
      }
    }
示例#4
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());
            }
        }
示例#5
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();
            }
        }
示例#6
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());
            }
        }
    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());
      }
    }
示例#8
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());
            }
        }
示例#9
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);
            }
        }
示例#10
0
 /// <summary>
 /// Deprecated Method for adding a new object to the EFModelEntity EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEFModelEntity(EFModelEntity eFModelEntity)
 {
     base.AddObject("EFModelEntity", eFModelEntity);
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the EFModelEntity EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEFModelEntity(EFModelEntity eFModelEntity)
 {
     base.AddObject("EFModelEntity", eFModelEntity);
 }
 /// <summary>
 /// Create a new EFModelEntity object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 public static EFModelEntity CreateEFModelEntity(global::System.Int64 id)
 {
     EFModelEntity eFModelEntity = new EFModelEntity();
     eFModelEntity.Id = id;
     return eFModelEntity;
 }
    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);
      }
    }
    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);
      }
    }
    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());
      }
    }
    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();
      }
    }