microsoft / sarif-sdk

.NET code and supporting files for working with the 'Static Analysis Results Interchange Format' (SARIF, see https://github.com/oasis-tcs/sarif-spec)
Other
191 stars 88 forks source link

Http mock test helper improvement #2715

Closed shaopeng-gh closed 10 months ago

shaopeng-gh commented 10 months ago

The problem is the timestamp difference between mocking and retrieving the test result, causing that we may not be able to retrieve the correct result form the cache list, because it compares all headers and the headers contains the timestamp, and also the other fields that generated based on the timestamp.

In most cases, we set up one request and response pair. The header matching mechanism is only needed for those situations where we need more than one pair. With this change, 1 to 1 mocking (which is the vast majority) will no longer need to worry about the timestamp. The rest of the code path is kept for those cases need it.

michaelcfanning commented 10 months ago
    public static readonly HttpResponseMessage OKResponse =

Please get rid of this property, we should only have CreateOkResponse. Once this single response is read, it is no longer valid, so publishing instance fields doesn't make sense.


In reply to: 1722541774


Refers to: src/Test.Utilities.Sarif/HttpMockHelper.cs:28 in a5d8664. [](commit_id = a5d8664e0d60c5659b43a60092bff19f6f9d5f1a, deletion_comment = False)

michaelcfanning commented 10 months ago
    public static readonly HttpResponseMessage NotFoundResponse =

Please convert this field and all others to a CreateXXX method, so this one should be CreateNotFoundResponse(). Then delete this public static field. Convert all tests to use the creation methods.


In reply to: 1722541936


Refers to: src/Test.Utilities.Sarif/HttpMockHelper.cs:31 in a5d8664. [](commit_id = a5d8664e0d60c5659b43a60092bff19f6f9d5f1a, deletion_comment = False)