public async Task Handle_WhenEventClientReturnsSuccessful_ReturnCorrectEvent() { long expectedEventId = 1; long expectedEventTypeId = 1; long expectedIncidentId = 1; var expectedEvent = new Event { Id = expectedEventId, EventTypeId = expectedEventTypeId, IncidentId = expectedIncidentId }; var serviceUnderTest = new GetEventHandler(await MockFactory .IncidentContext(nameof(Handle_WhenEventClientReturnsSuccessful_ReturnCorrectEvent)) .ConfigureAwait(continueOnCapturedContext: false)); var request = new GetEventRequest(expectedIncidentId, expectedEventId, new DummyAuthenticatedUserContext()); var result = await serviceUnderTest .Handle(request, new System.Threading.CancellationToken()) .ConfigureAwait(continueOnCapturedContext: false); Assert.AreEqual(expectedEventId, result.Id); Assert.AreEqual(expectedEventTypeId, result.EventTypeId); Assert.AreEqual(expectedIncidentId, result.IncidentId.Value); }
/// <summary> /// /// </summary> /// <param name="longpolling">Set true for event notification, false for immediate response.</param> /// <param name="error"></param> /// <param name="result"></param> public void GetEvent(bool longpolling, Action<int> error, GetEventHandler result) { AsyncPostClient.Post(endpoint, RequestGenerator.getEvent(longpolling), (res) => { ResultHandler.GetEvent(res, error, result); }, () => { error.Invoke(StatusCode.Any); }); }
internal static void GetEvent(string jString, Action<int> error, GetEventHandler result) { var json = JObject.Parse(jString); if (BasicResultHandler.HandleError(json, error)) { return; } var jResult = json["result"]; var jApi = jResult[0]; string[] apis = null; if (jApi.HasValues) { var apilist = new List<string>(); foreach (var str in jApi["names"].Values<string>()) { apilist.Add(str); } apis = apilist.ToArray(); } var jStatus = jResult[1]; string status = null; if (jStatus.HasValues) { status = jStatus.Value<string>("cameraStatus"); } var jZoom = jResult[2]; ZoomInfo zoom = null; if (jZoom.HasValues) { zoom = new ZoomInfo { position = jZoom.Value<int>("zoomPosition"), number_of_boxes = jZoom.Value<int>("zoomNumberBox"), current_box_index = jZoom.Value<int>("zoomIndexCurrentBox"), position_in_current_box = jZoom.Value<int>("zoomPositionCurrentBox") }; } var jLiveview = jResult[3]; bool liveview_status = false; if (jLiveview.HasValues) { jLiveview.Value<bool>("liveviewStatus"); } var jExposureMode = jResult[18]; BasicInfo<string> exposure = null; if (jExposureMode.HasValues) { var modecandidates = new List<string>(); foreach (var str in jExposureMode["exposureModeCandidates"].Values<string>()) { modecandidates.Add(str); } exposure = new BasicInfo<string> { current = jExposureMode.Value<string>("currentExposureMode"), candidates = modecandidates.ToArray() }; } var jPostView = jResult[19]; BasicInfo<string> postview = null; if (jPostView.HasValues) { var pvcandidates = new List<string>(); foreach (var str in jPostView["postviewImageSizeCandidates"].Values<string>()) { pvcandidates.Add(str); } postview = new BasicInfo<string> { current = jPostView.Value<string>("currentPostviewImageSize"), candidates = pvcandidates.ToArray() }; } var jSelfTimer = jResult[20]; BasicInfo<int> selftimer = null; if (jSelfTimer.HasValues) { var stcandidates = new List<int>(); foreach (var str in jSelfTimer["selfTimerCandidates"].Values<int>()) { stcandidates.Add(str); } selftimer = new BasicInfo<int> { current = jSelfTimer.Value<int>("currentSelfTimer"), candidates = stcandidates.ToArray() }; } var jShootMode = jResult[21]; BasicInfo<string> shootmode = null; if (jShootMode.HasValues) { var smcandidates = new List<string>(); foreach (var str in jShootMode["shootModeCandidates"].Values<string>()) { smcandidates.Add(str); } shootmode = new BasicInfo<string> { current = jShootMode.Value<string>("currentShootMode"), candidates = smcandidates.ToArray() }; } var jEV = jResult[25]; EvInfo ev = null; if (jEV.HasValues) { ev = new EvInfo { MaxIndex = jEV.Value<int>("maxExposureCompensation"), MinIndex = jEV.Value<int>("minExposureCompensation"), CurrentIndex = jEV.Value<int>("currentExposureCompensation"), StepDefinition = jEV.Value<int>("stepIndexOfExposureCompensation") }; } var jFN = jResult[27]; BasicInfo<string> fn = null; if (jFN.HasValues) { var fncandidates = new List<string>(); foreach (var str in jFN["fNumberCandidates"].Values<string>()) { fncandidates.Add(str); } fn = new BasicInfo<string> { current = jFN.Value<string>("currentFNumber"), candidates = fncandidates.ToArray() }; } var jIso = jResult[29]; BasicInfo<string> iso = null; if (jIso.HasValues) { var isocandidates = new List<string>(); foreach (var str in jIso["isoSpeedRateCandidates"].Values<string>()) { isocandidates.Add(str); } iso = new BasicInfo<string> { current = jIso.Value<string>("currentIsoSpeedRate"), candidates = isocandidates.ToArray() }; } var jPS = jResult[31]; bool? ps = null; if (jPS.HasValues) { ps = jPS.Value<bool>("isShifted"); } var jSS = jResult[32]; BasicInfo<string> ss = null; if (jSS.HasValues) { var sscandidates = new List<string>(); foreach (var str in jSS["shutterSpeedCandidates"].Values<string>()) { sscandidates.Add(str); } ss = new BasicInfo<string> { current = jSS.Value<string>("currentShutterSpeed"), candidates = sscandidates.ToArray() }; } result.Invoke(new Event() { AvailableApis = apis, CameraStatus = status, ZoomInfo = zoom, LiveviewAvailable = liveview_status, PostviewSizeInfo = postview, SelfTimerInfo = selftimer, ShootModeInfo = shootmode, FNumber = fn, ISOSpeedRate = iso, ShutterSpeed = ss, EvInfo = ev, ExposureMode = exposure, ProgramShiftActivated = ps }); }