Hi,
Recently we wrote a plugin assembly that was calling a rest service using WebChannelFactory.
// wcf interface
[ServiceContract]
public interface IAutoNumber
{
/// <summary>
/// Gets the next number.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>the next incremental value</returns>
[WebGet(UriTemplate = "getsequencenumber/{value}")]
[OperationContract]
string GetNextNumber(string value);
}
// plugin code
using (
var webChannelFactory =
new WebChannelFactory<IAutoNumber>(
new Uri(dictionaryConfigSettings[Constants.AutoNumberServiceUrl])))
{
IAutoNumber client = webChannelFactory.CreateChannel();
// get the next number from sequence
autoNumber = Constants.PrefixClient +
AddPadding(client.GetNextNumber(Constants.EntityNameClient),
Constants.PrefixClientLength);
if (entity.Attributes.Contains("name"))
{
// add the value to the name property bag input parameter for the client record being created
entity.Attributes["name"] = autoNumber;
}
else
{
entity.Attributes.Add("name", autoNumber);
}
}
Next we had to write the unit test case for the plugin using Microsoft Fakes.
Below is the code that we used
</span></pre>
using (ShimsContext.Create())
{
ShimChannelFactory<IAutoNumber>.Constructor = factory => { };
IAutoNumber autoNumber = new StubIAutoNumber
{
GetNextNumberString = s => { return "12345"; }
};
ShimChannelFactory<IAutoNumber>.AllInstances.CreateChannel = factory => { return autoNumber; };
var preClientCreate = new PreClientCreate();
preClientCreate.Execute(serviceProvider);
}
Hope it helps.
0.000000
0.000000