Ejemplo n.º 1
0
        public void ShouldBeAbleToMapObservationToMessage()
        {
            SignalR.Common.Dto.Observation source = new SignalR.Common.Dto.Observation
            {
                Entity = new SignalR.Common.Dto.Identity {
                    Value = "TESTENTITY"
                },
                Observable = new SignalR.Common.Dto.Identity {
                    Value = "TESTOBSERVABLE"
                },
                Date        = DateTimeOffset.Now,
                Measurement = new SignalR.Common.Dto.Measurement
                {
                    Type  = SignalR.Common.Dto.MeasurementType.Units,
                    Value = "3.14"
                }
            };
            With.Message.IObservation actual = source.AsMessage();

            Assert.AreEqual(actual.Entity.Value, source.Entity.Value);
            Assert.AreEqual(actual.Observable.Value, source.Observable.Value);
            Assert.AreEqual(actual.Date, source.Date);
            Assert.AreEqual(actual.Measurement.Value, source.Measurement.Value);
            Assert.AreEqual(actual.Measurement.Type.ToString(), source.Measurement.Type.ToString());
        }
Ejemplo n.º 2
0
        public void ThenTheFollowingObservationShouldHaveBeenReceivedByTheClientForTheIdentityIdentifiedAs(string observerId, int timeout, Table table)
        {
            SignalR.Common.Dto.Observation expected = table.Rows.Select(
                row => new SignalR.Common.Dto.Observation
            {
                Entity = new SignalR.Common.Dto.Identity {
                    Value = row.Read <string>("Entity")
                },
                Observable = new SignalR.Common.Dto.Identity {
                    Value = row.Read <string>("Observable")
                },
                Date        = row.ReadDate("Date"),
                Measurement = new SignalR.Common.Dto.Measurement
                {
                    Type  = row.ReadEnum <SignalR.Common.Dto.MeasurementType>("MeasurementType"),
                    Value = row.Read <string>("Measurement")
                }
            }
                ).SingleOrDefault();

            Assert.IsTrue(
                _messages.Where(tuple => string.Equals(tuple.Item1, observerId, StringComparison.CurrentCultureIgnoreCase))
                .Select(tuple => tuple.Item2)
                .OfType <With.Message.IObservation>()
                .Any(actual => string.Equals(actual.Entity.Value, expected.Entity.Value, StringComparison.CurrentCultureIgnoreCase) &&
                     string.Equals(actual.Observable.Value, expected.Observable.Value, StringComparison.CurrentCultureIgnoreCase) &&
                     actual.Date == expected.Date && actual.Measurement.Value == expected.Measurement.Value)
                .Timeout(TimeSpan.FromSeconds(timeout))
                .FirstAsync().Wait()
                );
        }
Ejemplo n.º 3
0
        public void ShouldBeAbleToMapObservationToDto()
        {
            With.Message.Observation source = new Message.Observation(
                new With.Component.Identity("TESTENTITY"),
                new With.Component.Identity("TESTOBSERVABLE"),
                DateTimeOffset.Now,
                new With.Component.Measurement(
                    With.Component.MeasurementType.Units,
                    "3.14"
                    )
                );

            SignalR.Common.Dto.Observation actual = source.AsDto();

            Assert.AreEqual(actual.Entity.Value, source.Entity.Value);
            Assert.AreEqual(actual.Observable.Value, source.Observable.Value);
            Assert.AreEqual(actual.Date, source.Date);
            Assert.AreEqual(actual.Measurement.Value, source.Measurement.Value);
            Assert.AreEqual(actual.Measurement.Type.ToString(), source.Measurement.Type.ToString());
        }
Ejemplo n.º 4
0
        public void ShouldBeAbleToMapObservationToMessage()
        {
            SignalR.Common.Dto.Observation source = new SignalR.Common.Dto.Observation
            {
                Entity = new SignalR.Common.Dto.Identity { Value = "TESTENTITY" },
                Observable = new SignalR.Common.Dto.Identity { Value = "TESTOBSERVABLE" },
                Date = DateTimeOffset.Now,
                Measurement = new SignalR.Common.Dto.Measurement
                {
                    Type = SignalR.Common.Dto.MeasurementType.Units,
                    Value = "3.14"
                }
            };
            With.Message.IObservation actual = source.AsMessage();

            Assert.AreEqual(actual.Entity.Value, source.Entity.Value);
            Assert.AreEqual(actual.Observable.Value, source.Observable.Value);
            Assert.AreEqual(actual.Date, source.Date);
            Assert.AreEqual(actual.Measurement.Value, source.Measurement.Value);
            Assert.AreEqual(actual.Measurement.Type.ToString(), source.Measurement.Type.ToString());
        }
Ejemplo n.º 5
0
        public void WhenTheObservableIdentifiedAsOfTheEntityIdentifiedAsEmitsTheFollowingObservation(Table table)
        {
            SignalR.Common.Dto.Observation observation = table.Rows.Select(
                row => new SignalR.Common.Dto.Observation
            {
                Entity = new SignalR.Common.Dto.Identity {
                    Value = row.Read <string>("Entity")
                },
                Observable = new SignalR.Common.Dto.Identity {
                    Value = row.Read <string>("Observable")
                },
                Date        = row.ReadDate("Date"),
                Measurement = new SignalR.Common.Dto.Measurement
                {
                    Type  = row.ReadEnum <SignalR.Common.Dto.MeasurementType>("MeasurementType"),
                    Value = row.Read <string>("Measurement")
                }
            }
                ).SingleOrDefault();

            _serviceContext.PublishObservation(observation);
        }
Ejemplo n.º 6
0
        public void ShouldBeAbleToDynamicallyMapObservationToMessage()
        {
            SignalR.Common.Dto.Message source = new SignalR.Common.Dto.Observation
            {
                Entity = new SignalR.Common.Dto.Identity {
                    Value = "TESTENTITY"
                },
                Observable = new SignalR.Common.Dto.Identity {
                    Value = "TESTOBSERVABLE"
                },
                Date        = DateTimeOffset.Now,
                Measurement = new SignalR.Common.Dto.Measurement
                {
                    Type  = SignalR.Common.Dto.MeasurementType.Units,
                    Value = "3.14"
                }
            };

            With.Message.IMessage actual = source.AsDynamicMessage();

            Assert.IsInstanceOfType(actual, typeof(With.Message.IObservation));
        }
Ejemplo n.º 7
0
 public void PublishObservation(SignalR.Common.Dto.Observation observation)
 {
     _observers.Where(observer => string.Equals(observer.ObserveeId, observation.Entity.Value, StringComparison.CurrentCultureIgnoreCase) && string.Equals(observer.ObservableId, observation.Observable.Value, StringComparison.CurrentCultureIgnoreCase))
     .ForEach(observer => observer.Process(observation.AsDynamicMessage()));
 }
Ejemplo n.º 8
0
        public void ShouldBeAbleToDynamicallyMapObservationToMessage()
        {
            SignalR.Common.Dto.Message source = new SignalR.Common.Dto.Observation
            {
                Entity = new SignalR.Common.Dto.Identity { Value = "TESTENTITY" },
                Observable = new SignalR.Common.Dto.Identity { Value = "TESTOBSERVABLE" },
                Date = DateTimeOffset.Now,
                Measurement = new SignalR.Common.Dto.Measurement
                {
                    Type = SignalR.Common.Dto.MeasurementType.Units,
                    Value = "3.14"
                }
            };
            
            With.Message.IMessage actual = source.AsDynamicMessage();

            Assert.IsInstanceOfType(actual, typeof(With.Message.IObservation));
        }