Browse Source

Added tests for RequestAllTemplateFiles.

Updated the script file and ConsoleCommands-- removed unused code.
master
Craig Oates 6 years ago
parent
commit
89925ec95f
  1. 31
      TestCentre/PropertyTests.fs
  2. 24
      TestCentre/UnitTests.fs
  3. 1
      WetPancake/ProductServices.fs
  4. 9
      WetPancake/Script.fsx
  5. 21
      WetPancakeCLI/ConsoleCommands.cs

31
TestCentre/PropertyTests.fs

@ -10,7 +10,7 @@
module ``Null Tests`` =
[<Property>]
let ``Request Random Text does not return null when using the built-in random settings`` () =
let ``Request Random Text does not return a null when using the built-in random settings`` () =
let test =
Pancake.RequestRandomTextAsync ()
|> Async.RunSynchronously
@ -18,7 +18,7 @@
Check.Quick results
[<Property>]
let ``Request Text does not return null when using fixed input parameters`` () =
let ``Request Text does not return a null when using fixed input parameters`` () =
let gibberishLevel () = System.Random().Next(2, 10)
let totalSentences () = System.Random().Next(2, 10)
let test =
@ -28,7 +28,7 @@
Check.Quick results
[<Property>]
let ``Request Text does not return null when using a random gibberish level`` () =
let ``Request Text does not return a null when using a random gibberish level`` () =
let gibberishLevel () = System.Random().Next(2, 10)
let test =
Pancake.RequestTextAsync (gibberishLevel()) 10
@ -37,7 +37,7 @@
Check.Quick results
[<Property>]
let ``Request Text does not return null when using a random sentence count`` () =
let ``Request Text does not return a null when using a random sentence count`` () =
let totalSentences () = System.Random().Next(2, 10)
let test () =
Pancake.RequestTextAsync 5 (totalSentences())
@ -46,7 +46,7 @@
Check.Quick results
[<Property>]
let ``Using desktop-clock-info does not return null`` () =
let ``Using desktop-clock-info does not return a null`` () =
let gibberishLevel () = System.Random().Next(2, 10)
let totalSentences () = System.Random().Next(2, 10)
let test =
@ -56,7 +56,7 @@
Check.Quick results
[<Property>]
let ``Using console-waterworks-announcement does not return null`` () =
let ``Using console-waterworks-announcement does not return a null`` () =
let gibberishLevel () = System.Random().Next(2, 10)
let totalSentences () = System.Random().Next(2, 10)
let test =
@ -66,7 +66,7 @@
Check.Quick results
[<Property>]
let ``Using word-generator does not return null`` () =
let ``Using word-generator does not return a null`` () =
let gibberishLevel () = System.Random().Next(2, 10)
let totalSentences () = System.Random().Next(2, 10)
let test =
@ -76,7 +76,7 @@
Check.Quick results
[<Property>]
let ``Using test-post does not return null`` () =
let ``Using test-post does not return a null`` () =
let gibberishLevel () = System.Random().Next(2, 10)
let totalSentences () = System.Random().Next(2, 10)
let test =
@ -85,6 +85,14 @@
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``RequestAllTemplateFiles does not return a null`` () =
let test =
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
let results = Assert.NotNull test
Check.Quick results
module ``Contents Test`` =
[<Property>]
@ -203,3 +211,10 @@
let results = Assert.EndsWith(".", test)
Check.Quick results
[<Property>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
let test =
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
let results = Assert.NotEmpty test
Check.Quick results

24
TestCentre/UnitTests.fs

@ -37,35 +37,35 @@
let ``RequestRandomText does not return a null`` () =
let result = Pancake.RequestRandomTextAsync ()
Assert.NotNull result
[<Fact>]
let ``RequestText does not return a null`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result () = Pancake.RequestTextAsync gibberishLevel totalSentences
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using desktop-clock-info`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences DesktopClock
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using console-waterworks-announcement`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences ConsoleWaterworks
Assert.NotNull result
[<Fact>]
let ``RequestTextFromFile does not return a null when using word-generator`` () =
let gibberishLevel = System.Random().Next(2, 20)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences WordGenerator
Assert.NotNull result
[<Fact>]
let ``RequestTestFromFile does not generate a null when using test-post`` () =
let gibberishLevel = System.Random().Next(2, 20)
@ -73,6 +73,11 @@
let result = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences TestPost
Assert.NotNull result
[<Fact>]
let ``RequestAllTemplateFiles does not generate a null`` () =
let result = Pancake.RequestAllTemplateFilesAsync ()
Assert.NotNull result
module ``Contents Tests`` =
[<Fact>]
@ -177,4 +182,11 @@
let result =
Pancake.RequestTextFromFileAsync gibberishLevel totalSentences WordGenerator
|> Async.RunSynchronously
Assert.EndsWith(".", result)
Assert.EndsWith(".", result)
[<Fact>]
let ``RequestAllTemplateFiles does not return an empty list`` () =
let result =
Pancake.RequestAllTemplateFilesAsync ()
|> Async.RunSynchronously
Assert.NotEmpty result

1
WetPancake/ProductServices.fs

@ -40,7 +40,6 @@ module Pancake =
return GenerateMarkovText sentences data
}
// These two methods have not been tested in Test Centre yet.
let RequestAllTemplateFilesAsync () =
async {
let files =

9
WetPancake/Script.fsx

@ -137,8 +137,7 @@ let ps_result3 = Pancake.RequestTextFromFileAsync 3 10 DesktopClock
let ps_result4 = Pancake.RequestTextFromFileAsync 3 10 ConsoleWaterworks
let ps_result5 = Pancake.RequestTextFromFileAsync 3 10 WordGenerator
let ps_result6 = Pancake.RequestTextFromFileAsync 3 10 TestPost
let ps_files = Pancake.RequestAllTextFilesAsync ()
let ps_files = Pancake.RequestAllTemplateFilesAsync ()
ps_result1 |> Async.RunSynchronously
ps_result2 |> Async.RunSynchronously
@ -146,8 +145,4 @@ ps_result3 |> Async.RunSynchronously
ps_result4 |> Async.RunSynchronously
ps_result5 |> Async.RunSynchronously
ps_result6 |> Async.RunSynchronously
let ps_templateFiles = ps_files |> Async.RunSynchronously
let ps_templateResult7 =
Pancake.RequestTextFromTemplateAsync 3 10 ps_templateFiles.[2]
|> Async.RunSynchronously
ps_files |> Async.RunSynchronously

21
WetPancakeCLI/ConsoleCommands.cs

@ -117,26 +117,5 @@ namespace WetPancakeCLI
throw;
}
}
[ListCommand]
[Description("Generates text using the gibberish level (between 2 and 20) and number of sentences specified by the user." +
"You can, also, specify which template file you want to use. " +
"If you are unsure what options are available, use the RequestAllTemplateFiles command-method to generate a list of them.")]
[Parameters("gibberish level: int, sentences: int, file path: string")]
[Usage("> GenerateTextFromTemplate 5 10 D:\\WetPancake\\WetPancake\\TextFiles\\console-waterworks-announcement.txt")]
public static string GenerateTextFromTemplate(int gibberishLevel, int sentences, string filePath)
{
try
{
if (gibberishLevel < 2 || gibberishLevel > 20) throw new ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel");
if (sentences < 1) throw new ArgumentException("Invalid argument. Must be greater than 0.", "sentences");
return FSharpAsync.StartAsTask(RequestTextFromTemplateAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result;
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
throw;
}
}
}
}

Loading…
Cancel
Save