private void TestIndexMultipleInsert(string s, int i, int r, bool shouldFail = false) { using (var container = new RhetosTestContainer()) { container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestUnique.Multi;", "DELETE FROM TestUnique.R;" }); var repository = container.Resolve <Common.DomRepository>(); var helper = new EntityHelperMultiple(container, repository); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert(s, i, r == 1 ? r1 : r2, shouldFail); } }
public void Insert_Index3() { using (var container = new RhetosTestContainer()) { container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestUnique.E;", "DELETE FROM TestUnique.R;" }); var repository = container.Resolve <Common.DomRepository>(); var helper = new EntityHelper(container); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert("b", 1, r1); helper.Insert("a", 2, r1); helper.Insert("a", 1, r2); helper.InsertShouldFail("a", 1, r1); } }
public void Insert(string s, int i, TestUnique.R r, bool shouldFail = false) { string error = null; var newItem = new TestUnique.Multi { S = s, I = i, RID = r.ID, ID = Guid.NewGuid() }; try { Console.WriteLine("Inserting " + s + ", " + i + " ..."); _repository.TestUnique.Multi.Insert(new[] { newItem }); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name + ": " + ex.Message); error = ex.Message; if (!shouldFail) { throw; } } if (shouldFail) { Assert.IsNotNull(error, "Insert should have failed with an exception."); TestUtility.AssertContains(error, "Cannot insert duplicate key"); } }
public void Insert_Index3() { using (var scope = TestScope.Create()) { scope.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestUnique.E;", "DELETE FROM TestUnique.R;" }); var repository = scope.Resolve <Common.DomRepository>(); var helper = new EntityHelper(scope); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert("b", 1, r1); helper.Insert("a", 2, r1); helper.Insert("a", 1, r2); helper.InsertShouldFail("a", 1, r1); } }
public void UpdateShouldFail(string s, int i, TestUnique.R r, Guid id) { string error = null; try { Update(s, i, r, id); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name + ": " + ex.Message); error = ex.Message; } Assert.IsNotNull(error, "Update should have failed with an exception."); }
public void InsertShouldFail(string s, int i, TestUnique.R r) { string error = null; try { Insert(s, i, r); } catch (Exception ex) { Console.WriteLine(ex.GetType().Name + ": " + ex.Message); error = ex.Message; } Assert.IsNotNull(error, "Insert should have failed with an exception."); }
//================================================================ private void TestIndexMultipleInsert(string s, int i, int r, bool shouldFail = false) { using (var container = new RhetosTestContainer()) { container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestUnique.Multi;", "DELETE FROM TestUnique.R;" }); var repository = container.Resolve <Common.DomRepository>(); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); repository.TestUnique.Multi.Insert(new TestUnique.Multi { S = "a", I = 1, RID = r1.ID, ID = Guid.NewGuid() }); Action insert = () => repository.TestUnique.Multi.Insert(new TestUnique.Multi { S = s, I = i, RID = (r == 1) ? r1.ID : r2.ID, ID = Guid.NewGuid() }); if (shouldFail) { var ex = TestUtility.ShouldFail(insert, "It is not allowed to enter a duplicate record."); TestUtility.AssertContains(ex.ToString(), "Cannot insert duplicate key", "Original SQL exception should be included."); } else { insert(); } } }
public void Insert_Index3() { using (var container = new RhetosTestContainer()) { container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestUnique.E;", "DELETE FROM TestUnique.R;" }); var repository = container.Resolve<Common.DomRepository>(); var helper = new EntityHelper(container); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert("b", 1, r1); helper.Insert("a", 2, r1); helper.Insert("a", 1, r2); helper.InsertShouldFail("a", 1, r1); } }
public void Insert_Index3() { using (var executionContext = new CommonTestExecutionContext()) { executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestUnique.E;", "DELETE FROM TestUnique.R;" }); var repository = new Common.DomRepository(executionContext); var helper = new EntityHelper(executionContext, repository); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert("b", 1, r1); helper.Insert("a", 2, r1); helper.Insert("a", 1, r2); helper.InsertShouldFail("a", 1, r1); } }
private void TestIndexMultipleInsert(string s, int i, int r, bool shouldFail = false) { using (var container = new RhetosTestContainer()) { container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestUnique.Multi;", "DELETE FROM TestUnique.R;" }); var repository = container.Resolve<Common.DomRepository>(); var helper = new EntityHelperMultiple(container, repository); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert(s, i, r == 1 ? r1 : r2, shouldFail); } }
public void Update(string s, int i, TestUnique.R r, Guid id) { _repository.TestUnique.E.Update(new[] { new TestUnique.E { S = s, I = i, RID = r.ID, ID = id } }); }
public void Insert(string s, int i, TestUnique.R r, Guid?id = null) { _repository.TestUnique.E.Insert(new[] { new TestUnique.E { S = s, I = i, RID = r.ID, ID = id ?? Guid.NewGuid() } }); }
private void TestIndexMultipleInsert(string s, int i, int r, bool shouldFail = false) { using (var executionContext = new CommonTestExecutionContext()) { executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestUnique.Multi;", "DELETE FROM TestUnique.R;" }); var repository = new Common.DomRepository(executionContext); var helper = new EntityHelperMultiple(executionContext, repository); var r1 = new TestUnique.R { S = "r1" }; var r2 = new TestUnique.R { S = "r2" }; repository.TestUnique.R.Insert(new[] { r1, r2 }); helper.Insert("a", 1, r1); helper.Insert(s, i, r == 1 ? r1 : r2, shouldFail); } }