Set ShimFileCreationInformation object properties

I am writing several unit test cases using a fake framework. I am using an object ShimFileCreationInformationfrom Microsoft.SharePoint.Client.Fakesthe namespace. Now I am passing this object to a function. Inside the function, I'm trying to assign a value to the Url property.

fileCreationInformation.Url = value;

But even though the value is present, nothing is assigned to the correct Url address, and it remains zero. Is there any workaround? To aggravate the situation, the object is ShimFileCreationInformationmissing documentation.

Code example:

ShimFileCreationInformation fileCreationInformation = new ShimFileCreationInformation();
SomeFunction(fileCreationInformation);

SomeFunction:

public void SomeFunction(FileCreationInformation fileCreationInformation)
{
     fileCreationInformation.Url = value; // This statement had so effect on fileCreationInformation.Url
}
+4
source share
1 answer

fileCreationInformation.Url = value;

, , , Shim, . ShimFileCreationInformation.AllInstances.UrlGet , , Url Get, .

:

[TestMethod]
public void derived_test()
{
    using (ShimsContext.Create())
    {
        ShimFileCreationInformation fileCreationInformation = new ShimFileCreationInformation();

        ShimFileCreationInformation.AllInstances.UrlGet = (instance) => value;

        SomeFunction(fileCreationInformation);
    }
}

public void SomeFunction(FileCreationInformation fileCreationInformation)
{
    var url = fileCreationInformation.Url; 

    // Check url variable above. It should be set to value

    fileCreationInformation.Url = value; // This statement will not work since you are trying to set the value of the Shim and you need to use `ShimFileCreationInformation.AllInstances.UrlGet` to set property value for Shims
}
0

All Articles