示例#1
0
        public async void SendNewIoTButtonMessageExists()
        {
            DBMock.Init();
            var service = CreateEventProcessorService();
            await service.HandleEventTriggerInput(CreateDeviceTriggerIoTMessage("DeviceButton3", "button"));

            Assert.True(VerifyDebugLog("Retrieved message", _mockLogger));
            var events = await _mockEventRest.Object.GetEventClusters();

            var eventsButton = events.ToList().FindAll(p => p.EventType == "button");
            var eventsSound  = events.ToList().FindAll(p => p.EventType == "sound");
            var eventsTest   = events.ToList().FindAll(p => p.EventType == "test");

            Assert.Equal(2, eventsButton.Count);
            Assert.Single(eventsSound);
            Assert.Empty(eventsTest);

            var k = await _mockEventRest.Object.GetEventCluster(eventsButton[0].EventClusterId);

            await service.HandleEventTriggerInput(CreateDeviceTriggerIoTMessage("DeviceButton2", "button"));

            events = await _mockEventRest.Object.GetEventClusters();

            eventsButton = events.ToList().FindAll(p => p.EventType == "button");
            Assert.Equal(3, eventsButton.Count);
        }
        public async void SendNewIoTNoteMessageCreateNote()
        {
            DBMock.Init();
            var service = CreateMessageService();
            var result  = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "We all want love"));

            Assert.True(result);
            result = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "we care about you!"));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal("We care about you!", eventObj.LastNote);
            Assert.Equal(2, DBMock.GetNotes("Event1").ToList().Count);

            eventObj = await _mockEventRest.Object.GetEvent("Event2");

            Assert.Equal(string.Empty, eventObj.LastNote);
            result = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event2", "You want courage"));

            Assert.True(result);
            eventObj = await _mockEventRest.Object.GetEvent("Event2");

            Assert.Equal("You need courage", eventObj.LastNote);
            Assert.Equal(1, DBMock.GetNotes("Event2").ToList().Count);
        }
示例#3
0
        public async void SendNewIoTButtonMessageCapacityAddition()
        {
            DBMock.Init();
            var service = CreateButtonService();
            var result  = await service.HandleButtonTriggerInput(CreateSerializedButtonTriggerIoTMessage("Event1", "Location1", 10));

            Assert.True(result);
            result = await service.HandleButtonTriggerInput(CreateSerializedButtonTriggerIoTMessage("Event1", "Location2", 15));

            Assert.True(result);
            result = await service.HandleButtonTriggerInput(CreateSerializedButtonTriggerIoTMessage("Event1", "Location1", 20));

            Assert.True(result);
            result = await service.HandleButtonTriggerInput(CreateSerializedButtonTriggerIoTMessage("Event2", "Location1", 5));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal(30, eventObj.EventLocations.Find(p => p.Id == "Location1").GoalStatus);
            Assert.Equal(15, eventObj.EventLocations.Find(p => p.Id == "Location2").GoalStatus);
            Assert.Null(eventObj.EventLocations.Find(p => p.Id == "Location3"));
            eventObj = await _mockEventRest.Object.GetEvent("Event2");

            Assert.Equal(5, eventObj.EventLocations.Find(p => p.Id == "Location1").GoalStatus);
            Assert.Equal(0, eventObj.EventLocations.Find(p => p.Id == "Location2").GoalStatus);
            Assert.Null(eventObj.EventLocations.Find(p => p.Id == "Location3"));
        }
示例#4
0
        public async void TestEventRestError()
        {
            DBMock.Init();
            var service = CreateEventProcessorServiceWithFailingRest();
            await service.HandleEventTriggerInput(CreateDeviceTriggerIoTMessage("DeviceButton", "button"));

            Assert.True(VerifyErrorLog("CreateEvent: The event was not created", _mockLogger));
            Assert.True(VerifyErrorLog("HandleEventTriggerInput: The event could not be created.", _mockLogger));
        }
        public async void SendNewIoTNoteMessageTypeButton()
        {
            DBMock.Init();
            var service = CreateMessageService();
            var result  = await service.HandleNoteTriggerInput(CreateSerializedButtonTriggerIoTMessage("Event1", "Location1"));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Hope").Value);
        }
        public async void SendNewIoTNoteMessageEventNotExists()
        {
            DBMock.Init();
            var service = CreateMessageService();
            var result  = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("EventFake", "This is a note about hope"));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Hope").Value);
        }
示例#7
0
        public async void SendNewIoTButtonMessageTypeNote()
        {
            DBMock.Init();
            var service = CreateButtonService();
            var result  = await service.HandleButtonTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1"));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal(0, eventObj.EventLocations.Find(p => p.Id == "Location1").GoalStatus);
        }
示例#8
0
        public async void SendNewIoTButtonMessageEventExists()
        {
            var logger = CreateLogger <ButtonService.ButtonService>();

            DBMock.Init();
            var service = CreateButtonService();
            var result  = await service.HandleButtonTriggerInput(CreateSerializedButtonTriggerIoTMessage("Event1", "Location1", 15));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal(15, eventObj.EventLocations.Find(p => p.Id == "Location1").GoalStatus);
        }
        public async void SendNewIoTNoteMessagesTestSentimentValues()
        {
            DBMock.Init();
            var service = CreateMessageService();
            var result  = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "This is a note about hope"));

            Assert.True(result);
            result = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "This is a nete about hape")); //Duplicate should be ignored.

            Assert.True(result);
            result = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "We all want love"));

            Assert.True(result);
            result = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "this is a nete about hapy"));

            Assert.True(result);
            result = await service.HandleNoteTriggerInput(CreateSerializedNoteCreatedIoTMessage("Event1", "we care about you!"));

            Assert.True(result);
            var eventObj = await _mockEventRest.Object.GetEvent("Event1");

            Assert.Equal(2, eventObj.EventSentiments.Find(p => p.Name == "Hope").Value);
            Assert.Equal(50, eventObj.EventSentiments.Find(p => p.Name == "Hope").Percentage);
            Assert.Equal(1, eventObj.EventSentiments.Find(p => p.Name == "Love").Value);
            Assert.Equal(25, eventObj.EventSentiments.Find(p => p.Name == "Love").Percentage);
            Assert.Equal(1, eventObj.EventSentiments.Find(p => p.Name == "Care").Value);
            Assert.Equal(25, eventObj.EventSentiments.Find(p => p.Name == "Care").Percentage);

            eventObj = await _mockEventRest.Object.GetEvent("Event2");

            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Brave").Value);
            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Brave").Percentage);
            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Courage").Value);
            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Courage").Percentage);
            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Love").Value);
            Assert.Equal(0, eventObj.EventSentiments.Find(p => p.Name == "Love").Percentage);
        }