public void GetParentIDAccessor_ClassWithNoDetectableParentID() { var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.ClassWithInsufficientData), null, null); // FindParentIDAccessor does not throw an exception like FindIDAccessor does: Assert.AreEqual(0, result.Count()); }
public void GetIDAccessor_ClassNamePlusUnderscoreID() { var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("ClassWithSuffixedUnderscore_ID", result.ElementAt(0)); }
public void GetIDAccessor_ClassWithNoDetectableID() { var ex = Assert.Throws <InvalidOperationException>(() => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithInsufficientData))); Assert.That(ex.Message, Is.StringStarting("Cannot find a way to get the ID from")); }
public void GetParentIDAccessor_ByAttribute() { var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.InvoiceLineWithAttributes), null, null); Assert.AreEqual(1, result.Count()); Assert.AreEqual("Invoice_id", result.ElementAt(0)); }
public void FindParentIDAccessor_ChildWithGenericNames() { var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.ChildWithGenericNames), null, null); Assert.AreEqual(1, result.Count()); Assert.AreEqual("ParentID", result.ElementAt(0)); }
public void GetIDAccessor_ByName() { //-----------------test single fields----------------- var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "ID"); Assert.AreEqual(1, result.Count()); Assert.AreEqual("ID", result.ElementAt(0)); result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "AnotherID"); Assert.AreEqual(1, result.Count()); Assert.AreEqual("AnotherID", result.ElementAt(0)); //-----------------test multiple fields----------------- result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "ID, AnotherID"); Assert.AreEqual(2, result.Count()); Assert.AreEqual("ID", result.ElementAt(0)); Assert.AreEqual("AnotherID", result.ElementAt(1)); // take out the spaces result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "ID,AnotherID"); Assert.AreEqual(2, result.Count()); Assert.AreEqual("ID", result.ElementAt(0)); Assert.AreEqual("AnotherID", result.ElementAt(1)); // reverse the order result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID), "AnotherID, ID"); Assert.AreEqual(2, result.Count()); Assert.AreEqual("AnotherID", result.ElementAt(0)); Assert.AreEqual("ID", result.ElementAt(1)); }
public void GetIDAccessor_ClassNamePlusId_WithOtherIdFields() { var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixed)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("ClassWithSuffixedId", result.ElementAt(0)); }
public void GetParentIDAccessor_UseParentsIDToGetParentID() { var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.InvoiceLine), null, typeof(TestClasses.Invoice)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("Invoice_id", result.ElementAt(0)); }
public void GetIDAccessor_ClassNamePlusUnderscoreID_MultipleOptions() { var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.InvoiceLine)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("InvoiceLine_id", result.ElementAt(0)); }
public void GetIDAccessor_PlainID() { var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithPlainID)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("ID", result.ElementAt(0)); }
public void GetParentIDAccessor_WhenPKIsJustId_Underscored() { var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.Glass238b), null, typeof(TestClasses.Beer238)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("Beer238_ID", result.ElementAt(0)); }
public void FindParentIDAccessor_RespectReservedWords() { // This is case in the rules, a field ending in _ParentID var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.Parent), null, typeof(TestClasses.Grandparent)); Assert.AreEqual(1, result.Count()); Assert.AreEqual("GrandparentID", result.ElementAt(0)); }
public void GetIDAccessor_ByMultiAttribute() { var result = ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.InvoiceLineWithMultiAttributes)); Assert.AreEqual(2, result.Count()); Assert.AreEqual("InvoiceLine_id", result.ElementAt(0)); Assert.AreEqual("Company_id", result.ElementAt(1)); }
public void FindParentIDAccessor_ChildEndingWithParentID() { // This is case in the rules, a field ending in ParentID var result = ChildMapperTestingHelper.FindParentIDAccessor(typeof(TestClasses.ChildEndingWithParentID), null, null); Assert.AreEqual(1, result.Count()); Assert.AreEqual("MyParentID", result.ElementAt(0)); }
public void GetIDAccessor_ByName_BadName() { var ex = Assert.Throws <InvalidOperationException>(() => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "foo123")); Assert.That(ex.Message, Is.StringContaining("foo123")); ex = Assert.Throws <InvalidOperationException>(() => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "ClassWithSuffixedUnderscore_ID, foo123")); Assert.That(ex.Message, Is.StringContaining("foo123")); ex = Assert.Throws <InvalidOperationException>(() => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "foo123, ClassWithSuffixedUnderscore_ID")); Assert.That(ex.Message, Is.StringContaining("foo123")); // we could clean up trailing commas, but this test verifies current behavior ex = Assert.Throws <InvalidOperationException>(() => ChildMapperTestingHelper.GetIDAccessor(typeof(TestClasses.ClassWithSuffixedUnderscore), "ID, ")); }