Пример #1
0
        public void Log_EqualityComparer_GetHashCode_NullableValues()
        {
            var random = new Random();

            var response = new MessageResponse(Enumerable.Range(0, 50).Select(i =>
            {
                var dateTimeRaw    = 43042.2573037732 + random.NextDouble() * 3000;
                var dateTimeRawStr = dateTimeRaw.ToString(CultureInfo.InvariantCulture);

                return(new MessageItem(null, null, dateTimeRawStr, null, null, "604", null, null, null, null, "1", null, null, "2304", null, null, null, null));
            }).ToArray());

            var logs = BaseTest.Initialize_Client(response).GetLogs(count: null);

            Assert.AreEqual(50, logs.Count);

            var set = new HashSet <Log>(new LogEqualityComparer());

            foreach (var log in logs)
            {
                set.Add(log);
            }

            Assert.AreEqual(50, set.Count);

            var comparer = new LogEqualityComparer();

            foreach (var log in logs)
            {
                Assert.AreEqual(comparer.GetHashCode(log), comparer.GetHashCode(log));
            }
        }
Пример #2
0
        public void Log_EqualityComparer_GetHashCode_UniqueValues()
        {
            var random = new Random();

            var response = new MessageResponse(Enumerable.Range(0, 50).Select(i =>
            {
                var r = random.NextDouble();

                return(new MessageItem(
                           $"WMI Remote Ping_{r}",
                           datetimeRaw: (43042.2573037732 + r).ToString(),
                           parent: $"Probe Device_{r}",
                           sensor: $"WMI Remote Ping_{r}",
                           device: $"Probe Device_{r}",
                           group: $"Local Probe_{r}"
                           ));
            }).ToArray());

            var logs = BaseTest.Initialize_Client(response).GetLogs(count: null);

            Assert.AreEqual(50, logs.Count);

            var set = new HashSet <Log>(new LogEqualityComparer());

            foreach (var log in logs)
            {
                set.Add(log);
            }

            Assert.AreEqual(50, set.Count);

            var comparer = new LogEqualityComparer();

            foreach (var log in logs)
            {
                Assert.AreEqual(comparer.GetHashCode(log), comparer.GetHashCode(log));
            }
        }