1 // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
2 
3 using System.Collections.Generic;
4 
5 namespace System.Web.Http.Tracing
6 {
7     /// <summary>
8     /// Comparer class to allow xUnit asserts for <see cref="TraceRecord"/>.
9     /// </summary>
10     class TraceRecordComparer : IEqualityComparer<TraceRecord>
11     {
Equals(TraceRecord x, TraceRecord y)12         public bool Equals(TraceRecord x, TraceRecord y)
13         {
14             if (!String.Equals(x.Category, y.Category) ||
15                    x.Level != y.Level ||
16                    x.Kind != y.Kind ||
17                    !Object.ReferenceEquals(x.Request, y.Request))
18                 return false;
19 
20             // The following must match only if they are present on 'x' -- the expected value
21             if (x.Exception != null && !Object.ReferenceEquals(x.Exception, y.Exception))
22                 return false;
23 
24             if (!String.IsNullOrEmpty(x.Message) && !String.Equals(x.Message, y.Message))
25                 return false;
26 
27             if (!String.IsNullOrEmpty(x.Operation) && !String.Equals(x.Operation, y.Operation))
28                 return false;
29 
30             if (!String.IsNullOrEmpty(x.Operator) && !String.Equals(x.Operator, y.Operator))
31                 return false;
32 
33             return true;
34         }
35 
GetHashCode(TraceRecord obj)36         public int GetHashCode(TraceRecord obj)
37         {
38             return obj.GetHashCode();
39         }
40     }
41 }
42