public ITestProperty SetObject(ITestObject testObject) { AssertIsVisible(); AssertIsModifiable(); ResetLastMessage(); Assert.IsFalse(field.Specification.IsParseable, "Drop(..) not allowed on value target field; use SetValue(..) instead"); INakedObject testNakedObject = testObject.NakedObject; Assert.IsTrue(testNakedObject.Specification.IsOfType(field.Specification), string.Format("Can't drop a {0} on to the {1} field (which accepts {2})", testObject.NakedObject.Specification.ShortName, Name, field.Specification)); INakedObject nakedObject = owningObject.NakedObject; IConsent valid; if (field is IOneToOneAssociation) { valid = ((IOneToOneAssociation) field).IsAssociationValid(nakedObject, testNakedObject); } else if (field is IOneToManyAssociation) { valid = new Veto("Always disabled"); } else { throw new UnknownTypeException(field); } LastMessage = valid.Reason; Assert.IsFalse(valid.IsVetoed, string.Format("Cannot SetObject {0} in the field {1} within {2}: {3}", testNakedObject, field, nakedObject, valid.Reason)); if (field is IOneToOneAssociation) { ((IOneToOneAssociation) field).SetAssociation(nakedObject, testNakedObject); } return this; }
public ITestProperty RemoveFromCollection(ITestObject testObject) { AssertIsVisible(); AssertIsModifiable(); ResetLastMessage(); Assert.IsTrue(field.IsCollection, "Cannot remove from non collection"); INakedObject testNakedObject = testObject.NakedObject; Assert.IsTrue(testNakedObject.Specification.IsOfType(field.Specification), string.Format("Can't clear a {0} from the {1} field (which accepts {2})", testObject.NakedObject.Specification.ShortName, Name, field.Specification)); INakedObject nakedObject = owningObject.NakedObject; if (!(field is IOneToManyAssociation)) { throw new UnknownTypeException(field); } IConsent valid = new Veto("Always disabled"); Assert.IsFalse(valid.IsVetoed, string.Format("Can't remove {0} from the field {1} within {2}: {3}", testNakedObject, field, nakedObject, valid.Reason)); return this; }