public void LoadValueCalledAgainWithInterimFalse_HasBusinessObjectCreatedTrue_BoundPropertyContainsValue_DoesNotCreateDefaultValue() { _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(null).Repeat.Once(); _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); var oldValue = MockRepository.GenerateStub <IBusinessObject> (); _referencePropertyStub.Stub(stub => stub.CreateDefaultValue(_referencedDataSourceStub.BusinessObject)) .Return(oldValue) .Repeat.Once(); var expectedValue = MockRepository.GenerateStub <IBusinessObject> (); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(expectedValue).Repeat.Once(); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.True); Assert.That(referenceDataSource.BusinessObject, Is.SameAs(oldValue)); referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.False); Assert.That(referenceDataSource.BusinessObject, Is.SameAs(expectedValue)); }
public void SetValue_OldValueIsNewlyCreatedDefaultValue() { _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(null).Repeat.Once(); _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); _referencePropertyStub.Stub(stub => stub.SupportsDelete).Return(true); var oldValue = MockRepository.GenerateStub <IBusinessObject> (); _referencePropertyStub.Stub(stub => stub.CreateDefaultValue(_referencedDataSourceStub.BusinessObject)) .Return(oldValue) .Repeat.Once(); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.True); Assert.That(referenceDataSource.BusinessObject, Is.SameAs(oldValue)); referenceDataSource.BusinessObject = null; Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.False); Assert.That(referenceDataSource.BusinessObject, Is.Null); _referencePropertyStub.AssertWasCalled(stub => stub.Delete(_referencedDataSourceStub.BusinessObject, oldValue)); }
public void LoadsValuesForBoundControls() { var referencedObject = MockRepository.GenerateStub <IBusinessObject>(); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(referencedObject); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); var firstControlMock = MockRepository.GenerateMock <IBusinessObjectBoundControl>(); firstControlMock.Stub(stub => stub.HasValidBinding).Return(true); referenceDataSource.Register(firstControlMock); var secondControlMock = MockRepository.GenerateMock <IBusinessObjectBoundControl>(); secondControlMock.Stub(stub => stub.HasValidBinding).Return(true); referenceDataSource.Register(secondControlMock); firstControlMock.Expect(mock => mock.LoadValue(false)) .WhenCalled(mi => Assert.That(referenceDataSource.BusinessObject, Is.SameAs(referencedObject))); secondControlMock.Expect(mock => mock.LoadValue(false)) .WhenCalled(mi => Assert.That(referenceDataSource.BusinessObject, Is.SameAs(referencedObject))); referenceDataSource.LoadValue(false); firstControlMock.VerifyAllExpectations(); secondControlMock.VerifyAllExpectations(); }
public void ReferencedDataSourceBusinessObjectNull_ClearsHasBusinessObjectCreated() { _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); _referencePropertyStub.Stub(stub => stub.CreateDefaultValue(null)).IgnoreArguments().Return(MockRepository.GenerateStub <IBusinessObject>()); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.Not.Null); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.True); _referencedDataSourceStub.BusinessObject = null; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.Null); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.False); }
public void ReferencedPropertyNull_DoesNotSetBusinessObject_DoesNotClearHasBusinessObjectChanged() { var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, null); var expectedValue = MockRepository.GenerateStub <IBusinessObject>(); referenceDataSource.BusinessObject = expectedValue; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.SameAs(expectedValue)); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.True); }
public void ReferencedDataSourceBusinessObjectNull_SetsBusinessObjectNull() { _referencedDataSourceStub.BusinessObject = null; var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.BusinessObject = MockRepository.GenerateStub <IBusinessObject>(); referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.Null); }
public void ReferencedDataSourceBusinessObjectNull_DoesNotCreateDefaultValue() { _referencedDataSourceStub.BusinessObject = null; var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.BusinessObject = null; referenceDataSource.LoadValue(false); _referencePropertyStub.AssertWasNotCalled(stub => stub.SupportsDefaultValue); _referencePropertyStub.AssertWasNotCalled(stub => stub.CreateDefaultValue(null), options => options.IgnoreArguments()); }
public void HasBusinessObjectChangedFalse_BusinessObjectNull_DoesNotSaveValueIntoBoundObject_AndReturnsTrue() { var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(null); referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.False); var result = referenceDataSource.SaveValue(false); Assert.That(result, Is.True); _referencedDataSourceStub.BusinessObject.AssertWasNotCalled(stub => stub.SetProperty(null, null), options => options.IgnoreArguments()); }
public void ReferencedDataSourceBusinessObjectNull_ClearsHasBusinessObjectChanged() { _referencedDataSourceStub.BusinessObject = null; var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.BusinessObject = MockRepository.GenerateStub <IBusinessObject> (); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.True); referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.False); }
public void ReferencedDataSourceBusinessObjectNull_DoesNotLoadValueFromProperty() { var parentObjectStub = _referencedDataSourceStub.BusinessObject; _referencedDataSourceStub.BusinessObject = null; var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.BusinessObject = MockRepository.GenerateStub <IBusinessObject> (); referenceDataSource.LoadValue(false); parentObjectStub.AssertWasNotCalled(stub => stub.GetProperty(null), options => options.IgnoreArguments()); }
public void SupportsDefaultValueFalse_DoesNotSetDefaultValue() { _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(null); _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(false); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.Null); _referencePropertyStub.AssertWasNotCalled(stub => stub.CreateDefaultValue(Arg <IBusinessObject> .Is.Anything)); }
public void LoadsValueFromBoundObject() { var expectedValue = MockRepository.GenerateStub <IBusinessObject>(); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(expectedValue); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.BusinessObject = null; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.SameAs(expectedValue)); }
public void PropertyIsReadOnly_DoesNotSaveValueIntoBoundObject() { var expectedValue = MockRepository.GenerateStub <IBusinessObject>(); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_readOnlyReferencePropertyStub)).Return(expectedValue); _readOnlyReferencePropertyStub.ReferenceClass.Stub(stub => stub.RequiresWriteBack).Return(true); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _readOnlyReferencePropertyStub); referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.False); Assert.That(() => referenceDataSource.SaveValue(false), Throws.Exception); _referencedDataSourceStub.BusinessObject.AssertWasNotCalled(stub => stub.SetProperty(null, null), options => options.IgnoreArguments()); }
public void SetsDefaultValue_SetHasBusinessObjectCreated() { _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(null); _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); var expectedValue = MockRepository.GenerateStub <IBusinessObject> (); _referencePropertyStub.Stub(stub => stub.CreateDefaultValue(_referencedDataSourceStub.BusinessObject)).Return(expectedValue); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.True); }
public void HasValueFromProperty_DoesNotSetDefaultValue() { _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)) .Return(MockRepository.GenerateStub <IBusinessObject>()); _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); _referencePropertyStub.Stub(stub => stub.CreateDefaultValue(_referencedDataSourceStub.BusinessObject)) .Return(MockRepository.GenerateStub <IBusinessObject> ()); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.BusinessObject, Is.Not.Null); }
public void PropertyIsReadWrite_SavesValueIntoBoundObject_AndReturnsTrue() { var expectedValue = MockRepository.GenerateStub <IBusinessObject>(); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_referencePropertyStub)).Return(expectedValue); _referencePropertyStub.ReferenceClass.Stub(stub => stub.RequiresWriteBack).Return(true); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.False); var result = referenceDataSource.SaveValue(false); Assert.That(result, Is.True); _referencedDataSourceStub.BusinessObject.AssertWasCalled(stub => stub.SetProperty(_referencePropertyStub, expectedValue)); }
public void HasBusinessObjectCreatedTrue_ReadsBusinessObject_SavesValueIntoBoundObject_AndReturnsTrue() { var expectedValue = MockRepository.GenerateStub <IBusinessObject> (); _referencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); _referencePropertyStub.Stub(stub => stub.CreateDefaultValue(_referencedDataSourceStub.BusinessObject)).Return(expectedValue); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _referencePropertyStub); referenceDataSource.Mode = DataSourceMode.Edit; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectCreated, Is.True); var result = referenceDataSource.SaveValue(false); Assert.That(result, Is.True); _referencedDataSourceStub.BusinessObject.AssertWasCalled(stub => stub.SetProperty(_referencePropertyStub, expectedValue)); }
public void PropertyIsReadOnly_ThrowsInvalidOperationException() { var expectedValue = MockRepository.GenerateStub <IBusinessObject>(); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_readOnlyReferencePropertyStub)).Return(expectedValue); _readOnlyReferencePropertyStub.ReferenceClass.Stub(stub => stub.RequiresWriteBack).Return(true); _readOnlyReferencePropertyStub.Stub(stub => stub.Identifier).Return("TestProperty"); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _readOnlyReferencePropertyStub); referenceDataSource.ID = "TestDataSource"; referenceDataSource.LoadValue(false); Assert.That(referenceDataSource.HasBusinessObjectChanged, Is.False); Assert.That( () => referenceDataSource.SaveValue(false), Throws.InvalidOperationException.With.Message.EqualTo( "The business object of the TestDataSource could not be saved into the domain model " + "because the property 'TestProperty' is read only.")); _referencedDataSourceStub.BusinessObject.AssertWasNotCalled(stub => stub.SetProperty(null, null), options => options.IgnoreArguments()); }
public void PropertyIsReadOnly_IsDefaultValue_ThrowsInvalidOperationException() { var referencedObject = MockRepository.GenerateStub <IBusinessObject> (); _readOnlyReferencePropertyStub.Stub(stub => stub.SupportsDefaultValue).Return(true); _readOnlyReferencePropertyStub.Stub(stub => stub.IsDefaultValue(null, null, null)).IgnoreArguments().Return(true); _readOnlyReferencePropertyStub.Stub(stub => stub.SupportsDelete).Return(true); _readOnlyReferencePropertyStub.Stub(stub => stub.Identifier).Return("TestProperty"); _referencedDataSourceStub.BusinessObject.Stub(stub => stub.GetProperty(_readOnlyReferencePropertyStub)).Return(referencedObject); var referenceDataSource = new TestableBusinessObjectReferenceDataSource(_referencedDataSourceStub, _readOnlyReferencePropertyStub); referenceDataSource.ID = "TestDataSource"; referenceDataSource.LoadValue(false); Assert.That( () => referenceDataSource.SaveValue(false), Throws.InvalidOperationException.With.Message.EqualTo( "The TestableBusinessObjectReferenceDataSource 'TestDataSource' could not be marked as changed " + "because the bound property 'TestProperty' is read only.")); Assert.That(referenceDataSource.BusinessObject, Is.Null); }