Esempio n. 1
0
        public void Process_WithTwoReadingsWithSameNameButDifferentGroups_CreatesTwoFeatureStatsWithSameNamesButDifferentGroups()
        {
            IList <FeatureStatistics> featureStats = null;

            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) =>
            {
                featureStats = dataPoints;
            }));
            string group1      = "Group1";
            string group2      = "Group2";
            string featureName = "featureName";

            ReadingPublisher.PublishReading(new Reading {
                FeatureName = featureName, FeatureGroup = group1, Data = new Int32ReadingData(1)
                {
                    Name = "Number"
                }
            });
            ReadingPublisher.PublishReading(new Reading {
                FeatureName = featureName, FeatureGroup = group2, Data = new Int32ReadingData(1)
                {
                    Name = "Error"
                }
            });

            ReadingPublisher.Start(100, false);
            ReadingPublisher.Process();

            Assert.That(featureStats.Count, Is.EqualTo(2));

            Assert.That(featureStats.First().Name, Is.EqualTo(featureStats.Last().Name));
            Assert.That(featureStats.First().Group, Is.EqualTo(group1));
            Assert.That(featureStats.Last().Group, Is.EqualTo(group2));
        }
Esempio n. 2
0
        public void Process_WithTwoReadingsWithSameNameButDifferentReadingDataNames_SendsOneDataPointToSubscribersWithTwoReadingDataValues()
        {
            IList <FeatureStatistics> passedDataPoints = null;

            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) =>
            {
                passedDataPoints = dataPoints;
            }));
            ReadingPublisher.PublishReading(new Reading {
                FeatureName = "DataPointName", Data = new Int32ReadingData(1)
                {
                    Name = "Number"
                }
            });
            ReadingPublisher.PublishReading(new Reading {
                FeatureName = "DataPointName", Data = new Int32ReadingData(1)
                {
                    Name = "Error"
                }
            });

            ReadingPublisher.Start(100, false);
            ReadingPublisher.Process();

            FeatureStatistics dataPoint = passedDataPoints.First();

            Assert.That(dataPoint.Readings.Count, Is.EqualTo(2));
            Assert.That(dataPoint.Readings.First().Name, Is.EqualTo("Number"));
            Assert.That(dataPoint.Readings.Last().Name, Is.EqualTo("Error"));
        }
        public void Process_With2ReadingsWithDifferentNames_PassesOnTwoSeparateDataPointsToSubscribers()
        {
            ReadingPublisher.PublishReading(GetNumberReading("test", 1));
            ReadingPublisher.PublishReading(GetNumberReading("test1", 1));

            ReadingPublisher.Process();

            Assert.That(_dataPoints.Count, Is.EqualTo(2));
        }
Esempio n. 4
0
        public void Process_ClearsReadingsFromReadingsQueue()
        {
            ReadingPublisher.PublishReading(GetReading());
            ReadingPublisher.PublishReading(GetReading());

            ReadingPublisher.Process();

            Assert.That(ReadingPublisher.Readings.Count, Is.EqualTo(0));
        }
        public void Process_WithMultipleReadings_CombinesTheReadingsIntoDataPoint()
        {
            string readingName = "test";

            ReadingPublisher.PublishReading(GetNumberReading(readingName, 1));
            ReadingPublisher.PublishReading(GetNumberReading(readingName, 1));

            ReadingPublisher.Process();

            Assert.That(_dataPoints.Count, Is.EqualTo(1));
            Assert.That(_dataPoints.First().Name, Is.EqualTo(readingName));
        }
        public void Process_WithMultipleReadings_PassesOnOneDataPointWithCombinedDataToSubscribers()
        {
            string readingName = "test";

            ReadingPublisher.PublishReading(GetNumberReading(readingName, 1));
            ReadingPublisher.PublishReading(GetNumberReading(readingName, 1));

            ReadingPublisher.Process();

            Assert.That(_dataPoints.Count, Is.EqualTo(1));
            Assert.That(_dataPoints.First().Readings.First().GetValue(), Is.EqualTo(2));
        }
Esempio n. 7
0
        public void Process_CallsAllSubsribers()
        {
            bool sub1called = false;
            bool sub2called = false;

            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) => sub1called = true));
            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) => sub2called = true));

            ReadingPublisher.Process();

            Assert.That(sub1called, Is.True);
            Assert.That(sub2called, Is.True);
        }
Esempio n. 8
0
        public void Process_WithNoReadings_PassesAnEmptyListOfDataPointsToAllSubscribers()
        {
            IList <FeatureStatistics> passedDataPoints = null;

            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) =>
            {
                passedDataPoints = dataPoints;
            }));

            ReadingPublisher.Process();

            Assert.That(passedDataPoints, Is.Empty);
        }
Esempio n. 9
0
        public void Process_WhenASubscriberFailsStillNotifiesTheRestOfTheSubscribers()
        {
            bool sub2called = false;

            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) =>
            {
                throw new Exception("Subscriber failed");
            }));
            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) => sub2called = true));

            ReadingPublisher.Process();

            Assert.That(sub2called, Is.True);
        }
Esempio n. 10
0
        public void Process_WithAReading_SendsOneDataPointWithCurrentDate()
        {
            IList <FeatureStatistics> passedDataPoints = null;

            ReadingPublisher.Subscribe(GetSubscriber((dataPoints) =>
            {
                passedDataPoints = dataPoints;
            }));
            ReadingPublisher.PublishReading(new Reading {
                FeatureName = "DataPointName", Data = new Int32ReadingData(1)
                {
                    Name = "Number"
                }
            });

            ReadingPublisher.Start(100, false);
            ReadingPublisher.Process();

            Assert.That(passedDataPoints.First().Timestamp - DateTime.Now, Is.LessThan(TimeSpan.FromSeconds(1)));
        }
Esempio n. 11
0
        public void Process_WithAReading_CreatedFeatureWithCorrectGroup()
        {
            IList <FeatureStatistics> featurestats = null;

            ReadingPublisher.Subscribe(GetSubscriber((stats) =>
            {
                featurestats = stats;
            }));

            string group = "Group";

            ReadingPublisher.PublishReading(new Reading {
                FeatureName = "DataPointName", FeatureGroup = group, Data = new Int32ReadingData(1)
                {
                    Name = "Number"
                }
            });

            ReadingPublisher.Start(100, false);
            ReadingPublisher.Process();

            Assert.That(featurestats.First().Group, Is.EqualTo(group));
        }