Skip to content

Commit bbcd813

Browse files
Sergio FerreiraSergio Ferreira
Sergio Ferreira
authored and
Sergio Ferreira
committed
added some integration tests to allow refactoring with some safety
1 parent 72db5f4 commit bbcd813

File tree

7 files changed

+173
-8
lines changed

7 files changed

+173
-8
lines changed

SOLID/01 - Introduction/Liquid/Liquid.Tests/FL_insurance_sample.csv

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props')" />
4+
<Import Project="..\packages\xunit.core.2.4.0\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.4.0\build\xunit.core.props')" />
5+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
6+
<PropertyGroup>
7+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9+
<ProjectGuid>{02779269-0B73-499C-9BC1-4F7B6ADCFF72}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>Liquid.Tests</RootNamespace>
13+
<AssemblyName>Liquid.Tests</AssemblyName>
14+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
17+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
18+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
19+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
20+
<IsCodedUITest>False</IsCodedUITest>
21+
<TestProjectType>UnitTest</TestProjectType>
22+
<NuGetPackageImportStamp>
23+
</NuGetPackageImportStamp>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
26+
<DebugSymbols>true</DebugSymbols>
27+
<DebugType>full</DebugType>
28+
<Optimize>false</Optimize>
29+
<OutputPath>bin\Debug\</OutputPath>
30+
<DefineConstants>DEBUG;TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
35+
<DebugType>pdbonly</DebugType>
36+
<Optimize>true</Optimize>
37+
<OutputPath>bin\Release\</OutputPath>
38+
<DefineConstants>TRACE</DefineConstants>
39+
<ErrorReport>prompt</ErrorReport>
40+
<WarningLevel>4</WarningLevel>
41+
</PropertyGroup>
42+
<ItemGroup>
43+
<Reference Include="System" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
46+
<HintPath>..\packages\xunit.abstractions.2.0.2\lib\net35\xunit.abstractions.dll</HintPath>
47+
</Reference>
48+
<Reference Include="xunit.assert, Version=2.4.0.4049, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
49+
<HintPath>..\packages\xunit.assert.2.4.0\lib\netstandard2.0\xunit.assert.dll</HintPath>
50+
</Reference>
51+
<Reference Include="xunit.core, Version=2.4.0.4049, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
52+
<HintPath>..\packages\xunit.extensibility.core.2.4.0\lib\net452\xunit.core.dll</HintPath>
53+
</Reference>
54+
<Reference Include="xunit.execution.desktop, Version=2.4.0.4049, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
55+
<HintPath>..\packages\xunit.extensibility.execution.2.4.0\lib\net452\xunit.execution.desktop.dll</HintPath>
56+
</Reference>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Compile Include="UnitTest1.cs" />
60+
<Compile Include="Properties\AssemblyInfo.cs" />
61+
</ItemGroup>
62+
<ItemGroup>
63+
<ProjectReference Include="..\Liquid\Liquid.csproj">
64+
<Project>{143e7698-a6e9-4283-9c8d-87ba46a596cc}</Project>
65+
<Name>Liquid</Name>
66+
</ProjectReference>
67+
</ItemGroup>
68+
<ItemGroup>
69+
<None Include="FL_insurance_sample.csv">
70+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
71+
</None>
72+
<None Include="packages.config" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<Analyzer Include="..\packages\xunit.analyzers.0.10.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
76+
</ItemGroup>
77+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
78+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
79+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
80+
<PropertyGroup>
81+
<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>
82+
</PropertyGroup>
83+
<Error Condition="!Exists('..\packages\xunit.core.2.4.0\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.0\build\xunit.core.props'))" />
84+
<Error Condition="!Exists('..\packages\xunit.core.2.4.0\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.4.0\build\xunit.core.targets'))" />
85+
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.4.0\build\net20\xunit.runner.visualstudio.props'))" />
86+
</Target>
87+
<Import Project="..\packages\xunit.core.2.4.0\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.4.0\build\xunit.core.targets')" />
88+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
[assembly: AssemblyTitle("Liquid.Tests")]
6+
[assembly: AssemblyDescription("")]
7+
[assembly: AssemblyConfiguration("")]
8+
[assembly: AssemblyCompany("")]
9+
[assembly: AssemblyProduct("Liquid.Tests")]
10+
[assembly: AssemblyCopyright("Copyright © 2018")]
11+
[assembly: AssemblyTrademark("")]
12+
[assembly: AssemblyCulture("")]
13+
14+
[assembly: ComVisible(false)]
15+
16+
[assembly: Guid("02779269-0b73-499c-9bc1-4f7b6adcff72")]
17+
18+
// [assembly: AssemblyVersion("1.0.*")]
19+
[assembly: AssemblyVersion("1.0.0.0")]
20+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.IO;
2+
using Xunit;
3+
4+
namespace Liquid.Tests
5+
{
6+
public class UnitTest1
7+
{
8+
[Fact]
9+
public void Test_program_for_client_1()
10+
{
11+
// Arrange
12+
var client = 1;
13+
14+
// Act
15+
Program.Main(new [] { client.ToString() });
16+
17+
// Assert
18+
Assert.True(File.Exists(".\\MyOutput1.csv"));
19+
var readAllLines = File.ReadAllLines(".\\MyOutput1.csv");
20+
21+
Assert.Equal("12094958399.10,10/04/2018", readAllLines[readAllLines.Length-1]);
22+
}
23+
24+
[Fact]
25+
public void Test_program_for_client_2()
26+
{
27+
// Arrange
28+
var client = 2;
29+
30+
// Act
31+
Program.Main(new [] { client.ToString() });
32+
33+
// Assert
34+
Assert.True(File.Exists(".\\MyOutput2.csv"));
35+
var readAllLines = File.ReadAllLines(".\\MyOutput2.csv");
36+
37+
Assert.Equal("82091205702.93,10/04/2018", readAllLines[readAllLines.Length-1]);
38+
}
39+
}
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="xunit" version="2.4.0" targetFramework="net462" />
4+
<package id="xunit.abstractions" version="2.0.2" targetFramework="net462" />
5+
<package id="xunit.analyzers" version="0.10.0" targetFramework="net462" />
6+
<package id="xunit.assert" version="2.4.0" targetFramework="net462" />
7+
<package id="xunit.core" version="2.4.0" targetFramework="net462" />
8+
<package id="xunit.extensibility.core" version="2.4.0" targetFramework="net462" />
9+
<package id="xunit.extensibility.execution" version="2.4.0" targetFramework="net462" />
10+
<package id="xunit.runner.visualstudio" version="2.4.0" targetFramework="net462" developmentDependency="true" />
11+
</packages>

SOLID/01 - Introduction/Liquid/Liquid.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28010.2016
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Liquid", "Liquid\Liquid.csproj", "{143E7698-A6E9-4283-9C8D-87BA46A596CC}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Liquid.Tests", "Liquid.Tests\Liquid.Tests.csproj", "{02779269-0B73-499C-9BC1-4F7B6ADCFF72}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{143E7698-A6E9-4283-9C8D-87BA46A596CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{143E7698-A6E9-4283-9C8D-87BA46A596CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{143E7698-A6E9-4283-9C8D-87BA46A596CC}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{02779269-0B73-499C-9BC1-4F7B6ADCFF72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{02779269-0B73-499C-9BC1-4F7B6ADCFF72}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{02779269-0B73-499C-9BC1-4F7B6ADCFF72}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{02779269-0B73-499C-9BC1-4F7B6ADCFF72}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

SOLID/01 - Introduction/Liquid/Liquid/Program.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Globalization;
43
using System.IO;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
84

95
namespace Liquid
106
{
@@ -15,13 +11,16 @@ namespace Liquid
1511
// -----
1612
// Client 1: Ignore Residential type of housing.
1713
// Client 2: Ignore Commercial type of housing.
18-
class Program
14+
public class Program
1915
{
20-
static void Main(string[] args)
16+
public static void Main(string[] args)
2117
{
22-
var client = 2;
18+
var client = -1;
19+
20+
int.TryParse(args[0], out client);
21+
2322
var fileLines = File.ReadAllLines(".\\FL_insurance_sample.csv");
24-
var output = new StreamWriter(File.OpenWrite("MyOutput.csv"));
23+
var output = new StreamWriter(File.OpenWrite($".\\MyOutput{client}.csv"));
2524
output.WriteLine($"Country,Value");
2625
var total = 0.0;
2726
for (var i = 1; i < fileLines.Length; i++)

0 commit comments

Comments
 (0)