public void RegisteringObservation_StateIsMerged()
        {
            _context.Database.EnsureDeleted();
            var service = new TimeLineService(_context);

            var o1 = new Observation()
            {
                On          = "2001/01/01 01:01",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyVal=Hello World" }
            };

            var o2 = new Observation()
            {
                On          = "2001/01/01 01:02",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyNextVal=Hello World Again" }
            };

            service.RegisterObservation(o1);
            service.RegisterObservation(o2);

            Assert.Equal("Hello World", service.GetEntityState("E1", "2001/01/01 01:02")["MyVal"]);
            Assert.Equal("Hello World Again", service.GetEntityState("E1", "2001/01/01 01:02")["MyNextVal"]);
        }
        public void RegisteringObservation_StateIsOverwritten()
        {
            _context.Database.EnsureDeleted();
            var service = new TimeLineService(_context);

            var o1 = new Observation()
            {
                On          = "2001/01/01 01:01",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyVal=Hello World" }
            };

            var o2 = new Observation()
            {
                On          = "2001/01/01 01:02",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyNextVal=Hello World Again" }
            };


            service.RegisterObservation(o1);
            service.RegisterObservation(o2);

            var contexts = service.SearchEvents(new string[] { }).OrderByDescending(x => x.On);

            Assert.Equal("Hello World Again", service.GetEntityState("E1", "2001/01/01 01:02")["MyNextVal"]);
        }
Example #3
0
        public void Entity_State_Tracked()
        {
            var e1 = new NewEvent()
            {
                On       = "2001/01/01 01:01",
                Type     = "MyEventType",
                Entities = new [] { "E1" }
            };

            var o1 = new Observation()
            {
                On          = "2001/01/01 01:01",
                Entity      = "E1",
                Expressions = new[] { "State.MyVal=Hello World" }
            };

            var e2 = new NewEvent()
            {
                On       = "2001/01/01 01:02",
                Type     = "MyEventType",
                Entities = new[] { "E1" }
            };

            var o2 = new Observation()
            {
                On          = "2001/01/01 01:02",
                Entity      = "E1",
                Expressions = new[] { "State.MyVal=Hello World Again" }
            };



            _service.RegisterObservation(o1);
            _service.RegisterEvent(e1);
            _service.RegisterObservation(o2);
            _service.RegisterEvent(e2);

            var state1 = _service.GetEntityState("E1", "2001 /01/01 01:01");
            var state2 = _service.GetEntityState("E1", "2001/01/01 01:02");
            var state3 = _service.GetEntityState("BADID", "2001/01/01 01:02");

            Assert.Equal("Hello World", state1["MyVal"]);
            Assert.Equal("Hello World Again", state2["MyVal"]);
            Assert.False(state3.ContainsKey("MyVal"));
        }
        public void RegisteringObservation_StateIsMerged_Reverse_Chronologically()
        {
            _context.Database.EnsureDeleted();
            var service = new TimeLineService(_context);

            var o1 = new Observation()
            {
                On          = "2001/01/01 01:03",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyNextVal=3" }
            };

            var o2 = new Observation()
            {
                On          = "2001/01/01 01:02",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyNextVal=2" }
            };

            var o3 = new Observation()
            {
                On          = "2001/01/01 01:01",
                Type        = "MyEventType",
                Entity      = "E1",
                Expressions = new[] { "State.MyNextVal=1" }
            };


            service.RegisterObservation(o1);
            service.RegisterObservation(o2);
            service.RegisterObservation(o3);

            Assert.Equal("1", service.GetEntityState("E1", "2001/01/01 01:01")["MyNextVal"]);
            Assert.Equal("2", service.GetEntityState("E1", "2001/01/01 01:02")["MyNextVal"]);
            Assert.Equal("3", service.GetEntityState("E1", "2001/01/01 01:03")["MyNextVal"]);
        }