Jens Geyer | aa0c8b3 | 2019-01-28 23:27:45 +0100 | [diff] [blame^] | 1 | // Licensed to the Apache Software Foundation(ASF) under one |
| 2 | // or more contributor license agreements.See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership.The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | using System; |
| 19 | using System.Collections.Generic; |
| 20 | using System.Text; |
| 21 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 22 | using Thrift.Collections; |
| 23 | |
| 24 | namespace Thrift.Tests.Collections |
| 25 | { |
| 26 | // ReSharper disable once InconsistentNaming |
| 27 | [TestClass] |
| 28 | public class TCollectionsTests |
| 29 | { |
| 30 | //TODO: Add tests for IEnumerable with objects and primitive values inside |
| 31 | |
| 32 | [TestMethod] |
| 33 | public void TCollection_Equals_Primitive_Test() |
| 34 | { |
| 35 | var collection1 = new List<int> {1,2,3}; |
| 36 | var collection2 = new List<int> {1,2,3}; |
| 37 | |
| 38 | var result = TCollections.Equals(collection1, collection2); |
| 39 | |
| 40 | Assert.IsTrue(result); |
| 41 | } |
| 42 | |
| 43 | [TestMethod] |
| 44 | public void TCollection_Equals_Primitive_Different_Test() |
| 45 | { |
| 46 | var collection1 = new List<int> { 1, 2, 3 }; |
| 47 | var collection2 = new List<int> { 1, 2 }; |
| 48 | |
| 49 | var result = TCollections.Equals(collection1, collection2); |
| 50 | |
| 51 | Assert.IsFalse(result); |
| 52 | } |
| 53 | |
| 54 | [TestMethod] |
| 55 | public void TCollection_Equals_Objects_Test() |
| 56 | { |
| 57 | var collection1 = new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } }; |
| 58 | var collection2 = new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } }; |
| 59 | |
| 60 | var result = TCollections.Equals(collection1, collection2); |
| 61 | |
| 62 | // references to different collections |
| 63 | Assert.IsFalse(result); |
| 64 | } |
| 65 | |
| 66 | [TestMethod] |
| 67 | public void TCollection_Equals_OneAndTheSameObject_Test() |
| 68 | { |
| 69 | var collection1 = new List<ExampleClass> { new ExampleClass { X = 1 }, new ExampleClass { X = 2 } }; |
| 70 | var collection2 = collection1; |
| 71 | |
| 72 | var result = TCollections.Equals(collection1, collection2); |
| 73 | |
| 74 | // references to one and the same collection |
| 75 | Assert.IsTrue(result); |
| 76 | } |
| 77 | |
| 78 | private class ExampleClass |
| 79 | { |
| 80 | public int X { get; set; } |
| 81 | } |
| 82 | } |
| 83 | } |