public void Test_BusinessObject_WhenSet_HavingNonExistingChildRelationshipForRelatedBo_ShouldThrowError() { //---------------Set up test pack------------------- IClassDef contactPersonClassDef = ClassDef.Get <ContactPersonTestBO>(); ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); contactPersonTestBO.Organisation = new OrganisationTestBO(); const string innerRelationshipName = "Addresses"; const string outerRelationshipName = "NonExistingRelationship"; const string relationshipName = outerRelationshipName + "." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- try { boRelationshipMapper.BusinessObject = contactPersonTestBO; Assert.Fail("Expected to throw a HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (RelationshipNotFoundException ex) { StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '" + contactPersonClassDef.ClassName + "' cannot be found. Please contact your system administrator.", ex.Message); /* StringAssert.Contains("The relationship '" + outerRelationshipName + "' does not exist on the BusinessObject '" + contactPersonClassDef.ClassNameFull + "'", ex.DeveloperMessage);*/ Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); } }
/// <summary> /// Constructs a <see cref="RelationshipComboBoxMapper"/> with the <paramref name="comboBox"/> /// <paramref name="relationshipName"/> /// </summary> /// <param name="comboBox">The combo box that is being mapped to</param> /// <param name="relationshipName">The name of the relation that is being mapped to</param> /// <param name="isReadOnly">Whether the Combo box can be used to edit from or whether it is only viewable</param> /// <param name="controlFactory">A control factory that is used to create control mappers etc</param> public RelationshipComboBoxMapper (IComboBox comboBox, string relationshipName, bool isReadOnly, IControlFactory controlFactory) { if (comboBox == null) { throw new ArgumentNullException("comboBox"); } if (relationshipName == null) { throw new ArgumentNullException("relationshipName"); } if (controlFactory == null) { throw new ArgumentNullException("controlFactory"); } IsReadOnly = isReadOnly; ControlFactory = controlFactory; Control = comboBox; RelationshipName = relationshipName; _boRelationshipMapper = new BORelationshipMapper(relationshipName); _boRelationshipMapper.RelationshipChanged += (sender, e) => OnMappedRelationshipChanged(); _mapperStrategy = ControlFactory.CreateLookupComboBoxDefaultMapperStrategy(); _mapperStrategy.AddHandlers(this); UpdateIsEditable(); _comboBoxCollectionSelector = new ComboBoxCollectionSelector(comboBox, controlFactory, false) { PreserveSelectedItem = true }; this.IncludeBlankItem = true; }
public void Test_BusinessObject_WhenSet_HavingExistingNonSingleRelationshipOnRelatedBO_ShouldThrowError() { //---------------Set up test pack------------------- ClassDef.ClassDefs.Clear(); AddressTestBO.LoadDefaultClassDef(); IClassDef contactPersonClassDef = ContactPersonTestBO.LoadClassDefWithAddressesRelationship_DeleteRelated(); ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string innerRelationshipName = "ContactPersonTestBO"; const string outerRelationshipName = "Addresses"; const string relationshipName = outerRelationshipName + "." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- try { boRelationshipMapper.BusinessObject = contactPersonTestBO; Assert.Fail("Expected to throw a HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (HabaneroDeveloperException ex) { StringAssert.Contains("The relationship '" + outerRelationshipName + "' on '" + contactPersonClassDef.ClassName + "' is not a Single Relationship. Please contact your system administrator.", ex.Message); StringAssert.Contains("The relationship '" + outerRelationshipName + "' on the BusinessObject '" + contactPersonClassDef.ClassNameFull + "' is not a Single Relationship therefore cannot be traversed.", ex.DeveloperMessage); Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); } }
public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedRelationship_ShouldNotFireRelationshipChangedEvent() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string relationshipName = "SomeNonExistentRelationship"; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); bool eventFired = false; boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true; //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); Assert.IsFalse(eventFired); //---------------Execute Test ---------------------- try { boRelationshipMapper.BusinessObject = contactPersonTestBO; Assert.Fail("Expected to throw an Exception"); } //---------------Test Result ----------------------- catch (Exception) { Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); Assert.IsFalse(eventFired); } }
public void Test_BusinessObject_WhenSetWithBONotHavingSpecifiedRelationship_ShouldThrowError() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string relationshipName = "SomeNonExistentRelationship"; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- try { boRelationshipMapper.BusinessObject = contactPersonTestBO; Assert.Fail("Expected to throw a HabaneroDeveloperException"); } //---------------Test Result ----------------------- catch (RelationshipNotFoundException ex) { StringAssert.Contains("The relationship '" + relationshipName + "' on '" + contactPersonTestBO.ClassDef.ClassName + "' cannot be found. Please contact your system administrator.", ex.Message); /* StringAssert.Contains("The relationship '" + relationshipName + "' does not exist on the BusinessObject '" + contactPersonTestBO.ClassDef.ClassNameFull + "'", ex.DeveloperMessage);*/ Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); } }
public void Test_Construct() { //---------------Set up test pack------------------- string relationshipName = TestUtil.GetRandomString(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Test Result ----------------------- Assert.AreEqual(relationshipName, boRelationshipMapper.RelationshipName); Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); }
public void Test_BusinessObject_GetAndSet() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string relationshipName = "Organisation"; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); //---------------Execute Test ---------------------- boRelationshipMapper.BusinessObject = contactPersonTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); }
public void Test_BusinessObject_WhenSetWithBOHavingSpecifiedRelationship_ShouldReturnCorrectRelationship() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string relationshipName = "Organisation"; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- boRelationshipMapper.BusinessObject = contactPersonTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(contactPersonTestBO.Relationships[relationshipName], boRelationshipMapper.Relationship); }
public void Test_BusinessObject_WhenSetToNull_ShouldReturnNullRelationship() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string relationshipName = "Organisation"; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); boRelationshipMapper.BusinessObject = contactPersonTestBO; //---------------Assert Precondition---------------- Assert.IsNotNull(boRelationshipMapper.BusinessObject); Assert.IsNotNull(boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- boRelationshipMapper.BusinessObject = null; //---------------Test Result ----------------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); }
public void Test_BusinessObject_WhenSet_HavingRelationshipOnRelatedBO_ShouldReturnRelatedBOsRelationship() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); contactPersonTestBO.Organisation = new OrganisationTestBO(); const string innerRelationshipName = "ContactPeople"; const string relationshipName = "Organisation." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- boRelationshipMapper.BusinessObject = contactPersonTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(contactPersonTestBO.Organisation.Relationships[innerRelationshipName], boRelationshipMapper.Relationship); }
public void Test_BusinessObject_WhenSetWithBOHavingSpecifiedRelationship_ShouldFireRelationshipChangedEvent() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); const string relationshipName = "Organisation"; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); bool eventFired = false; boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true; //---------------Assert Precondition---------------- Assert.IsNull(boRelationshipMapper.BusinessObject); Assert.IsNull(boRelationshipMapper.Relationship); Assert.IsFalse(eventFired); //---------------Execute Test ---------------------- boRelationshipMapper.BusinessObject = contactPersonTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(contactPersonTestBO.Relationships[relationshipName], boRelationshipMapper.Relationship); Assert.IsTrue(eventFired); }
public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingRelationshipOnRelatedBO_ShouldFireRelationshipChangedEvent() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerRelationshipName = "ContactPeople"; const string relationshipName = "Organisation." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); boRelationshipMapper.BusinessObject = contactPersonTestBO; OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO(); bool eventFired = false; boRelationshipMapper.RelationshipChanged += (sender, e) => eventFired = true; //---------------Assert Precondition---------------- Assert.IsFalse(eventFired); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = newOrganisationTestBO; //---------------Test Result ----------------------- Assert.IsTrue(eventFired); }
public void Test_ChangeRelatedBO_WhenSetToDifferentBo_HavingRelationshipOnRelatedBO_ShouldChangeRelationship() { //---------------Set up test pack------------------- ContactPersonTestBO contactPersonTestBO = new ContactPersonTestBO(); OrganisationTestBO oldOrganisationTestBO = new OrganisationTestBO(); contactPersonTestBO.Organisation = oldOrganisationTestBO; const string innerRelationshipName = "ContactPeople"; const string relationshipName = "Organisation." + innerRelationshipName; BORelationshipMapper boRelationshipMapper = new BORelationshipMapper(relationshipName); boRelationshipMapper.BusinessObject = contactPersonTestBO; OrganisationTestBO newOrganisationTestBO = new OrganisationTestBO(); //---------------Assert Precondition---------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(oldOrganisationTestBO.Relationships[innerRelationshipName], boRelationshipMapper.Relationship); //---------------Execute Test ---------------------- contactPersonTestBO.Organisation = newOrganisationTestBO; //---------------Test Result ----------------------- Assert.AreSame(contactPersonTestBO, boRelationshipMapper.BusinessObject); Assert.AreSame(newOrganisationTestBO.Relationships[innerRelationshipName], boRelationshipMapper.Relationship); }