Scenario:
You want to write a test case for the Feature Receiver
Sample Feature Code:
namespace TrainingSamplesSample Test Case Code:
{
public class SampleFeatureReceiver:SPFeatureReceiver
{
[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
if (properties == null)
{
return;
}
SPWeb web = (SPWeb)properties.Feature.Parent;
this.OnActivationCode(web);
}
public void OnActivationCode(SPWeb web)
{
//Code
}
}
}
namespace TrainingSamples
{
[TestMethod()]
public void FeatureRecieverOnActivationTest()
{
SampleFeatureReceiver target = new SampleFeatureReceiver();
SPSite site;
SPWeb web;
//Bind to the site where you are testing provisioning code.
site = new SPSite("http://servername");
using (site)
{
web = site.RootWeb;
using (web)
{
target.OnActivationCode(web);
}
}
Assert.IsTrue(true,
"Feature Activation did not throw any exceptions.");
}
}
}
0 comments:
Post a Comment