/// <summary> /// Creates a mock <see cref="IStatistics"/> object. /// </summary> /// <returns></returns> public static Mock <IStatistics> CreateLockableStatistics() { var mock = TestUtilities.CreateMockImplementation <IStatistics>(); var lockObject = new object(); var adsbTypeCount = new long[256]; var modeSDFStatistics = new ModeSDFStatistics[32]; var adsbMessageFormatCount = new long[Enum.GetValues(typeof(MessageFormat)).OfType <MessageFormat>().Select(r => (int)r).Max() + 1]; for (var i = 0; i < modeSDFStatistics.Length; ++i) { modeSDFStatistics[i] = new ModeSDFStatistics() { DF = (DownlinkFormat)i }; } mock.Setup(r => r.Lock(It.IsAny <Action <IStatistics> >())).Callback((Action <IStatistics> del) => { del(mock.Object); }); mock.Setup(r => r.AdsbTypeCount).Returns(adsbTypeCount); mock.Setup(r => r.ModeSDFStatistics).Returns(modeSDFStatistics); mock.Setup(r => r.AdsbMessageFormatCount).Returns(adsbMessageFormatCount); return(mock); }
public ModeSDFStatisticsModel(ModeSDFStatistics value) { DF = (int)value.DF; DFName = Enum.GetName(typeof(DownlinkFormat), value.DF); MessagesReceived = value.MessagesReceived; BadParityPI = value.BadParityPI; }
public StatisticsView() { _FeedManager = Factory.ResolveSingleton <IFeedManager>(); AdsbMessageTypeCount = new long[256]; ModeSDFStatistics = new ModeSDFStatistics[32]; AdsbMessageFormatCount = new long[Enum.GetValues(typeof(MessageFormat)).OfType <MessageFormat>().Select(r => (int)r).Max() + 1]; }
/// <summary> /// Creates a new object. /// </summary> public StatisticsView() : base() { InitializeComponent(); AdsbMessageTypeCount = new long[256]; ModeSDFStatistics = new ModeSDFStatistics[32]; AdsbMessageFormatCount = new long[Enum.GetValues(typeof(MessageFormat)).OfType <MessageFormat>().Select(r => (int)r).Max() + 1]; }
/// <summary> /// Resets the <see cref="ModeSDFStatistics"/> array. /// </summary> private void ResetModeSDFStatistics() { for (var i = 0; i < ModeSDFStatistics.Length; ++i) { ModeSDFStatistics[i] = new ModeSDFStatistics() { DF = (DownlinkFormat)i }; } }
/// <summary> /// See interface docs. /// </summary> public void Initialise() { if (!_Initialised) { AdsbTypeCount = new long[256]; AdsbMessageFormatCount = new long[Enum.GetValues(typeof(MessageFormat)).OfType <MessageFormat>().Select(r => (int)r).Max() + 1]; ModeSDFStatistics = new ModeSDFStatistics[32]; ResetModeSDFStatistics(); _Initialised = true; } }
public void StatisticsPresenter_HeartbeatTick_Updates_View_Correctly() { var worksheet = new ExcelWorksheetData(TestContext); var viewProperty = worksheet.String("ViewProperty"); var valueType = worksheet.String("ValueType"); var statistic1 = worksheet.String("Statistic1"); var statistic2 = worksheet.String("Statistic2"); _Presenter.Initialise(_View.Object); switch (valueType) { case "Counter": SetStatistic(statistic1, 6000000000L); _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); Assert.AreEqual(6000000000L, GetViewLong(viewProperty), viewProperty); _View.Verify(r => r.UpdateCounters(), Times.Exactly(2)); break; case "Duration": var startTimeDuration = new DateTime(2013, 1, 1, 11, 17, 42); _Clock.UtcNowValue = new DateTime(2013, 1, 2, 12, 0, 0); var expectedDuration = _Clock.UtcNowValue - startTimeDuration; SetStatistic(statistic1, startTimeDuration); _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); Assert.AreEqual(expectedDuration, GetViewTimeSpan(viewProperty), viewProperty); _View.Verify(r => r.UpdateCounters(), Times.Exactly(2)); // Confirm that a null connection time is handled correctly SetStatistic(statistic1, null); _Clock.UtcNowValue = _Clock.UtcNowValue.AddSeconds(1); _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); Assert.AreEqual(TimeSpan.Zero, GetViewTimeSpan(viewProperty), viewProperty); break; case "ListCounters": var statCounters = (long[])typeof(IStatistics).GetProperty(statistic1).GetValue(_Statistics.Object, null); var viewCounters = GetViewListCounters(viewProperty); var length = statCounters.Count(); for (var i = 0; i < length; ++i) { statCounters[i] = (i + 1) * 4; } _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); for (var i = 0; i < length; ++i) { Assert.AreEqual((i + 1) * 4, viewCounters[i], "{0}[{1}]", viewProperty, i); } _View.Verify(r => r.UpdateCounters(), Times.Exactly(2)); break; case "ListObjects": var statList = (IList)typeof(IStatistics).GetProperty(statistic1).GetValue(_Statistics.Object, null); var viewList = GetViewListObjects(viewProperty); var listLength = statList.Count; Assert.IsTrue(listLength > 0); var elementType = statList.GetType().GetElementType(); for (var i = 0; i < listLength; ++i) { if (elementType == typeof(ModeSDFStatistics)) { statList[i] = new ModeSDFStatistics() { DF = (DownlinkFormat)i, BadParityPI = i + 1, MessagesReceived = i - 1, }; } else { throw new NotImplementedException(); } } _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); for (var i = 0; i < listLength; ++i) { Assert.AreNotEqual(statList[i], viewList[i], "The view object must be a clone of the statistic object, not the actual statistic object"); if (elementType == typeof(ModeSDFStatistics)) { var viewElement = (ModeSDFStatistics)viewList[i]; Assert.AreEqual((DownlinkFormat)i, viewElement.DF); Assert.AreEqual(i + 1, viewElement.BadParityPI); Assert.AreEqual(i - 1, viewElement.MessagesReceived); } else { throw new NotImplementedException(); } } break; case "Ratio": SetStatistic(statistic1, 400L); SetStatistic(statistic2, 100L); _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); Assert.AreEqual(0.25, GetViewDouble(viewProperty), viewProperty); _View.Verify(r => r.UpdateCounters(), Times.Exactly(2)); // Assert that a denominator of zero doesn't cause the ratio calculation to throw a divide by zero exception or produce a result of Infinity SetStatistic(statistic1, 0L); _Clock.UtcNowValue = _Clock.UtcNowValue.AddSeconds(1); _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); Assert.AreEqual(0.0, GetViewDouble(viewProperty), viewProperty); break; case "Throughput": SetStatistic(statistic1, 2239488L); var startTimeThroughput = new DateTime(2013, 1, 2, 12, 0, 0); _Clock.UtcNowValue = new DateTime(2013, 1, 2, 12, 1, 0); SetStatistic(statistic2, startTimeThroughput); _HeartbeatService.Raise(r => r.FastTick += null, EventArgs.Empty); Assert.AreEqual(36.45, GetViewDouble(viewProperty), viewProperty); _View.Verify(r => r.UpdateCounters(), Times.Exactly(2)); break; default: Assert.Fail("Unknown value type {0}", valueType); break; } }