From 9bae6e37043716d374523755cae5aea47eb4922e Mon Sep 17 00:00:00 2001 From: Markus Meyer Date: Thu, 5 Mar 2020 09:29:26 +0100 Subject: [PATCH] #106 Add Tests --- PlanB.Butler.Bot.Test/NextOrderTest.cs | 97 +++++++++++++++++ .../PlanB.Butler.Bot.Test.csproj | 42 +++++++ .../StyleCop.Analyzers.ruleset | 103 ++++++++++++++++++ PlanB.Butler.Bot.Test/stylecop.json | 43 ++++++++ PlanB.Butler.Bot/Dialogs/NextOrder.cs | 2 +- PlanB.Butler.Bot/Startup.cs | 15 +-- .../PlanB.Butler.Library/BotModels/Plan.cs | 15 +-- PlanB.Butler.sln | 6 + 8 files changed, 299 insertions(+), 24 deletions(-) create mode 100644 PlanB.Butler.Bot.Test/NextOrderTest.cs create mode 100644 PlanB.Butler.Bot.Test/PlanB.Butler.Bot.Test.csproj create mode 100644 PlanB.Butler.Bot.Test/StyleCop.Analyzers.ruleset create mode 100644 PlanB.Butler.Bot.Test/stylecop.json diff --git a/PlanB.Butler.Bot.Test/NextOrderTest.cs b/PlanB.Butler.Bot.Test/NextOrderTest.cs new file mode 100644 index 0000000..efd3435 --- /dev/null +++ b/PlanB.Butler.Bot.Test/NextOrderTest.cs @@ -0,0 +1,97 @@ +using BotLibraryV2; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using PlanB.Butler.Bot.Dialogs; +using System; + +namespace PlanB.Butler.Bot.Test +{ + /// + /// NextOrderTest. + /// + [TestClass] + public class NextOrderTest + { + /// + /// The plan + /// + private Plan plan; + private PlanDay planDay; + private PlanDayMeal planDayMealLinsen; + + + /// + /// Initialize each test. + /// + [TestInitialize] + public void Init() + { + this.plan = new Plan(); + this.planDay = new PlanDay() { Name = "Day1" }; + this.planDayMealLinsen = new PlanDayMeal() + { + Name = "Linsen", + Price = 2.3, + Restaurant = "LinsenWirt", + }; + this.planDay.Meal1 = new System.Collections.Generic.List(); + this.planDay.Meal1.Add(this.planDayMealLinsen); + this.plan.Planday = new System.Collections.Generic.List + { + this.planDay, + }; + } + + /// + /// Plans the null identifier empty. + /// + [TestMethod] + [ExpectedException(typeof(NullReferenceException))] + public void PlanNullIdentifierEmpty() + { + var result = NextOrder.GetChoice(string.Empty, this.plan); + Assert.IsNotNull(result); + } + + /// + /// Plans the empty identifier empty. + /// + [TestMethod] + [ExpectedException(typeof(NullReferenceException))] + public void PlanEmptyIdentifierEmpty() + { + this.plan = new Plan(); + var result = NextOrder.GetChoice(string.Empty, this.plan); + Assert.IsNotNull(result); + } + + /// + /// Plans the only name identifier empty. + /// + [TestMethod] + public void PlanOnlyNameIdentifierEmpty() + { + this.plan = new Plan(); + var planDay = new PlanDay() { Name = "Day1" }; + this.plan.Planday = new System.Collections.Generic.List + { + planDay, + }; + + var result = NextOrder.GetChoice(string.Empty, this.plan); + Assert.IsNotNull(result); + Assert.AreEqual(0, result.Count); + } + + + /// + /// Plans the one meal identifier empty. + /// + [TestMethod] + public void PlanOneMealIdentifierEmpty() + { + var result = NextOrder.GetChoice(string.Empty, this.plan); + Assert.IsNotNull(result); + Assert.AreEqual(0, result.Count); + } + } +} diff --git a/PlanB.Butler.Bot.Test/PlanB.Butler.Bot.Test.csproj b/PlanB.Butler.Bot.Test/PlanB.Butler.Bot.Test.csproj new file mode 100644 index 0000000..f973966 --- /dev/null +++ b/PlanB.Butler.Bot.Test/PlanB.Butler.Bot.Test.csproj @@ -0,0 +1,42 @@ + + + netcoreapp2.2 + latest + PlanB. GmbH + PlanB Butler Bot + PlanB. GmbH + false + + + + bin\Release\netcoreapp2.2\ + bin\Release\netcoreapp2.2\PlanB.Butler.Bot.Test.xml + + + + bin\Debug\netcoreapp2.2\ + bin\Debug\netcoreapp2.2\PlanB.Butler.Bot.Test.xml + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + diff --git a/PlanB.Butler.Bot.Test/StyleCop.Analyzers.ruleset b/PlanB.Butler.Bot.Test/StyleCop.Analyzers.ruleset new file mode 100644 index 0000000..d3131ca --- /dev/null +++ b/PlanB.Butler.Bot.Test/StyleCop.Analyzers.ruleset @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PlanB.Butler.Bot.Test/stylecop.json b/PlanB.Butler.Bot.Test/stylecop.json new file mode 100644 index 0000000..d27d1fc --- /dev/null +++ b/PlanB.Butler.Bot.Test/stylecop.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "indentation": { + "indentationSize": 4, + "tabSize": 4, + "useTabs": false + }, + "spacingRules": { + }, + "readabilityRules": { + }, + "orderingRules": { + "elementOrder": [ "kind", "accessibility", "constant", "static", "readonly" ], + "systemUsingDirectivesFirst": true, + "usingDirectivesPlacement": "outsideNamespace", + "blankLinesBetweenUsingGroups": "require" + }, + "namingRules": { + "allowCommonHungarianPrefixes": true, + "allowedHungarianPrefixes": [] + }, + "maintainabilityRules": { + "topLevelTypes": [ "class", "delegate", "enum", "interface", "struct" ] + }, + "layoutRules": { + "newlineAtEndOfFile": "allow", + "allowConsecutiveUsings": false + }, + "documentationRules": { + "companyName": "PlanB. GmbH", + "copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\r\nLicensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.", + "xmlHeader": false, + "fileNamingConvention": "metadata", + "documentInterfaces": true, + "documentExposedElements": true, + "documentInternalElements": true, + "documentPrivateElements": true, + "documentPrivateFields": true, + "documentationCulture": "en-US" + } + } +} \ No newline at end of file diff --git a/PlanB.Butler.Bot/Dialogs/NextOrder.cs b/PlanB.Butler.Bot/Dialogs/NextOrder.cs index a10f54c..d84cb0d 100644 --- a/PlanB.Butler.Bot/Dialogs/NextOrder.cs +++ b/PlanB.Butler.Bot/Dialogs/NextOrder.cs @@ -631,7 +631,7 @@ private async Task SummaryStepAsync(WaterfallStepContext stepC /// The identifier is used to define what choises you want /// The plan Object /// Returnds the specified choises - private static IList GetChoice(string identifier, Plan plan) + internal static IList GetChoice(string identifier, Plan plan) { List choice = new List(); var day = plan.Planday[dayId]; diff --git a/PlanB.Butler.Bot/Startup.cs b/PlanB.Butler.Bot/Startup.cs index 4f35afd..4c87033 100644 --- a/PlanB.Butler.Bot/Startup.cs +++ b/PlanB.Butler.Bot/Startup.cs @@ -2,18 +2,13 @@ // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; +using System.Runtime.CompilerServices; using Microsoft.ApplicationInsights.Extensibility; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Localization; -using Microsoft.AspNetCore.Localization.Routing; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.ApplicationInsights; using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core; @@ -23,6 +18,8 @@ using Microsoft.Extensions.Options; using PlanB.Butler.Bot.Dialogs; +[assembly: InternalsVisibleTo("PlanB.Butler.Bot.Test")] + namespace PlanB.Butler.Bot { /// @@ -35,8 +32,6 @@ public class Startup /// private readonly IConfiguration configuration; - - /// /// Initializes a new instance of the class. /// @@ -57,13 +52,11 @@ public void ConfigureServices(IServiceCollection services) services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); - // The Bot needs an HttpClient to download and upload files. - //services.AddHttpClient(); + // services.AddHttpClient(); services.AddHttpClient() .SetHandlerLifetime(TimeSpan.FromMinutes(5)); - // Create the Bot Framework Adapter with error handling enabled. services.AddSingleton(); diff --git a/PlanB.Butler.Library/PlanB.Butler.Library/BotModels/Plan.cs b/PlanB.Butler.Library/PlanB.Butler.Library/BotModels/Plan.cs index ac3d3b9..7309dcb 100644 --- a/PlanB.Butler.Library/PlanB.Butler.Library/BotModels/Plan.cs +++ b/PlanB.Butler.Library/PlanB.Butler.Library/BotModels/Plan.cs @@ -5,16 +5,7 @@ using System.Linq; using System.Threading.Tasks; - public class Meal1 - { - public string Restaurant { get; set; } - - public string Name { get; set; } - - public double Price { get; set; } - } - - public class Meal2 + public class PlanDayMeal { public string Restaurant { get; set; } @@ -30,12 +21,12 @@ public class PlanDay [Obsolete("Replace Restaurant1 with List")] public string Restaurant1 { get; set; } - public List Meal1 { get; set; } + public List Meal1 { get; set; } [Obsolete("Replace Restaurant2 with List")] public string Restaurant2 { get; set; } - public List Meal2 { get; set; } + public List Meal2 { get; set; } } public class Plan diff --git a/PlanB.Butler.sln b/PlanB.Butler.sln index 40cad57..3fbc8ae 100644 --- a/PlanB.Butler.sln +++ b/PlanB.Butler.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanB.Butler.Services", "Pl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlanB.Butler.Services.Test", "PlanB.Butler.Services\PlanB.Butler.Services.Test\PlanB.Butler.Services.Test.csproj", "{5DC67115-3051-44E2-A69F-C9694D2BDD0D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlanB.Butler.Bot.Test", "PlanB.Butler.Bot.Test\PlanB.Butler.Bot.Test.csproj", "{C2C38FE1-E107-4694-91AE-69E951979E96}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {5DC67115-3051-44E2-A69F-C9694D2BDD0D}.Debug|Any CPU.Build.0 = Debug|Any CPU {5DC67115-3051-44E2-A69F-C9694D2BDD0D}.Release|Any CPU.ActiveCfg = Release|Any CPU {5DC67115-3051-44E2-A69F-C9694D2BDD0D}.Release|Any CPU.Build.0 = Release|Any CPU + {C2C38FE1-E107-4694-91AE-69E951979E96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2C38FE1-E107-4694-91AE-69E951979E96}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2C38FE1-E107-4694-91AE-69E951979E96}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2C38FE1-E107-4694-91AE-69E951979E96}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE