sdk/dotnet/test/Datasync.Common.Test/AssertEx.cs
/// <summary>
/// Asserts if the headers contains the specific header provided
/// </summary>
/// <param name="headers"></param>
/// <param name="headerName"></param>
/// <param name="expected"></param>
Asserts if the headers contains the specific header provided
Asserts if the headers contains the specific header provided
public static void HasHeader(HttpHeaders headers, string headerName, string expected)
        {
            string allHeaders = Enumerable.Empty<(String name, String value)>().Concat(
                headers.SelectMany(kvp => kvp.Value.Select(v => (name: kvp.Key, value: v)))
            ).Aggregate(seed: new StringBuilder(), func: (sb, pair) => sb.Append(pair.name).Append(": ").AppendLine(pair.value), resultSelector: sb => sb.ToString());
            Assert.True(headers.TryGetValues(headerName, out IEnumerable<string> values), $"The request/response does not contain header {headerName} (Headers = {allHeaders})");
            Assert.True(values.Count() == 1, $"There are {values.Count()} values for header {headerName} (values = {string.Join(';', values)})");
            Assert.True(values.First().Equals(expected), $"Value of header {headerName} does not match (expected: {expected}, got: {values.First()})");
        }
public static void HasHeader ( HttpHeaders headers , string headerName , string expected ) { string allHeaders = Enumerable . Empty < ( String name , String value ) > ( ) . Concat ( headers . SelectMany ( kvp => kvp . Value . Select ( v => ( name : kvp . Key , value : v ) ) ) ) . Aggregate ( seed : new StringBuilder ( ) , func : ( sb , pair ) => sb . Append ( pair . name ) . Append ( " " ) . AppendLine ( pair . value ) , resultSelector : sb => sb . ToString ( ) ) ; Assert . True ( headers . TryGetValues ( headerName , out IEnumerable < string > values ) , $" The request/response does not contain header  { headerName }  (Headers =  { allHeaders } ) " ) ; Assert . True ( values . Count ( ) == 1 , $" There are  { values . Count ( ) }  values for header  { headerName }  (values =  { string . Join ( ' ' , values ) } ) " ) ; Assert . True ( values . First ( ) . Equals ( expected ) , $" Value of header  { headerName }  does not match (expected:  { expected } , got:  { values . First ( ) } ) " ) ; }
Asserts if the headers contains the specific header provided
Asserts if the headers contains the specific header provided
headers
HttpHeaders
None
headerName
string
None
expected
string
None