hi please let me know how write moq unit test case below method.any appreciated .thanks in advance.
public void constructaddmappingquery(iannotationmapping annotationmappings, out string commandtext, out dictionary<string, dynamic> parameters) { commandtext =@"insert annotationmapping values (@annotationsetupid, @wordtoannotate, @annotation, @createddttm, @createduserid, @modifieddate, @modifieduserid, @isactive)"; parameters = new dictionary<string, dynamic>(); parameters.add("@wordtoannotate", annotationmappings.wordtoannotate); parameters.add("@annotation", annotationmappings.annotation); parameters.add("@modifieddate", annotationmappings.modifieddate); parameters.add("@modifieduserid", annotationmappings.modifieduserid); parameters.add("@annotationsetupid", annotationmappings.annotationsetupid); parameters.add("@createddttm", annotationmappings.createddttm); parameters.add("@createduserid", annotationmappings.createduserid); parameters.add("@isactive", 1); }
looking whole method not stub.cheers!!!!!!!!!!!!
assuming class like
public class annotationmappingquerybuilder { public void constructaddmappingquery(iannotationmapping annotationmappings, out string commandtext, out dictionary<string, dynamic> parameters) { commandtext = @"insert annotationmapping values (@annotationsetupid, @wordtoannotate, @annotation, @createddttm, @createduserid, @modifieddate, @modifieduserid, @isactive)"; parameters = new dictionary<string, dynamic>(); parameters.add("@wordtoannotate", annotationmappings.wordtoannotate); parameters.add("@annotation", annotationmappings.annotation); parameters.add("@modifieddate", annotationmappings.modifieddate); parameters.add("@modifieduserid", annotationmappings.modifieduserid); parameters.add("@annotationsetupid", annotationmappings.annotationsetupid); parameters.add("@createddttm", annotationmappings.createddttm); parameters.add("@createduserid", annotationmappings.createduserid); parameters.add("@isactive", 1); } }
you need moq interface. test this.
[testclass] public class unittest1 { [testmethod] public void testmethod1() { //arrange var mock = mock.of<iannotationmapping>(); var expectedcommandtext = @"insert annotationmapping values (@annotationsetupid, @wordtoannotate, @annotation, @createddttm, @createduserid, @modifieddate, @modifieduserid, @isactive)"; string commandtext = null; dictionary<string, dynamic> parameters = null; int expectedparametercount = 8; var sut = new annotationmappingquerybuilder(); //act sut.constructaddmappingquery(mock, out commandtext, out parameters); //assert assert.isnotnull(commandtext); assert.areequal(expectedcommandtext, commandtext); assert.isnotnull(parameters); assert.areequal(expectedparametercount, parameters.count); ///what ever else want assert parameters } }
Comments
Post a Comment