@@ -524,12 +524,80 @@ module Examples =
524
524
exactCopy = false
525
525
}
526
526
527
- let testConfig = { config with ExampleConfigFiles = Some [ { exampleConfigFile with exactCopy = false } ] }
527
+ let testConfig = { config with ExampleConfigFiles = Some [ exampleConfigFile ] }
528
528
Restler.Workflow.generateRestlerGrammar None testConfig
529
529
530
530
let grammarFilePath = Path.Combine( grammarOutputDirectoryPath, Restler.Workflow.Constants.DefaultRestlerGrammarFileName)
531
531
let grammar = File.ReadAllText( grammarFilePath)
532
532
Assert.True( grammar.Contains( " required-param" ))
533
533
Assert.True( grammar.Contains( " optional-param" ))
534
534
535
+
536
+ /// Test that the grammar is correct when the entire body is replaced by an example payload.
537
+ /// Both 'exactCopy' settings should be tested.
538
+ [<Fact>]
539
+ let ``replace entire body with example`` () =
540
+ let grammarOutputDirectoryPath = ctx.testRootDirPath
541
+ let config = { Restler.Config.SampleConfig with
542
+ IncludeOptionalParameters = false
543
+ GrammarOutputDirectoryPath = Some grammarOutputDirectoryPath
544
+ ResolveBodyDependencies = false
545
+ UseBodyExamples = Some true
546
+ UseQueryExamples = Some true
547
+ DataFuzzing = true
548
+ SwaggerSpecFilePath = Some [( Path.Combine( Environment.CurrentDirectory, @" swagger\exampleTests\body_param.json" ))]
549
+ }
550
+
551
+ let exampleConfigFile = {
552
+ filePath = Path.Combine( Environment.CurrentDirectory, @" swagger\exampleTests\body_param_example.json" )
553
+ exactCopy = true
554
+ }
555
+
556
+ let testConfig = { config with ExampleConfigFiles = Some [ exampleConfigFile ] }
557
+ Restler.Workflow.generateRestlerGrammar None testConfig
558
+
559
+ let expectedGrammarFilePath = Path.Combine( Environment.CurrentDirectory,
560
+ @" baselines\exampleTests\body_param_exactCopy_grammar.py" )
561
+ let actualGrammarFilePath = Path.Combine( grammarOutputDirectoryPath,
562
+ Restler.Workflow.Constants.DefaultRestlerGrammarFileName)
563
+ let grammarDiff = getLineDifferences expectedGrammarFilePath actualGrammarFilePath
564
+ let message = sprintf " Grammar Does not match baseline. First difference: %A " grammarDiff
565
+ Assert.True( grammarDiff.IsNone, message)
566
+
567
+ ///// Test that the grammar is correct when the entire body is replaced by an example payload.
568
+ ///// Both 'exactCopy' settings should be tested.
569
+ //[<Fact>]
570
+ //let ``replace entire body with example`` () =
571
+ // let grammarOutputDirectoryPath = ctx.testRootDirPath
572
+
573
+ // let customDictionaryText = "{ \"restler_custom_payload\":\
574
+ // { \"/subnets/{subnetName}/get/__body__\": [\"abc\"] } }\
575
+ // "
576
+ // // TODO: passing in the dictionary directly via 'SwaggerSpecConfig' is not working.
577
+ // // Write out the dictionary until the but is fixed
578
+ // //
579
+ // let dictionaryFilePath =
580
+ // Path.Combine(grammarOutputDirectoryPath,
581
+ // "input_dict.json")
582
+ // File.WriteAllText(dictionaryFilePath, customDictionaryText)
583
+
584
+ // let config = { Restler.Config.SampleConfig with
585
+ // IncludeOptionalParameters = true
586
+ // GrammarOutputDirectoryPath = Some grammarOutputDirectoryPath
587
+ // ResolveBodyDependencies = true
588
+ // UseBodyExamples = Some true
589
+ // SwaggerSpecFilePath = Some [Path.Combine(Environment.CurrentDirectory, @"swagger\dependencyTests\subnet_id.json")]
590
+ // AllowGetProducers = true
591
+ // CustomDictionaryFilePath = Some dictionaryFilePath
592
+ // }
593
+
594
+ // Restler.Workflow.generateRestlerGrammar None config
595
+
596
+ // let grammarFilePath = Path.Combine(grammarOutputDirectoryPath,
597
+ // Restler.Workflow.Constants.DefaultRestlerGrammarFileName)
598
+ // let grammar = File.ReadAllText(grammarFilePath)
599
+
600
+ // Assert.True(grammar.Contains("""restler_custom_payload("/subnets/{subnetName}/get/__body__", quoted=False)"""))
601
+
602
+
535
603
interface IClassFixture< Fixtures.TestSetupAndCleanup>
0 commit comments