moq - Writing unit test cases for Sitecore project -


my client wants have 100% code coverage projects. have written few test cases long web api's using nunit. client decided use xunit unit test framework using moq mock framework.

as have never worked on unit test case sitecore project, please en-light on approach? start coudl please write sample test case below method? using glassmapperframework orm.

public class registrationcontroller : glasscontroller     {     public actionresult registrationinitiation()             {                 var someobject = getdatasourceitem<iregistrationmaincontent>();                  return view(someobject);             } } 

to test controllers, want inject sitecore context controller. glasscontroller has overload method on glasscontroller(isitecorecontext). used unit test controllers. has other overloads if needed...

here more complete code need unit test controller

private mock<iregistrationmodel> registrationmodel { get; set; }; private registrationcontroller controller { get; set; }  [testinitialize] public void setup() {     var mocksitecorecontext = new mock<isitecorecontext>();     this.registrationmodel = new mock<iregistrationmodel>();      this.registrationmodel.setupallproperties();      mocksitecorecontext.setup(sc =>sc.getitem<iregistrationmodel         (it.isany<string>(), false, false)).         returns(this.registrationmodel.object);      this.controller = new registrationcontroller {sitecorecontext =         mocksitecorecontext.object } }  [testmethod] public void your_unit_test_name() {     //....perform unit test here     this.controller.sitecorecontext = null;      var result = this.controller.getindex() viewresult;      //assert .... } 

let me know if have questions!


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -