Created
November 23, 2020 18:16
-
-
Save Ganeshcse/095c3fa5bb6ccaee22198beab1062557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object which should be returned as out parameter from another mock object | |
var mockedObject = MockRepository.GenerateMock<IRealTimeData>(); | |
mockedObject.Expect(x => x.HeatValue).Return(30); | |
// Mock object which has method GetRealTimeData(out var ...) with out params as IRealTimeData | |
serverMockObject.Expect(x => x.GetRealTimeData(out _)).OutRef(mockedObject).Return(true); | |
var actualValue = serice.GetHeatValue(); | |
// Inside the implementation of above method, see below. | |
private void GetRealTimeData(out IRealTimeData ealTimeData) | |
{ | |
//... | |
} | |
public double GetHeat() | |
{ | |
GetRealTimeData(out var realTimeData); // At this statement the object realTimeData contains the data that I am mocking from unit test | |
if(realTimeData != null) | |
var absoluteHeat = realTimeData.HeatValue; // At this statement the object realTimeData resets the value of all properties. | |
// if I try to skip the null condition and directly execute line no. #20 then I am able to get the value that I am setting from | |
// unit test. | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment