/// <summary> /// Add a method to the object, will remove the previously set method if there is one. Generates a randomized return object based on the type /// </summary> /// <param name="methodName">The method to mock</param> /// <param name="expectedReturnType">The return type to simulate</param> private void UpsertMethod(string methodName, Type expectedReturnType) { Func <object> del; if (expectedReturnType.IsClass && expectedReturnType != typeof(string)) { del = () => RandomDataGenerator.GenerateRawTestValueForClass(expectedReturnType); } else { del = () => RandomDataGenerator.GenerateRawTestValue(expectedReturnType); } if (MockedMembers.ContainsKey(methodName)) { MockedMembers.Remove(methodName); } MockedMembers.Add(methodName, del); }
/// <summary> /// Add a method to the object, will remove the previously set method if there is one. Returns the initial value set /// </summary> /// <param name="methodName">The method to mock</param> /// <param name="returnValue">The actual value to return</param> private void UpsertMethod(string methodName, object returnValue, Dictionary <string, object> outParams) { Func <object> del = () => returnValue; if (MockedMembers.ContainsKey(methodName)) { MockedMembers.Remove(methodName); } //Always remove them if we're overloading an existing mock if (OutParameters.ContainsKey(methodName)) { OutParameters.Remove(methodName); } //Only add this if there are any to bother with if (outParams.Any()) { OutParameters.Add(methodName, outParams); } MockedMembers.Add(methodName, del); }