public void SimpleConvertionWithCodeGenOptionShouldCreateTableAndCodeOutput() { var sut = new JsonConverterToExampleTable(); var convertionResult = sut.Convert(PayloadLoader.GetPayloadAsString("TwoItemsPayload"), true); AssertConvertionResult(convertionResult, JsonParserGeneralTest.ExpectedTableTwoItemsPayload, ExpectedSimpleCode); }
public void ConvertionWithCodeGenOptionShouldReturnNormalizedAndWithTheRightAttribute() { var sut = new JsonConverterToExampleTable(); var convertionResult = sut.Convert(PayloadLoader.GetPayloadAsString("SimplePayloadWithInsideObject"), true); AssertConvertionResult(convertionResult, JsonParserGeneralTest.SimplePayloadWithInsideObjectExpectedTable, ExpectedNormalizedwithAttribute); }
public void ConvertMultipleValidJsonShouldReturnMultilineExampleTableToFileDest() { var expected = $"|name|Age|{Environment.NewLine}|this is a test|33|{Environment.NewLine}|this is a test|33|"; var sut = CreateService(); var jsonToTest = PayloadLoader.GetPayloadAsString("TwoItemsPayload"); var fileFolderGuid = Guid.NewGuid().ToString(); var originFolder = Path.Combine(Directory.GetCurrentDirectory(), fileFolderGuid); Directory.CreateDirectory(originFolder); var destFilePath = $"destFile_{Guid.NewGuid()}.txt"; var file1 = Path.Combine(originFolder, $"example1_{Guid.NewGuid()}.json"); var file2 = Path.Combine(originFolder, $"example2_{Guid.NewGuid()}.json"); var config = ConfigurationBuilder.StartBuild(CreateLoggerForConfigurationBuilder()) .WithFolderPath(originFolder) .WithResultFilePath(destFilePath) .Build(); try { File.WriteAllText(file1, jsonToTest); File.WriteAllText(file2, jsonToTest); sut.Convert(config); var result = File.ReadAllText(destFilePath); result.Should().BeEquivalentTo(expected); } finally { CleanUpTestScenario(config); } }
public void ParseMultiDifferentJsonShouldReturnErrorMessage() { var firstJson = PayloadLoader.GetPayloadAsString("TwoItemsPayload"); var secondJson = PayloadLoader.GetPayloadAsString("SimplePayloadWithInsideObject"); var sut = JsonParserGeneralTest.GetNewConverter().ConvertMultipleIntoSingleTable(false, firstJson, secondJson); CommonTestsHelper.AssertValidTable(GeneralConstants.AllJsonsShouldHaveSameFieldNamsToConvertMultipleIntoOneTable, sut); }
public void ParseCoupleOfSimpleJsonShouldReturnValidTableWithMultiLines() { var expectedTable = $"|name|Age|{Environment.NewLine}|this is a test|33|{Environment.NewLine}|this is a test|33|"; var firstJson = PayloadLoader.GetPayloadAsString("TwoItemsPayload"); var SecondJson = PayloadLoader.GetPayloadAsString("TwoItemsPayload"); var sut = JsonParserGeneralTest.GetNewConverter().ConvertMultipleIntoSingleTable(false, firstJson, SecondJson); CommonTestsHelper.AssertValidTable(expectedTable, sut); }
public void ConvertFromValidPayloadOnClipboardShouldGenerateValideExampleTable() { Skip.If(Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX); var simplePayload = PayloadLoader.GetPayloadAsString("TwoItemsPayload"); new Clipboard().SetText(simplePayload); var convertionService = CreateService(); var config = ConfigurationBuilder.StartBuild(CreateLoggerForConfigurationBuilder()) .WithPayloadFromClipboard(true) .Build(); convertionService.Convert(config); var result = new Clipboard().GetText(); result.Should().BeEquivalentTo(JsonParserGeneralTest.ExpectedTableTwoItemsPayload); }
public void ConvertSingleValidJsonShouldReturnExampleTableToFileDest() { var sut = CreateService(); var jsonToTest = PayloadLoader.GetPayloadAsString("TwoItemsPayload"); var config = ConfigurationBuilder.StartBuild(CreateLoggerForConfigurationBuilder()) .WithFilePath($"example_{Guid.NewGuid()}.json") .WithResultFilePath($"destFile_{Guid.NewGuid()}.txt") .Build(); try { File.WriteAllText(config.FilePath, jsonToTest); sut.Convert(config); var result = File.ReadAllText(config.ResultFilePath); result.Should().BeEquivalentTo(JsonParserGeneralTest.ExpectedTableTwoItemsPayload); } finally { CleanUpTestScenario(config); } }