public async Task TestCircularReferences() { _expectedData = new TestCollection(); for (var i = 0; i < 10; i++) { var item = new TestItem(i, _expectedData, RandomEnum()); _expectedData.Add(item); } _expectedHash = _expectedData.GetHashCode(); if (_client != null) { await _client.WriteAsync(_expectedData); } _barrier.WaitOne(TimeSpan.FromSeconds(5)); if (_exceptions.Any()) { throw new AggregateException(_exceptions); } Assert.IsNotNull(_actualHash, $"Server should have received client's {_expectedData.Count} item message"); Assert.AreEqual(_expectedHash, _actualHash, $"Hash codes for {_expectedData.Count} item message should match"); if (_actualData == null) { throw new InvalidOperationException($"{nameof(_actualData)} is null"); } Assert.AreEqual(_expectedData.Count, _actualData.Count, "Collection lengths should be equal"); for (var i = 0; i < _actualData.Count; i++) { var expectedItem = _expectedData[i]; var actualItem = _actualData[i]; Assert.AreEqual(expectedItem, actualItem, $"Items at index {i} should be equal"); Assert.AreEqual(actualItem.Parent, _actualData, $"Item at index {i}'s Parent property should reference the item's parent collection"); } }
protected bool Equals(TestItem other) { return(Id == other.Id && Enum == other.Enum); }