• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Protocol Buffers - Google's data interchange format
3 // Copyright 2015 Google Inc.  All rights reserved.
4 //
5 // Use of this source code is governed by a BSD-style
6 // license that can be found in the LICENSE file or at
7 // https://developers.google.com/open-source/licenses/bsd
8 #endregion
9 
10 using System;
11 using NUnit.Framework;
12 
13 namespace Google.Protobuf
14 {
15     /// <summary>
16     /// Helper methods when testing equality. NUnit's Assert.AreEqual and
17     /// Assert.AreNotEqual methods try to be clever with collections, which can
18     /// be annoying...
19     /// </summary>
20     internal static class EqualityTester
21     {
22         public static void AssertEquality<T>(T first, T second) where T : IEquatable<T>
23         {
24             Assert.IsTrue(first.Equals(second));
25             Assert.IsTrue(first.Equals((object) second));
26             Assert.AreEqual(first.GetHashCode(), second.GetHashCode());
27         }
28 
29         public static void AssertInequality<T>(T first, T second) where T : IEquatable<T>
30         {
31             Assert.IsFalse(first.Equals(second));
32             Assert.IsFalse(first.Equals((object) second));
33             // While this isn't a requirement, the chances of this test failing due to
34             // coincidence rather than a bug are very small.
35             if (first != null && second != null)
36             {
37                 Assert.AreNotEqual(first.GetHashCode(), second.GetHashCode());
38             }
39         }
40     }
41 }
42