public void TestForDuplicateNewObjects() { //create the first object ContactPerson myContact_1 = new ContactPerson(); //Edit first object and save myContact_1.FirstName = "My FirstName"; myContact_1.Surname = "My Surname"; myContact_1.SetPropertyValue("PK2Prop1", "PK2Prop1Value1" + TestUtil.GetRandomString()); myContact_1.SetPropertyValue("PK2Prop2", "PK2Prop1Value2" + TestUtil.GetRandomString()); myContact_1.Save(); // //get the second new object from the object manager; ContactPerson myContact_2 = new ContactPerson(); //set this new object to have the same // data as the already saved object myContact_2.Surname = "My Surname"; myContact_2.SetPropertyValue("PK2Prop1", myContact_1.GetPropertyValue("PK2Prop1")); myContact_2.SetPropertyValue("PK2Prop2", myContact_1.GetPropertyValue("PK2Prop2")); try { myContact_2.Save(); Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException"); } //---------------Test Result ----------------------- catch (BusObjDuplicateConcurrencyControlException ex) { StringAssert.Contains("A 'Contact Person' already exists with the same identifier", ex.Message); } }
public void TestForDuplicateNewObjectsSinglePropKeyNull() { //create the first object ContactPerson myContact_1 = new ContactPerson(); //Edit first object and save myContact_1.Surname = "My Surname SinglePropKeyNull"; myContact_1.SetPropertyValue("PK3Prop", null); // set the previous value to null myContact_1.Save(); // //get the second new object from the object manager ContactPerson myContact_2 = new ContactPerson(); //set this new object to have the same // data as the already saved object myContact_2.Surname = "My Surname SinglePropKeyNull"; myContact_2.SetPropertyValue("PK3Prop", myContact_1.GetPropertyValue("PK3Prop")); // set the previous value to null try { myContact_2.Save(); Assert.Fail("Expected to throw an BusObjDuplicateConcurrencyControlException"); } //---------------Test Result ----------------------- catch (BusObjDuplicateConcurrencyControlException ex) { StringAssert.Contains("A 'Contact Person' already exists with the same identifier", ex.Message); } }