public void GetInputData_Test( string expectedLocaly, int expectedNumber, params string[] args ) { // Arrange var expectedValue = new InputData() { LocalizationName = expectedLocaly, Number = expectedNumber }; var logger = new Mock <ILogger>(); var languageNumbersDescriptors = new ILanguageNumbersDescriptor[] { new EnLoсalizationNumbers(), new RuLocalizationNumbers(), new UaLocalizationNumbers() }; var inputDataParser = new InputDataParser(languageNumbersDescriptors, logger.Object); // Act var actualValue = inputDataParser.GetInputData(args); // Assert Assert.Equal(expectedValue.LocalizationName, actualValue.LocalizationName); Assert.Equal(expectedValue.Number, actualValue.Number); }
/// <inheritdoc /> public async Task <bool> InitializeAsync(IAgentLogPluginContext context) { try { _logger = new TraceLogger(context); _clientFactory = new ClientFactory(context.VssConnection); PopulatePipelineConfig(context); if (CheckForPluginDisable(context)) { return(false); // disable the plugin } await InputDataParser.InitializeAsync(_clientFactory, _pipelineConfig, _logger); } catch (Exception ex) { _logger.Warning($"Unable to initialize {FriendlyName}"); context.Trace(ex.ToString()); return(false); } return(true); }
public async Task <IActionResult> Edit(BenchmarkDto model) { ApplicationUser user = await this.GetCurrentUserAsync(); if (user == null) { throw new NotLoggedInException("You are not logged in"); } const string ViewName = "Add"; if (!this.ModelState.IsValid) { return(this.View(ViewName, model)); } // Manually parse input var testCases = InputDataParser.ReadTestCases(this.HttpContext.Request); // Check if benchmark code was actually entered if (testCases.Count() < 2) { this.ModelState.AddModelError("TestCases", "At least two test cases are required."); return(this.View(ViewName, model)); } if (testCases.Any(t => string.IsNullOrWhiteSpace(t.BenchmarkCode))) { this.ModelState.AddModelError("TestCases", "Benchmark code must not be empty."); return(this.View(ViewName, model)); } model.TestCases = new List <TestCaseDto>(testCases); // Check that there are no test cases with the same name var set = new HashSet <string>(); foreach (var testCase in model.TestCases) { if (!set.Add(testCase.TestCaseName.ToLowerInvariant().Trim())) { this.ModelState.AddModelError("TestCases", "Test cases must have unique names"); return(this.View("Add", model)); } } try { BenchmarkDto updatedModel = await this.m_benchmarkRepository.Update(model, user.Id); return(this.RedirectToAction("Show", new { Id = updatedModel.Id, Version = updatedModel.Version, name = SeoFriendlyStringConverter.Convert(model.BenchmarkName) })); } catch (Exception ex) { m_logger.LogError("Can't update benchmark: " + ex.Message); return(RedirectToAction(ErrorActionName)); } }
public void GetTicketsTask_Negative() { // Arrange var args = new string[] { "Nothing" }; // Assert Assert.Throws <FileNotFoundException>(() => InputDataParser.GetTicketsTask(args)); }
public async Task <IActionResult> Add(BenchmarkDto model) { if (!this.ModelState.IsValid) { return(this.View(model)); } // Manually parse input var testCases = InputDataParser.ReadTestCases(this.HttpContext.Request); // Check if benchmark code was actually entered if (testCases.Count() < 2) { // TODO: use correct error key this.ModelState.AddModelError("TestCases", "At least two test cases are required."); return(this.View(model)); } if (testCases.Any(t => string.IsNullOrWhiteSpace(t.BenchmarkCode))) { this.ModelState.AddModelError("TestCases", "Benchmark code must not be empty."); return(this.View(model)); } model.TestCases = new List <TestCaseDto>(testCases); // Check that there are no test cases with the same name var set = new HashSet <string>(); foreach (var testCase in model.TestCases) { if (!set.Add(testCase.TestCaseName.ToLowerInvariant().Trim())) { this.ModelState.AddModelError("TestCases", "Test cases must have unique names"); return(this.View(model)); } } ApplicationUser user = await this.GetCurrentUserAsync(); model.OwnerId = user?.Id; long id = await this.m_benchmarkRepository.Add(model); return(this.RedirectToAction("Show", new { Id = id, Version = 0, name = SeoFriendlyStringConverter.Convert(model.BenchmarkName) })); }
public void GetInputData_NegativeNumbers_Tests(params string[] args) { // Arrange var logger = new Mock <ILogger>(); var languageNumbersDescriptors = new ILanguageNumbersDescriptor[] { new EnLoсalizationNumbers(), new RuLocalizationNumbers(), new UaLocalizationNumbers() }; var inputDataParser = new InputDataParser(languageNumbersDescriptors, logger.Object); // Assert Assert.Throws <ArgumentException>(() => inputDataParser.GetInputData(args)); }
private void ValidateInputModel(BenchmarkDto model) { if (!this.ModelState.IsValid) { return; } // Manually parse input var testCases = InputDataParser.ReadTestCases(this.HttpContext.Request); // Check if benchmark code was actually entered if (testCases.Count() < 2) { this.ModelState.AddModelError("TestCases", "At least two test cases are required."); } if (testCases.Any(t => string.IsNullOrWhiteSpace(t.BenchmarkCode))) { this.ModelState.AddModelError("TestCases", "Benchmark code must not be empty."); } model.TestCases = new List <TestCaseDto>(testCases); // Check that there are no test cases with the same name var set = new HashSet <string>(); foreach (var testCase in model.TestCases) { if (testCase == null) { continue; } if (string.IsNullOrWhiteSpace(testCase.TestCaseName)) { this.ModelState.AddModelError("TestCases", "Test name must not be empty"); continue; } if (!set.Add(testCase.TestCaseName.ToLowerInvariant().Trim())) { this.ModelState.AddModelError("TestCases", "Test cases must have unique names"); } } }
public void GetInputData_OverflowNumbers_Tests() { // Arrange var args = new string[] { "ru", "1000000000" }; var logger = new Mock <ILogger>(); var languageNumbersDescriptors = new List <ILanguageNumbersDescriptor> { new EnLoсalizationNumbers(), new RuLocalizationNumbers(), new UaLocalizationNumbers() }; var inputDataParser = new InputDataParser(languageNumbersDescriptors, logger.Object); // Assert Assert.Throws <OverflowException>(() => inputDataParser.GetInputData(args)); }
public void GetTicketsTask_Positive() { // Arrange var args = new string[] { "File.txt" }; var expectedTicketsTask = new TicketsTask { Algorithm = "Piter" }; // Act var actualTicketsTask = InputDataParser.GetTicketsTask(args); // Assert Assert.Equal(expectedTicketsTask.Algorithm, actualTicketsTask.Algorithm); }
public static void Main(string[] args) { var logPath = "application.log"; var logger = new AggregatedLogger( new FileLogger(logPath), new ConsoleLogger() ); try { if (!Validator.IsParametersValid(args)) { logger.LogInformation("Input data must be in format <LocalizationType> <number>"); return; } var languageNumbersDescriptors = new ILanguageNumbersDescriptor[] { new EnLoсalizationNumbers(), new RuLocalizationNumbers(), new UaLocalizationNumbers() }; var inputDataParser = new InputDataParser(languageNumbersDescriptors, logger); var inputData = inputDataParser.GetInputData(args); var localization = languageNumbersDescriptors.First(l => l.Name == inputData.LocalizationName); var result = NumberConverter.ConvertToString(inputData.Number, localization); logger.LogInformation($"Result: {result}"); } catch (Exception ex) { logger.LogInformation(ex.Message); } }
/// <inheritdoc /> public async Task FinalizeAsync(IAgentLogPluginContext context) { await InputDataParser.CompleteAsync(); }
/// <inheritdoc /> public async Task ProcessLineAsync(IAgentLogPluginContext context, Pipelines.TaskStepDefinitionReference step, string line) { await InputDataParser.ProcessDataAsync(line); }