Scott,
Thanks for the tips. I have tried both and neither of them were successful. Here is what I experienced:
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(new ContentBlock().EkItem.Html, "<p>Hello World!</p>");
recorder.CheckArguments();
}
This failed on the recorder.ExpectAndReturn line with the following error:
TestCase 'NationalFinancial.BAC.Tests.Unit.Core.Models.XmlSmartFormBlockBehaviour.ShouldCreateMatchingXml' failed: TypeMock.TypeMockException:
*** Method get_EkItem in type Ektron.Cms.Controls.ContentBlock cannot return System.String
at TypeMock.RecordExpectations.Return(Object returnValue)
at TypeMock.RecordExpectations.ExpectAndReturn(Object mockedStatements, Object returnValue)
C:clientWorkNationalFinancialBACsrcTests.UnitCoreModelsXmlSmartFormBlockBehaviour.cs(37,0): at NationalFinancial.BAC.Tests.Unit.Core.Models.XmlSmartFormBlockBehaviour.ShouldCreateMatchingXml()
The second sample (listed below) is something I'd already tried before posting but tried again for good measure.
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
Ektron.Cms.Common.ContentBase mockedBase = new Ektron.Cms.Common.ContentBase();
ContentBlock mockedBlock = new ContentBlock();
recorder.ExpectAndReturn(mockedBlock.EkItem, mockedBase).RepeatAlways();
recorder.ExpectAndReturn(mockedBlock.Title, "Hello World Test");
recorder.ExpectAndReturn(mockedBase.Html, "<p>Hello World!</p>");
recorder.CheckArguments();
}
This sample fails with the following error:
TestCase 'NationalFinancial.BAC.Tests.Unit.Core.Models.XmlSmartFormBlockBehaviour.ShouldCreateMatchingXml' failed: TypeMock.TypeMockException:
*** Method get_Title in type Ektron.Cms.Controls.EkXsltWebPart already has a mocked return value
Perhaps you are trying to mock a method from mscorlib
at TypeMock.RecordExpectations.Return(Object returnValue)
at TypeMock.RecordExpectations.ExpectAndReturn(Object mockedStatements, Object returnValue)
C:clientWorkNationalFinancialBACsrcTests.UnitCoreModelsXmlSmartFormBlockBehaviour.cs(47,0): at NationalFinancial.BAC.Tests.Unit.Core.Models.XmlSmartFormBlockBehaviour.ShouldCreateMatchingXml()
.
Let me know what you need more from me. Any other tips for how I might be able to get this to work are greatly appreciated. I can't figure out another way to test this particular code.