feat: add a couple unit tests to L3.LD_24
This commit is contained in:
parent
8371ae885b
commit
4354e33d59
10
L3/L3.sln
10
L3/L3.sln
@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.1525
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LD_24", "LD_24\LD_24.csproj", "{AE159626-A105-440C-B997-F377C5F8F280}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LD_24Tests", "LD_24Tests\LD_24Tests.csproj", "{39E0FA27-E323-45EE-BA1B-5DDFE00A7C03}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{AE159626-A105-440C-B997-F377C5F8F280}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AE159626-A105-440C-B997-F377C5F8F280}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AE159626-A105-440C-B997-F377C5F8F280}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{39E0FA27-E323-45EE-BA1B-5DDFE00A7C03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{39E0FA27-E323-45EE-BA1B-5DDFE00A7C03}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{39E0FA27-E323-45EE-BA1B-5DDFE00A7C03}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{39E0FA27-E323-45EE-BA1B-5DDFE00A7C03}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,5 +1,4 @@
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" />
|
||||
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
@ -44,9 +43,6 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentAssertions, Version=6.5.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.6.5.1\lib\netstandard2.0\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
@ -70,18 +66,6 @@
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Web.Services" />
|
||||
<Reference Include="System.EnterpriseServices" />
|
||||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.abstractions.2.0.3\lib\net35\xunit.abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.assert, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.assert.2.4.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.core, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.core.2.4.1\lib\net452\xunit.core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit.execution.desktop, Version=2.4.1.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\xunit.extensibility.execution.2.4.1\lib\net452\xunit.execution.desktop.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
|
||||
@ -131,9 +115,6 @@
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
@ -164,10 +145,7 @@
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
|
||||
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.props'))" />
|
||||
<Error Condition="!Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\xunit.core.2.4.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.1\build\xunit.core.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
30
L3/LD_24Tests/LD_24Tests.csproj
Normal file
30
L3/LD_24Tests/LD_24Tests.csproj
Normal file
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bogus" Version="34.0.1" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.5.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
|
||||
<PackageReference Include="xunit.analyzers" Version="0.10.0" />
|
||||
<PackageReference Include="xunit.core" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.extensibility.core" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LD_24\LD_24.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
73
L3/LD_24Tests/LinkedListTests.cs
Normal file
73
L3/LD_24Tests/LinkedListTests.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
using LD_24.Code;
|
||||
using System.Collections;
|
||||
|
||||
namespace LD_24Tests
|
||||
{
|
||||
public abstract class LinkedListTests<T>
|
||||
where T : IComparable<T>, IEquatable<T>
|
||||
{
|
||||
protected abstract LinkedList<T> CreateNewList();
|
||||
protected abstract T CreateItem();
|
||||
|
||||
[Fact]
|
||||
public void New_List_Is_Empty()
|
||||
{
|
||||
LinkedList<T> list = CreateNewList();
|
||||
|
||||
list.IsEmpty().Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Assert_List_Is_Not_Empty()
|
||||
{
|
||||
LinkedList<T> list = CreateNewList();
|
||||
|
||||
list.Add(CreateItem());
|
||||
|
||||
list.IsEmpty().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
[InlineData(5)]
|
||||
public void Retrieve_How_Many_Were_Added(int count)
|
||||
{
|
||||
LinkedList<T> list = CreateNewList();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
list.Add(CreateItem());
|
||||
}
|
||||
|
||||
list.Count().Should().Be(count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IEnumerable_Is_Implemented_Correctly()
|
||||
{
|
||||
LinkedList<T> list = CreateNewList();
|
||||
|
||||
var item1 = CreateItem();
|
||||
var item2 = CreateItem();
|
||||
var item3 = CreateItem();
|
||||
|
||||
list.Add(item1);
|
||||
list.Add(item2);
|
||||
list.Add(item3);
|
||||
|
||||
var newList = new System.Collections.Generic.List<T>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
newList.Add(item);
|
||||
}
|
||||
|
||||
newList[0].Should().Be(item1);
|
||||
newList[1].Should().Be(item2);
|
||||
newList[2].Should().Be(item3);
|
||||
}
|
||||
}
|
||||
}
|
22
L3/LD_24Tests/OrderLinkedListTests.cs
Normal file
22
L3/LD_24Tests/OrderLinkedListTests.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Bogus;
|
||||
using LD_24.Code;
|
||||
|
||||
namespace LD_24Tests
|
||||
{
|
||||
public class OrderLinkedListTests : LinkedListTests<Order>
|
||||
{
|
||||
private Faker faker = new Faker("en");
|
||||
|
||||
protected override LinkedList<Order> CreateNewList() => new LinkedList<Order>();
|
||||
protected override Order CreateItem()
|
||||
{
|
||||
string customerSurname = faker.Name.FindName();
|
||||
string customerName = faker.Name.LastName();
|
||||
string productID = faker.Random.AlphaNumeric(5);
|
||||
int productAmount = faker.Random.Number(1, 100);
|
||||
return new Order(customerSurname, customerName, productID, productAmount);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user