Browse Source

Updated the name of the functions in Product Services.

Added "Async" to end of function names to match .Net coding convention.
master
Craig Oates 6 years ago
parent
commit
633a5cd5f8
  1. 18
      TestCentre/PropertyTests.fs
  2. 14
      TestCentre/UnitTests.fs
  3. 6
      WetPancake/ProductServices.fs
  4. 12
      WetPancake/Script.fsx
  5. 12
      WetPancakeCLI/ConsoleCommands.cs

18
TestCentre/PropertyTests.fs

@ -11,7 +11,7 @@
[<Property>]
let ``Request Random Text does not return null when using the built-in random settings`` () =
let test = Pancake.RequestRandomText()
let test = Pancake.RequestRandomTextAsync()
let results = Assert.NotNull test
Check.Quick results
@ -19,21 +19,21 @@
let ``Request Text does not return null when using fixed input parameters`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestText gibberishLevel totalSentences
let test = Pancake.RequestTextAsync gibberishLevel totalSentences
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Request Text does not return null when using a random gibberish level`` () =
let gibberishLevel = System.Random().Next(2, 10)
let test = Pancake.RequestText gibberishLevel 10
let test = Pancake.RequestTextAsync gibberishLevel 10
let results = Assert.NotNull test
Check.Quick results
[<Property>]
let ``Request Text does not return null when using a random sentence count`` () =
let totalSentences = System.Random().Next(2, 10)
let test () = Pancake.RequestText 5 totalSentences
let test () = Pancake.RequestTextAsync 5 totalSentences
let results () = Assert.NotNull test
Check.Quick results
@ -41,7 +41,7 @@
let ``Using desktop-clock-info does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences DesktopClock
let test = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences DesktopClock
let results = Assert.NotNull test
Check.Quick results
@ -49,7 +49,7 @@
let ``Using console-waterworks-announcement does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences ConsoleWaterworks
let test = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences ConsoleWaterworks
let results = Assert.NotNull test
Check.Quick results
@ -57,7 +57,7 @@
let ``Using word-generator does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences WordGenerator
let test = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences WordGenerator
let results = Assert.NotNull test
Check.Quick results
@ -65,7 +65,7 @@
let ``Using test-post does not return null`` () =
let gibberishLevel = System.Random().Next(2, 10)
let totalSentences = System.Random().Next(2, 10)
let test = Pancake.RequestTextFromFile gibberishLevel totalSentences TestPost
let test = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences TestPost
let results = Assert.NotNull test
Check.Quick results
@ -73,6 +73,6 @@
[<Property>]
let ``RequestRandomText produces content with at least one full stop`` () =
let test = Pancake.RequestRandomText() |> Async.RunSynchronously
let test = Pancake.RequestRandomTextAsync() |> Async.RunSynchronously
let results = Assert.Contains(".", test)
Check.Quick results

14
TestCentre/UnitTests.fs

@ -34,46 +34,46 @@
module ``Null Tests`` =
[<Fact>]
let ``RequestRandomText does not return a null`` () =
let result = Pancake.RequestRandomText ()
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.RequestText gibberishLevel totalSentences
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.RequestTextFromFile gibberishLevel totalSentences DesktopClock
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.RequestTextFromFile gibberishLevel totalSentences ConsoleWaterworks
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.RequestTextFromFile gibberishLevel totalSentences WordGenerator
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)
let totalSentences = System.Random().Next(2, 20)
let result = Pancake.RequestTextFromFile gibberishLevel totalSentences TestPost
let result = Pancake.RequestTextFromFileAsync gibberishLevel totalSentences TestPost
Assert.NotNull result
module ``Contents Tests`` =
[<Fact>]
let ``RequestRandomText returns a string which contains at least one full stop`` () =
let result = Pancake.RequestRandomText () |> Async.RunSynchronously
let result = Pancake.RequestRandomTextAsync () |> Async.RunSynchronously
Assert.Contains(".", result)

6
WetPancake/ProductServices.fs

@ -8,7 +8,7 @@ module Pancake =
open DataStructuring
open DataServices
let RequestRandomText() =
let RequestRandomTextAsync() =
async {
let data =
LoadFile (SelectRandomSampleFile())
@ -18,7 +18,7 @@ module Pancake =
return GenerateMarkovText (PickRandomNumber 2 10) data
}
let RequestText (gibberishLevel: int) (sentences: int) =
let RequestTextAsync (gibberishLevel: int) (sentences: int) =
async {
let data =
LoadFile (SelectRandomSampleFile())
@ -28,7 +28,7 @@ module Pancake =
return GenerateMarkovText sentences data
}
let RequestTextFromFile (gibberishLevel: int) (sentences: int) (filePath: string) =
let RequestTextFromFileAsync (gibberishLevel: int) (sentences: int) (filePath: string) =
async {
let data =
LoadFile filePath

12
WetPancake/Script.fsx

@ -131,12 +131,12 @@ let WordGenerator = __SOURCE_DIRECTORY__ + @"\TextFiles\word-generator.txt"
[<Literal>]
let TestPost = __SOURCE_DIRECTORY__ + @"\TextFiles\test-post.txt"
let p_result = Pancake.RequestRandomText()
let p_result2 = Pancake.RequestText 5 10
let p_result3 = Pancake.RequestTextFromFile 3 10 DesktopClock
let p_result4 = Pancake.RequestTextFromFile 3 10 ConsoleWaterworks
let p_result5 = Pancake.RequestTextFromFile 3 10 WordGenerator
let p_result6 = Pancake.RequestTextFromFile 3 10 TestPost
let p_result = Pancake.RequestRandomTextAsync()
let p_result2 = Pancake.RequestTextAsync 5 10
let p_result3 = Pancake.RequestTextFromFileAsync 3 10 DesktopClock
let p_result4 = Pancake.RequestTextFromFileAsync 3 10 ConsoleWaterworks
let p_result5 = Pancake.RequestTextFromFileAsync 3 10 WordGenerator
let p_result6 = Pancake.RequestTextFromFileAsync 3 10 TestPost
p_result |> Async.RunSynchronously
p_result2 |> Async.RunSynchronously

12
WetPancakeCLI/ConsoleCommands.cs

@ -43,12 +43,12 @@ namespace WetPancakeCLI
public static string GenerateRandomText()
{
string result = String.Empty;
try { return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result; }
try { return FSharpAsync.StartAsTask(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result; }
catch (Exception e)
{
Debug.WriteLine(e.Message);
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command...");
return FSharpAsync.StartAsTask(RequestRandomText(), _taskCreationOptions, _cancellationToken).Result;
return FSharpAsync.StartAsTask(RequestRandomTextAsync(), _taskCreationOptions, _cancellationToken).Result;
}
}
@ -59,12 +59,12 @@ namespace WetPancakeCLI
public static string GenerateText(int gibberishLevel, int sentences)
{
if (gibberishLevel < 2) return "Please enter a gibberish level greater than 1.";
try { return FSharpAsync.StartAsTask(RequestText(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result; }
try { return FSharpAsync.StartAsTask(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result; }
catch (Exception e)
{
Debug.WriteLine(e.Message);
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command...");
return FSharpAsync.StartAsTask(RequestText(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
return FSharpAsync.StartAsTask(RequestTextAsync(gibberishLevel, sentences), _taskCreationOptions, _cancellationToken).Result;
}
}
@ -78,12 +78,12 @@ namespace WetPancakeCLI
// Could do with checking if the file type is .txt...
if (gibberishLevel < 2) return "Please enter a gibberish level greater than 1.";
try
{ return FSharpAsync.StartAsTask(RequestTextFromFile(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result; }
{ return FSharpAsync.StartAsTask(RequestTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result; }
catch (Exception e)
{
Debug.WriteLine(e.Message);
System.Console.WriteLine("[ERROR] Unable to complete request. Re-executing command...");
return FSharpAsync.StartAsTask(RequestTextFromFile(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result;
return FSharpAsync.StartAsTask(RequestTextFromFileAsync(gibberishLevel, sentences, filePath), _taskCreationOptions, _cancellationToken).Result;
}
}
}

Loading…
Cancel
Save