dimanche 22 mars 2015

Define generic shim for HttpRequestMessageExtensions.CreateResponse extension

HttpRequestMessageExtensions.CreateResponse methode can be called like this:



Return Request.CreateResponse(HttpStatusCode.OK)


I can't figure out delegate definition for Relevant Microsoft.Fakes Shim of this extension. Shim definition is:



System.Net.Http.Fakes.ShimHttpRequestMessageExtensions.CreateResponseOf1HttpRequestMessageHttpStatusCodeM0(Of T)(Microsoft.QualityTools.Testing.Fakes.FakesDelegates.Func(Of System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, T, System.Net.Http.HttpResponseMessage))


In this case T is Generic Type of some object which should go after HttpStatusCode. But what if i ommit this parameter. There is no shim for not generic no parameter overload.


Now i do it like this:


Testing:



Return Request.CreateResponse(HttpStatusCode.OK, "")


Unit test:



<TestMethod()> Public Sub TestValidateCodeInput()
Dim c As New NetClub.UIControls.Controllers.DnnCellInputController
Using s = Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create
Dim z As New Microsoft.QualityTools.Testing.Fakes.FakesDelegates.Func(Of System.Net.Http.HttpRequestMessage, System.Net.HttpStatusCode, String, System.Net.Http.HttpResponseMessage)(AddressOf zf)

System.Net.Http.Fakes.ShimHttpRequestMessageExtensions.CreateResponseOf1HttpRequestMessageHttpStatusCodeM0(Of String)(z)

Assert.IsTrue(c.ValidateCode(000, "+70000000000").StatusCode = HttpStatusCode.OK)

End Using
End Sub

Function zf(i As System.Net.Http.HttpRequestMessage, i1 As System.Net.HttpStatusCode, i2 As String) As System.Net.Http.HttpResponseMessage
Return New System.Net.Http.HttpResponseMessage(HttpStatusCode.OK)
End Function


But i dot like that i have to add empty string to create respons function


Aucun commentaire:

Enregistrer un commentaire