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); }
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)); }
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 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); } }