how can I mock the below function in JustMock Lite?

  Uncategorised

I am trying to write the unit test for the below function but unable to think of some correct logic that can work properly.

private static Dictionary<string, Dictionary<string, object>> keyValuePairs = new Dictionary<string, Dictionary<string, object>>();

public void SetValue(string id, string key, object payload)
        {
            if (keyValuePairs.ContainsKey(id))
            {
                keyValuePairs[id][key] = payload;
            }
            else
            {
                keyValuePairs[id] = new Dictionary<string, object>();
                keyValuePairs[id][key] = payload;
            }
        }

I have written a mock function to test this, but so far unable to get the success.
Below are some mock variables I created to start the test

        //Arrange
        private static Dictionary<string, object> valuePairs = new Dictionary<string, object>()
            {
                { mockKey1, "mock-value1"},
                { mockKey2, "mock-value2"},
            };
       private Dictionary<string, Dictionary<string, object>> mockKeyValuePairs = new Dictionary<string, Dictionary<string, object>>() {
                 {mockID, valuePairs}
            };
        private Dictionary<string, object> mockPayload = new Dictionary<string, object>() {
                  {mockKey3, "mock-value3"}
            };

this is the function I am trying to write. I got success in the GetValue functions
but unable to think about this one.

public void CacheControl_SetValue()
        {
            //Mock.Arrange(() => mockKeyValuePairs.ContainsKey(mockID)).Returns((bool)true);
            //Mock.Arrange(() => mockKeyValuePairs[mockID].Add(mockKey3, "mock-value3"));
//above calls are failing because of Lite Version

/*below is some gibberish, I was trying*/
            mockKeyValuePairs[mockID].Add(mockKey3, "mock-value3");
            cc.SetValue(mockID, mockKey3, mockPayload);

            Assert.AreEqual(expectvaluePairs.Keys, mockKeyValuePairs[mockID].Keys);
            Assert.AreEqual(expectvaluePairs.Values, mockKeyValuePairs[mockID].Values);
        }

Can someone please help me? I am new to this JustMock Unit testing and C#.

Source: Visual Studio Questions

LEAVE A COMMENT