Skip to content

Commit

Permalink
#106 Add Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusMeyer13 committed Mar 5, 2020
1 parent df946d6 commit 9bae6e3
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 24 deletions.
97 changes: 97 additions & 0 deletions PlanB.Butler.Bot.Test/NextOrderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using BotLibraryV2;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlanB.Butler.Bot.Dialogs;
using System;

namespace PlanB.Butler.Bot.Test
{
/// <summary>
/// NextOrderTest.
/// </summary>
[TestClass]
public class NextOrderTest
{
/// <summary>
/// The plan
/// </summary>
private Plan plan;
private PlanDay planDay;
private PlanDayMeal planDayMealLinsen;


/// <summary>
/// Initialize each test.
/// </summary>
[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<PlanDayMeal>();
this.planDay.Meal1.Add(this.planDayMealLinsen);
this.plan.Planday = new System.Collections.Generic.List<PlanDay>
{
this.planDay,
};
}

/// <summary>
/// Plans the null identifier empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public void PlanNullIdentifierEmpty()
{
var result = NextOrder.GetChoice(string.Empty, this.plan);
Assert.IsNotNull(result);
}

/// <summary>
/// Plans the empty identifier empty.
/// </summary>
[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public void PlanEmptyIdentifierEmpty()
{
this.plan = new Plan();
var result = NextOrder.GetChoice(string.Empty, this.plan);
Assert.IsNotNull(result);
}

/// <summary>
/// Plans the only name identifier empty.
/// </summary>
[TestMethod]
public void PlanOnlyNameIdentifierEmpty()
{
this.plan = new Plan();
var planDay = new PlanDay() { Name = "Day1" };
this.plan.Planday = new System.Collections.Generic.List<PlanDay>
{
planDay,
};

var result = NextOrder.GetChoice(string.Empty, this.plan);
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}


/// <summary>
/// Plans the one meal identifier empty.
/// </summary>
[TestMethod]
public void PlanOneMealIdentifierEmpty()
{
var result = NextOrder.GetChoice(string.Empty, this.plan);
Assert.IsNotNull(result);
Assert.AreEqual(0, result.Count);
}
}
}
42 changes: 42 additions & 0 deletions PlanB.Butler.Bot.Test/PlanB.Butler.Bot.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
<Company>PlanB. GmbH</Company>
<Product>PlanB Butler Bot</Product>
<Authors>PlanB. GmbH</Authors>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<CodeAnalysisRuleSet />
<OutputPath>bin\Release\netcoreapp2.2\</OutputPath>
<DocumentationFile>bin\Release\netcoreapp2.2\PlanB.Butler.Bot.Test.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<CodeAnalysisRuleSet />
<OutputPath>bin\Debug\netcoreapp2.2\</OutputPath>
<DocumentationFile>bin\Debug\netcoreapp2.2\PlanB.Butler.Bot.Test.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Remove="StyleCop.Analyzers.ruleset" />
<None Remove="stylecop.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="StyleCop.Analyzers.ruleset" />
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlanB.Butler.Bot\PlanB.Butler.Bot.csproj" />
</ItemGroup>

</Project>
103 changes: 103 additions & 0 deletions PlanB.Butler.Bot.Test/StyleCop.Analyzers.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for StyleCop.Analyzers" Description="Code analysis rules for StyleCop.Analyzers.csproj." ToolsVersion="14.0">
<Rules AnalyzerId="AsyncUsageAnalyzers" RuleNamespace="AsyncUsageAnalyzers">
<Rule Id="UseConfigureAwait" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
<Rule Id="CA1016" Action="Warning" />
<Rule Id="CA1033" Action="Warning" />
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
<Rule Id="CA1404" Action="Warning" />
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />
<Rule Id="CA2002" Action="Warning" />
<Rule Id="CA2100" Action="Warning" />
<Rule Id="CA2101" Action="Warning" />
<Rule Id="CA2108" Action="Warning" />
<Rule Id="CA2111" Action="Warning" />
<Rule Id="CA2112" Action="Warning" />
<Rule Id="CA2114" Action="Warning" />
<Rule Id="CA2116" Action="Warning" />
<Rule Id="CA2117" Action="Warning" />
<Rule Id="CA2122" Action="Warning" />
<Rule Id="CA2123" Action="Warning" />
<Rule Id="CA2124" Action="Warning" />
<Rule Id="CA2126" Action="Warning" />
<Rule Id="CA2131" Action="Warning" />
<Rule Id="CA2132" Action="Warning" />
<Rule Id="CA2133" Action="Warning" />
<Rule Id="CA2134" Action="Warning" />
<Rule Id="CA2137" Action="Warning" />
<Rule Id="CA2138" Action="Warning" />
<Rule Id="CA2140" Action="Warning" />
<Rule Id="CA2141" Action="Warning" />
<Rule Id="CA2146" Action="Warning" />
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2200" Action="Warning" />
<Rule Id="CA2202" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2220" Action="Warning" />
<Rule Id="CA2229" Action="Warning" />
<Rule Id="CA2231" Action="Warning" />
<Rule Id="CA2232" Action="Warning" />
<Rule Id="CA2235" Action="Warning" />
<Rule Id="CA2236" Action="Warning" />
<Rule Id="CA2237" Action="Warning" />
<Rule Id="CA2238" Action="Warning" />
<Rule Id="CA2240" Action="Warning" />
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Analyzers" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Analyzers">
<Rule Id="RS1022" Action="None" />
<!-- https://github.com/dotnet/roslyn-analyzers/issues/1803 -->
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.CodeStyle" RuleNamespace="Microsoft.CodeAnalysis.CSharp.CodeStyle">
<Rule Id="IDE0055" Action="Warning" />
</Rules>
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
<Rule Id="IDE0003" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1305" Action="Warning" />
<Rule Id="SA1412" Action="Warning" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1609" Action="Warning" />
</Rules>
<Rules AnalyzerId="DocumentationAnalyzers" RuleNamespace="DocumentationAnalyzers">
<Rule Id="DOC100" Action="Warning" />
<Rule Id="DOC101" Action="Warning" />
<Rule Id="DOC102" Action="Warning" />
<Rule Id="DOC103" Action="Warning" />
<Rule Id="DOC104" Action="Warning" />
<Rule Id="DOC105" Action="Warning" />
<Rule Id="DOC106" Action="Warning" />
<Rule Id="DOC107" Action="Warning" />
<Rule Id="DOC108" Action="Warning" />
<Rule Id="DOC200" Action="Warning" />
<Rule Id="DOC201" Action="Warning" />
<Rule Id="DOC202" Action="Warning" />
<Rule Id="DOC203" Action="Warning" />
<Rule Id="DOC204" Action="Warning" />
</Rules>
</RuleSet>
43 changes: 43 additions & 0 deletions PlanB.Butler.Bot.Test/stylecop.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
2 changes: 1 addition & 1 deletion PlanB.Butler.Bot/Dialogs/NextOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ private async Task<DialogTurnResult> SummaryStepAsync(WaterfallStepContext stepC
/// <param name="identifier">The identifier is used to define what choises you want</param>
/// <param name="plan">The plan Object</param>
/// <returns>Returnds the specified choises</returns>
private static IList<Choice> GetChoice(string identifier, Plan plan)
internal static IList<Choice> GetChoice(string identifier, Plan plan)
{
List<string> choice = new List<string>();
var day = plan.Planday[dayId];
Expand Down
15 changes: 4 additions & 11 deletions PlanB.Butler.Bot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +18,8 @@
using Microsoft.Extensions.Options;
using PlanB.Butler.Bot.Dialogs;

[assembly: InternalsVisibleTo("PlanB.Butler.Bot.Test")]

namespace PlanB.Butler.Bot
{
/// <summary>
Expand All @@ -35,8 +32,6 @@ public class Startup
/// </summary>
private readonly IConfiguration configuration;



/// <summary>
/// Initializes a new instance of the <see cref="Startup"/> class.
/// </summary>
Expand All @@ -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<PlanB.Butler.Bot.Services.IMealService, PlanB.Butler.Bot.Services.MealService>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5));


// Create the Bot Framework Adapter with error handling enabled.
services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

Expand Down
15 changes: 3 additions & 12 deletions PlanB.Butler.Library/PlanB.Butler.Library/BotModels/Plan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -30,12 +21,12 @@ public class PlanDay
[Obsolete("Replace Restaurant1 with List<Restaurant>")]
public string Restaurant1 { get; set; }

public List<Meal1> Meal1 { get; set; }
public List<PlanDayMeal> Meal1 { get; set; }

[Obsolete("Replace Restaurant2 with List<Restaurant>")]
public string Restaurant2 { get; set; }

public List<Meal2> Meal2 { get; set; }
public List<PlanDayMeal> Meal2 { get; set; }
}

public class Plan
Expand Down
Loading

0 comments on commit 9bae6e3

Please sign in to comment.