Skip to content
Permalink
Browse files

重構 STEP1 Customer.statement Test Cover 100%

  • Loading branch information...
marsen committed Feb 28, 2019
1 parent 6e600db commit d8d6f463960572af6ffdb3a5612fd00623d0d7e2
@@ -3,18 +3,24 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marsen.NetCore.Dojo", "Marsen.NetCore.Dojo\Marsen.NetCore.Dojo.csproj", "{C9188843-172B-45F7-86CE-3454F9881F62}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Marsen.NetCore.Dojo", "src\Marsen.NetCore.Dojo\Marsen.NetCore.Dojo.csproj", "{FAC1D502-6D14-42E1-AFDF-26BB516E49C6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marsen.NetCore.Dojo.Tests", "test\Marsen.NetCore.Dojo.Tests\Marsen.NetCore.Dojo.Tests.csproj", "{AF335305-DF99-4423-9A05-E809EEE173A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C9188843-172B-45F7-86CE-3454F9881F62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9188843-172B-45F7-86CE-3454F9881F62}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9188843-172B-45F7-86CE-3454F9881F62}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9188843-172B-45F7-86CE-3454F9881F62}.Release|Any CPU.Build.0 = Release|Any CPU
{FAC1D502-6D14-42E1-AFDF-26BB516E49C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAC1D502-6D14-42E1-AFDF-26BB516E49C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAC1D502-6D14-42E1-AFDF-26BB516E49C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAC1D502-6D14-42E1-AFDF-26BB516E49C6}.Release|Any CPU.Build.0 = Release|Any CPU
{AF335305-DF99-4423-9A05-E809EEE173A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF335305-DF99-4423-9A05-E809EEE173A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF335305-DF99-4423-9A05-E809EEE173A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF335305-DF99-4423-9A05-E809EEE173A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="Kata\" />
</ItemGroup>

</Project>
@@ -19,6 +19,11 @@ public Customer(string name)
_name = name;
}

public void addRental(Rental arg)
{
_rentals.Add(arg);
}

public string getName()
{
return _name;
@@ -37,21 +42,22 @@ public String statement()
//determine amounts for each line
switch (each.getMovie().getPriceCode())
{
case 0://// Movie.REGULAR:
case 0: //// Movie.REGULAR:
thisAmount += 2;
if (each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 1.5;

thisAmount += (each.getDaysRented() - 2) * 1.5;
break;
case 1://// Movie.NEW_RELEASE
case 1: //// Movie.NEW_RELEASE
thisAmount += each.getDaysRented() * 3;
break;
case 2://// Movie.CHILDRENS:
case 2: //// Movie.CHILDRENS:
thisAmount += 1.5;
if (each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3) * 1.5;
break;
}

// add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
@@ -60,9 +66,10 @@ public String statement()
each.getDaysRented() > 1) frequentRenterPoints++;
//show figures for this rental
result += "\t" + each.getMovie().getTitle() + "\t" +
thisAmount.ToString() + "\n";
thisAmount.ToString() + "\n";
totalAmount += thisAmount;
}

//add footer lines
result += "Amount owed is " + totalAmount.ToString() +
"\n";
@@ -71,6 +78,5 @@ public String statement()
" frequent renter points";
return result;
}

}
}
}
@@ -25,4 +25,4 @@ public Movie getMovie()
return _movie;
}
}
}
}
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Marsen.NetCore.Dojo\Marsen.NetCore.Dojo.csproj" />
</ItemGroup>

</Project>
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Text;
using Marsen.NetCore.Dojo.Refactoring_Improving_The_Design_of_Existing_Code;
using Xunit;

namespace Marsen.NetCore.Dojo.Tests.Refactoring_Improving_The_Design_of_Existing_Code
{
public class CustomerTester
{
readonly Customer _customer = new Customer("Marsen");

[Fact]
public void no_items()
{
var actual = _customer.statement();
var expected = "Rental Record for Marsen\nAmount owed is 0\nYou earned 0 frequent renter points";
Assert.Equal(expected, actual);
}

[Fact]
public void rent_1_new_release_one_day()
{
_customer.addRental(new Rental(new Movie("A", Movie.NEW_RELEASE), 1));
var actual = _customer.statement();
var expected = "Rental Record for Marsen\n\tA\t3\nAmount owed is 3\nYou earned 1 frequent renter points";
Assert.Equal(expected, actual);
}

[Fact]
public void rent_1_new_release_2_day()
{
_customer.addRental(new Rental(new Movie("A", Movie.NEW_RELEASE), 2));
var actual = _customer.statement();
var expected = "Rental Record for Marsen\n\tA\t6\nAmount owed is 6\nYou earned 2 frequent renter points";
Assert.Equal(expected, actual);
}

[Fact]
public void rent_1_regular_one_day()
{
_customer.addRental(new Rental(new Movie("A", Movie.REGULAR), 1));
var actual = _customer.statement();
var expected = "Rental Record for Marsen\n\tA\t2\nAmount owed is 2\nYou earned 1 frequent renter points";
Assert.Equal(expected, actual);
}

[Fact]
public void rent_1_regular_3_day()
{
_customer.addRental(new Rental(new Movie("A", Movie.REGULAR), 3));
var actual = _customer.statement();
var expected =
"Rental Record for Marsen\n\tA\t3.5\nAmount owed is 3.5\nYou earned 1 frequent renter points";
Assert.Equal(expected, actual);
}

[Fact]
public void rent_1_childrens_one_day()
{
_customer.addRental(new Rental(new Movie("A", Movie.CHILDRENS), 1));
var actual = _customer.statement();
var expected =
"Rental Record for Marsen\n\tA\t1.5\nAmount owed is 1.5\nYou earned 1 frequent renter points";
Assert.Equal(expected, actual);
}


[Fact]
public void rent_1_childrens_4_days()
{
_customer.addRental(new Rental(new Movie("A", Movie.CHILDRENS), 4));
var actual = _customer.statement();
var expected =
"Rental Record for Marsen\n\tA\t3\nAmount owed is 3\nYou earned 1 frequent renter points";
Assert.Equal(expected, actual);
}
}
}

0 comments on commit d8d6f46

Please sign in to comment.
You can’t perform that action at this time.