public AddHttpUnitTestResponse AddHttpUnitTest(Guid accountId, AddHttpUnitTestRequestData data) { var request = GetRequest <AddHttpUnitTestRequest>(accountId); request.Data = data; var dispatcher = DispatcherHelper.GetDispatcherService(); return(dispatcher.AddHttpUnitTest(request)); }
public void AddHttpCheckTest() { // Добавим проверку http var account = TestHelper.GetTestAccount(); var component = account.CreateTestApplicationComponent(); var dispatcher = TestHelper.GetDispatcherClient(); var data = new AddHttpUnitTestRequestData() { ComponentId = component.Id, SystemName = "Http_" + Guid.NewGuid(), PeriodSeconds = 600, ErrorColor = UnitTestResult.Alarm, Rules = new[] { new AddHttpUnitTestRuleRequestData() { SortNumber = 1, DisplayName = "Rule1", Url = "http://" + Guid.NewGuid() + ".ru", Method = HttpRequestMethod.Get, ResponseCode = 200, MaxResponseSize = 1024, SuccessHtml = "<body>", ErrorHtml = "<error>", TimeoutSeconds = 5 } } }; var response = dispatcher.AddHttpUnitTest(account.Id, data); var result = response.Data; // Проверим параметры созданной проверки Assert.Equal(data.ComponentId, result.ComponentId); Assert.Equal(data.SystemName, result.SystemName); Assert.NotNull(result.DisplayName); Assert.Equal(data.PeriodSeconds, result.PeriodSeconds); Assert.Equal(data.ErrorColor, result.ErrorColor); var rules = data.Rules; Assert.NotNull(rules); var rule = rules.SingleOrDefault(t => t.SortNumber == data.Rules[0].SortNumber); Assert.NotNull(rule); Assert.Equal(data.Rules[0].DisplayName, rule.DisplayName); Assert.Equal(data.Rules[0].Url, rule.Url); Assert.Equal(data.Rules[0].Method, rule.Method); Assert.Equal(data.Rules[0].ResponseCode, rule.ResponseCode); Assert.Equal(data.Rules[0].MaxResponseSize, rule.MaxResponseSize); Assert.Equal(data.Rules[0].SuccessHtml, rule.SuccessHtml); Assert.Equal(data.Rules[0].ErrorHtml, rule.ErrorHtml); Assert.Equal(data.Rules[0].TimeoutSeconds, rule.TimeoutSeconds); }
public UnitTest AddHttpUnitTest(Guid accountId, AddHttpUnitTestRequestData data) { var unitTestCache = GetOrCreateUnitTest(accountId, new GetOrCreateUnitTestRequestData() { UnitTestTypeId = SystemUnitTestTypes.HttpUnitTestType.Id, ComponentId = data.ComponentId, SystemName = data.SystemName, DisplayName = data.DisplayName }); using (var unitTest = AllCaches.UnitTests.Write(unitTestCache)) { unitTest.PeriodSeconds = data.PeriodSeconds; unitTest.ErrorColor = data.ErrorColor; unitTest.NextDate = DateTime.Now; unitTest.BeginSave(); unitTest.WaitSaveChanges(TimeSpan.FromSeconds(30)); } var accountDbContext = Context.GetAccountDbContext(accountId); var repository = accountDbContext.GetUnitTestRepository(); var unitTestObj = repository.GetById(unitTestCache.Id); if (unitTestObj.HttpRequestUnitTest == null) { unitTestObj.HttpRequestUnitTest = new HttpRequestUnitTest() { UnitTest = unitTestObj } } ; foreach (var ruleData in data.Rules) { unitTestObj.HttpRequestUnitTest.Rules.Add(new HttpRequestUnitTestRule() { Id = Guid.NewGuid(), HttpRequestUnitTest = unitTestObj.HttpRequestUnitTest, SortNumber = ruleData.SortNumber, DisplayName = ruleData.DisplayName, Url = ruleData.Url, Method = ruleData.Method, ResponseCode = ruleData.ResponseCode, MaxResponseSize = ruleData.MaxResponseSize, SuccessHtml = ruleData.SuccessHtml, ErrorHtml = ruleData.ErrorHtml, TimeoutSeconds = ruleData.TimeoutSeconds }); } accountDbContext.SaveChanges(); return(unitTestObj); }