Hi Guys,
Thanks for the response, it did come in handy but not quite what I was looking for. I did figure it out though. Let me try to clarify.
The RateController.SavePlateRateWithReturnValue method returns the OkNegotiatedContentResult with a content created by this call chain:
LogicRepository.SaveRate (Rate rate) ->
Rate.SaveRate(int staff, bool open) ->
PRate.SavePRate ( string key, bool open) ->
DBRate.SavePR(Rate, rate) ->
DB.ExecuteScalar(string procName, Rate rate) (OLEDB layer)
I want to fake the DB.ExecuteScalar method or the DBRate.SavePR method in so that a database is not required in order to run the test.
My basic problem was fuzzy thinking I did not have to fake the OkNegotiatedContentResult, just the DBRate method and let TypeMock take care of doing that at the right time.
My Current Test successful code looks like this:
[TestMethod]
public void A_New_PlateRate_Can_Be_Successfully_Saved()
{
Settings temp = new Settings
{
Database = "PlateTech",
LoggingLevel = "4",
Password = "",
SQLDataSource = "",
UserId = ""
};
SKIDATA.SDUSA.PlateTechAdmin.PlateRate pr = new SKIDATA.SDUSA.PlateTechAdmin.PlateRate()
{
Comments = "Initial Comment",
PlateNumber = "ABC123",
UpdateStaffRecNum = 5,
Used = true
};
PTMessage retMsg = new PTMessage
{
OperationStatus = true
};
var utilRepo = Isolate.Fake.NextInstance<PTUtilityRepository>(Members.ReturnRecursiveFakes);
Isolate.WhenCalled(() => utilRepo.CheckWebServicePrerequisites(ActionEnums.eActions.AuthorizationsUse, ActionEnums.eActions.AuthorizationsEdit)).WillReturn(retMsg);
var fakePlateRate = Isolate.Fake.AllInstances<DBPlateRate>(Members.ReturnRecursiveFakes);
PlateRateController prc = new PlateRateController();
OkNegotiatedContentResult<PTMessage> result = prc.SavePlateRateWithReturnValue(pr) as OkNegotiatedContentResult<PTMessage>;
Isolate.Verify.WasCalledWithExactArguments(() => fakePlateRate.SavePlateRate(pr));
Assert.AreEqual(true, result.Content.OperationStatus);
Assert.AreEqual("Plate Rate saved.", result.Content.MessageText);
Assert.AreEqual(0, result.Content.ReturnObject.Count);
}
}
Thanks very much for your help.