protected void SetMainStatus(AgentTaskResult result, TimeSpan actualInterval) { var unitTestResult = new SendUnitTestResultData() { ActualInterval = actualInterval, Message = result.Message, Result = result.Status }; MainUnitTest.SendResult(unitTestResult); }
public void SendResultsTest() { var account = TestHelper.GetTestAccount(); var client = account.GetClient(); client.Config.Access.WaitOnError = TimeSpan.Zero; var component = account.CreateRandomComponentControl(); // 1 - запросим статус неизвестной проверки Guid unitTestId = Guid.NewGuid(); var checkResponse = client.ApiService.GetUnitTestState(unitTestId); Assert.False(checkResponse.Success); // 2 - отправляем Success var unitTest = component.GetOrCreateUnitTestControl("myInstance"); unitTestId = unitTest.Info.Id; var now = TestHelper.GetNow(); var message = new SendUnitTestResultData() { ActualInterval = TimeSpan.FromMinutes(10), Message = "Ура проверка, работает!", Result = UnitTestResult.Success }; var sendResponse = unitTest.SendResult(message); Assert.True(sendResponse.Success); // 3 - запросим статус нашей проверки checkResponse = client.ApiService.GetUnitTestState(unitTestId); Assert.True(checkResponse.Success); var status = checkResponse.Data; Assert.Equal(status.OwnerId, unitTest.Info.Id); Assert.Equal(status.Message, message.Message); Assert.Equal(status.Status, MonitoringStatus.Success); // 4 - отправляем повтор message.Message = "Изменили сообщение"; sendResponse = unitTest.SendResult(message); Assert.True(sendResponse.Success); checkResponse = client.ApiService.GetUnitTestState(unitTestId); Assert.True(checkResponse.Success); status = checkResponse.Data; Assert.Equal(status.OwnerId, unitTest.Info.Id); Assert.Equal(status.Message, "Изменили сообщение");// новое Assert.Equal(status.Status, MonitoringStatus.Success); }
public override SendUnitTestResultResponse SendResult(SendUnitTestResultData data) { return(ResponseHelper.GetOfflineResponse <SendUnitTestResultResponse>()); }
public static SendUnitTestResultRequestDtoData GetSendUnitTestResultRequestDtoData(Guid unitTestId, SendUnitTestResultData data) { return(new SendUnitTestResultRequestDtoData() { UnitTestId = unitTestId, ActualIntervalSeconds = GetSeconds(data.ActualInterval), Message = data.Message, Result = data.Result, ReasonCode = data.ReasonCode, Properties = GetExtentionPropertyDtos(data.Properties) }); }
public ComponentSelfTestResult Validate() { var result = new ComponentSelfTestResult() { Success = true, UnitTests = new Dictionary <string, Exception>() }; foreach (var pair in _unitTests) { var name = pair.Key; var action = pair.Value; try { action(); result.UnitTests.Add(name, null); } catch (Exception exception) { result.UnitTests.Add(name, exception); result.Success = false; } } var log = new StringBuilder(); var unitTestControl = _componentControl.GetOrCreateUnitTestControl("SelfTest"); if (_unitTests.Count == 0) { result.Success = false; log.AppendLine("Нет ни одного юнит-теста"); unitTestControl.SendResult(UnitTestResult.Alarm, TimeSpan.FromMinutes(5), "Нет ни одного юнит-теста"); } else { if (result.Success) { unitTestControl.SendResult(UnitTestResult.Success, TimeSpan.FromMinutes(5)); } else { var resultData = new SendUnitTestResultData() { ActualInterval = TimeSpan.FromMinutes(5), Result = UnitTestResult.Alarm }; foreach (var pair in result.UnitTests) { var name = pair.Key; var exception = pair.Value; var message = (exception == null) ? "success" : exception.Message; resultData.Properties.Set(name, message); } unitTestControl.SendResult(resultData); } } string title = result.Success ? "### SUCCESS ###" : "### ERROR ###"; foreach (var pair in result.UnitTests) { var name = pair.Key; var exception = pair.Value; var message = (exception == null) ? "success" : exception.Message; log.AppendLine(name + ": " + message); } result.Log = title + Environment.NewLine + DateTime.Now + Environment.NewLine + "-----------------------------------------------" + Environment.NewLine + log; return(result); }