如何编写Azure功能的单元测试用例?

时间:2019-12-30 10:55:01

标签: c# unit-testing mocking azure-functions

我必须为Azure Function编写单元测试用例。我想模拟输入值。

这是我的天蓝色功能:

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage httpRequestMessage, TraceWriter traceWriter)
{

    var con = httpRequestMessage.Content;//it has image file 
    string httpreqContent = con.ReadAsStringAsync().Result;           
    var headers = httpRequestMessage.Headers;          
    var Returnvalue="";

    var ImageHeight = headers.GetValues("height");                                            
    var ms = new MemoryStream(Convert.FromBase64String(httpreqContent));                     
    var Obj = new { image = Convertmethod(ms, ImageHeight,traceWriter) };
    Returnvalue = JsonConvert.SerializeObject(Obj);                               
    return new HttpResponseMessage(HttpStatusCode.OK)
    {
        Content = new StringContent(Returnvalue, Encoding.UTF8, Constants.JSON)

    };
}

0 个答案:

没有答案