protected virtual void IncludeFixture() { ClearSharedRepositories(); using (Repositories.Use()) { var model7 = new TestModel7() { Model7Id = 7, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model7).UpdateAll(); var model8 = new TestModel8() { Id = 8, Model7Id = 7, DataString = "data8", DataInt = 8, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel8Repo.AddOne(model8).UpdateAll(); } using (Repositories.Use()) { var res = TestModel8Repo.GetAllAndInclude(m8 => m8.Id == 8, m8 => m8.TestModel7Object, TestModel7Repo).FirstOrDefault(); res.Should().Not.Be.Null(); res.TestModel7Object.DataString.Should().Equal("data7"); res.TestModel7Object.DataInt.Should().Equal(7); } using (Repositories.Use()) { var res = TestModel8Repo.AsQueryable().Where(m8 => m8.Id == 8).Include(m8 => m8.TestModel7Object, TestModel7Repo).FirstOrDefault(); res.Should().Not.Be.Null(); res.TestModel7Object.DataString.Should().Equal("data7"); res.TestModel7Object.DataInt.Should().Equal(7); } ClearSharedRepositories(); }
protected virtual void TransactionScopeFixture() { ClearSharedRepositories(); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { using (Repositories.Use()) { var model7 = new TestModel7() { Model7Id = 7, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model7).UpdateAll(); var model8 = new TestModel8() { Id = 8, Model7Id = 7, DataString = "data8", DataInt = 8, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel8Repo.AddOne(model8).UpdateAll(); TestModel8Repo.UpdateAll(); scope.Complete(); var model70 = new TestModel7() { Model7Id = 70, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model70); Assert.Throws<EntityException>(() => TestModel7Repo.UpdateAll());//The underlying provider failed on open } } using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { using (Repositories.Use()) { var model71 = new TestModel7() { Model7Id = 71, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model71).UpdateAll(); var model81 = new TestModel8() { Id = 81, Model7Id = 7, DataString = "data8", DataInt = 8, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel8Repo.AddOne(model81).UpdateAll(); } } using (Repositories.Use()) { TestModel7Repo.GetOne(x => x.Model7Id == 7).Should().Not.Be.Null(); TestModel8Repo.GetOne(x => x.Id == 8).Should().Not.Be.Null(); TestModel7Repo.GetOne(x => x.Model7Id == 71).Should().Be.Null(); TestModel8Repo.GetOne(x => x.Id == 81).Should().Be.Null(); } ClearSharedRepositories(); }
protected virtual void TransactionScopeFixture() { ClearSharedRepositories(); using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { using (Repositories.Use()) { var model7 = new TestModel7() { Model7Id = 7, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model7).UpdateAll(); var model8 = new TestModel8() { Id = 8, Model7Id = 7, DataString = "data8", DataInt = 8, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel8Repo.AddOne(model8).UpdateAll(); TestModel8Repo.UpdateAll(); scope.Complete(); var model70 = new TestModel7() { Model7Id = 70, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model70); Assert.Throws <EntityException>(() => TestModel7Repo.UpdateAll());//The underlying provider failed on open } } using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { using (Repositories.Use()) { var model71 = new TestModel7() { Model7Id = 71, DataString = "data7", DataInt = 7, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel7Repo.AddOne(model71).UpdateAll(); var model81 = new TestModel8() { Id = 81, Model7Id = 7, DataString = "data8", DataInt = 8, DataDateTime = DateTime.Now, NullableDateTime = DateTime.Now }; TestModel8Repo.AddOne(model81).UpdateAll(); } } using (Repositories.Use()) { TestModel7Repo.GetOne(x => x.Model7Id == 7).Should().Not.Be.Null(); TestModel8Repo.GetOne(x => x.Id == 8).Should().Not.Be.Null(); TestModel7Repo.GetOne(x => x.Model7Id == 71).Should().Be.Null(); TestModel8Repo.GetOne(x => x.Id == 81).Should().Be.Null(); } ClearSharedRepositories(); }