public void Step_08_Entity_State() { Console.WriteLine("8. Checking the state of the entity."); Stopwatch watch = Stopwatch.StartNew(); //Insert should fail as there should be a duplicate key. Category category = Category.NewCategory(); Assert.IsTrue(category.IsDirty); category.CategoryId = TestCategoryID2; category.Name = TestUtility.Instance.RandomString(80, false); category.Description = TestUtility.Instance.RandomString(255, false); Assert.IsTrue(category.IsNew); Assert.IsTrue(category.IsDirty); Assert.IsFalse(category.IsDeleted); Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString()); category = category.Save(); Assert.IsFalse(category.IsNew); Assert.IsFalse(category.IsDirty); Assert.IsFalse(category.IsDeleted); category.Name = TestUtility.Instance.RandomString(80, false); Assert.IsTrue(category.IsDirty); Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString()); category = category.Save(); Assert.IsFalse(category.IsNew); Assert.IsFalse(category.IsDirty); Assert.IsFalse(category.IsDeleted); category.Delete(); Assert.IsTrue(category.IsDeleted); Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString()); category = category.Save(); Assert.IsFalse(category.IsDeleted); Assert.IsTrue(category.IsNew); Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds); }
public void Step_22_Double_Delete() { Console.WriteLine("20. Deleting the category twice."); Stopwatch watch = Stopwatch.StartNew(); Category category = Category.GetByCategoryId(TestCategoryID); Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase)); Assert.IsFalse(category.IsDeleted); category.Delete(); //Delete the category the other way before calling save which would call a delete. This should simulate a concurency issue. Category.DeleteCategory(TestCategoryID); try { Category.GetByCategoryId(TestCategoryID); Assert.Fail("Record exists when it should have been deleted."); } catch (Exception) { // Exception was thrown if record doesn't exist. Assert.IsTrue(true); } // Call delete on an already deleted item. Assert.IsTrue(category.IsDeleted); try { Assert.IsTrue(category.IsValid, category.BrokenRulesCollection.ToString()); category = category.Save(); Assert.Fail("Record exists when it should have been deleted."); } catch (Exception) { // Exception was thrown if record doesn't exist. Assert.IsTrue(true); } Assert.IsTrue(string.Equals(category.CategoryId, TestCategoryID, StringComparison.InvariantCultureIgnoreCase)); Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds); }