public void TestThatGetSourceValueGetsSourceValue() { var fieldMock = MockRepository.GenerateMock <IField>(); Assert.That(fieldMock, Is.Not.Null); var dataObject = new MyDataObject(fieldMock, new Fixture()); Assert.That(dataObject, Is.Not.Null); var sourceValue = dataObject.GetSourceValue <string>(); Assert.That(sourceValue, Is.Not.Null); Assert.That(sourceValue, Is.Not.Empty); }
public void TestThatGetTargetValueThrowsDeliveryEngineMappingExceptionWithInnerExceptionIfDeliveryEngineMappingExceptionOccursInMapper() { var fixture = new Fixture(); fixture.Customize <IDeliveryEngineMappingExceptionInfo>(e => e.FromFactory(() => MockRepository.GenerateMock <IDeliveryEngineMappingExceptionInfo>())); var mapException = fixture.CreateAnonymous <DeliveryEngineMappingException>(); var mapMock = MockRepository.GenerateMock <IMap>(); mapMock.Expect(m => m.MapValue <string, string>(Arg <string> .Is.NotNull)) .Throw(mapException) .Repeat.Any(); var tableMock = MockRepository.GenerateMock <ITable>(); tableMock.Expect(m => m.NameTarget) .Return(fixture.CreateAnonymous <string>()) .Repeat.Any(); var fieldMock = MockRepository.GenerateMock <IField>(); fieldMock.Expect(m => m.Table) .Return(tableMock) .Repeat.Any(); fieldMock.Expect(m => m.NameTarget) .Return(fixture.CreateAnonymous <string>()) .Repeat.Any(); fieldMock.Expect(m => m.DatatypeOfSource) .Return(typeof(string)) .Repeat.Any(); fieldMock.Expect(m => m.Map) .Return(mapMock) .Repeat.Any(); Assert.That(fieldMock, Is.Not.Null); var dataObject = new MyDataObject(fieldMock, new Fixture()); Assert.That(dataObject, Is.Not.Null); var exception = Assert.Throws <DeliveryEngineMappingException>(() => dataObject.GetTargetValue <string>()); Assert.That(exception, Is.Not.Null); Assert.That(exception.Message, Is.Not.Null); Assert.That(exception.Message, Is.Not.Empty); Assert.That(exception.Message, Is.StringStarting(Resource.GetExceptionMessage(ExceptionMessage.UnableToMapValueForField, dataObject.GetSourceValue <string>(), fieldMock.NameTarget, tableMock.NameTarget, string.Empty))); var innerException = exception.InnerException; Assert.That(innerException, Is.Not.Null); Assert.That(innerException, Is.TypeOf <DeliveryEngineMappingException>()); Assert.That(innerException.Message, Is.Not.Null); Assert.That(innerException.Message, Is.Not.Empty); fieldMock.AssertWasCalled(m => m.NameTarget); tableMock.AssertWasCalled(m => m.NameTarget); }