public void testMap_shouldFaileToParseStructureEvent() { var handler = new DummyEventHandler(); var mapper = new ObjectModelMapper(handler); mapper.Map(new StreamingEvent("put", "{\"devices\":\"cameras\":{}")); }
public void testMap_shouldFailToParseErrorEvent() { var handler = new DummyEventHandler(); var mapper = new ObjectModelMapper(handler); string json = "{\"error\":\"unauthorized\""; mapper.Map(new StreamingEvent("error", json)); }
public void testMap_shouldTriggerAuthRevokedEvent() { var handler = new DummyEventHandler(); var mapper = new ObjectModelMapper(handler); mapper.Map(new StreamingEvent("auth_revoked", "")); Assert.IsNull(handler.error); Assert.IsNull(handler.updateEvent); Assert.IsTrue(handler.authRevokedEvent); }
public void testMap_shouldSkipUnknownEvent() { var handler = new DummyEventHandler(); var mapper = new ObjectModelMapper(handler); mapper.Map(new StreamingEvent("unknown", "")); Assert.IsNull(handler.error); Assert.IsNull(handler.updateEvent); Assert.IsFalse(handler.authRevokedEvent); }
public void testMap_shouldParseErrorEvent() { //Should also ignore unknown fields var handler = new DummyEventHandler(); var mapper = new ObjectModelMapper(handler); string json = "{\"error\":\"unauthorized\",\"type\":\"auth-error\",\"message\":\"unauthorized\",\"instance\":\"2372e4af-c774-495f-b485-5e6a81aa27fe\",\"unknown\":\"ignore\"}"; mapper.Map(new StreamingEvent("error", json)); Assert.IsNotNull(handler.error); Assert.AreEqual(handler.error.Error, "unauthorized"); Assert.AreEqual(handler.error.Type, "auth-error"); Assert.IsNull(handler.updateEvent); Assert.IsFalse(handler.authRevokedEvent); }
public void testMap_shouldParseStructureEventWithPathNode() { var handler = new DummyEventHandler(); var mapper = new ObjectModelMapper(handler); string json = LoadString(TEST_GLOBAL_UPDATE_JSON_NEW); mapper.Map(new StreamingEvent("put", json)); Assert.IsNull(handler.error); Assert.IsFalse(handler.authRevokedEvent); GlobalUpdate eventData = handler.updateEvent; Assert.IsNotNull(eventData); Assert.IsNotNull(eventData.Devices); Assert.IsNotNull(eventData.Metadata); Assert.IsNotNull(eventData.Structures); Assert.IsNotNull(eventData.Devices.Cameras); Assert.IsNotNull(eventData.Devices.SmokeCOAlarms); Assert.IsNotNull(eventData.Devices.Thermostats); Assert.AreEqual(eventData.Devices.Cameras.Count, 1); Assert.AreEqual(eventData.Devices.SmokeCOAlarms.Count, 1); Assert.AreEqual(eventData.Devices.Thermostats.Count, 1); }