Skip to content

Commit 17a1d40

Browse files
Merge branch 'csharp-booking-04'
2 parents 6cf9918 + e68ee2d commit 17a1d40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1083
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 15.0.26124.0
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{26CCBDA1-0811-47E7-92BA-A4749674B8E4}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking", "src\Booking\Booking.csproj", "{70A618E2-11BC-454B-84D4-A0DE26F2D296}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{4E771359-5709-4FE7-A7B4-A956EC611D14}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Tests", "test\Booking.Tests\Booking.Tests.csproj", "{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Debug|x64 = Debug|x64
18+
Debug|x86 = Debug|x86
19+
Release|Any CPU = Release|Any CPU
20+
Release|x64 = Release|x64
21+
Release|x86 = Release|x86
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
27+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Debug|x64.ActiveCfg = Debug|Any CPU
30+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Debug|x64.Build.0 = Debug|Any CPU
31+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Debug|x86.ActiveCfg = Debug|Any CPU
32+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Debug|x86.Build.0 = Debug|Any CPU
33+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Release|x64.ActiveCfg = Release|Any CPU
36+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Release|x64.Build.0 = Release|Any CPU
37+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Release|x86.ActiveCfg = Release|Any CPU
38+
{70A618E2-11BC-454B-84D4-A0DE26F2D296}.Release|x86.Build.0 = Release|Any CPU
39+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Debug|x64.ActiveCfg = Debug|Any CPU
42+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Debug|x64.Build.0 = Debug|Any CPU
43+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Debug|x86.ActiveCfg = Debug|Any CPU
44+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Debug|x86.Build.0 = Debug|Any CPU
45+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Release|Any CPU.ActiveCfg = Release|Any CPU
46+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Release|x64.ActiveCfg = Release|Any CPU
48+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Release|x64.Build.0 = Release|Any CPU
49+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Release|x86.ActiveCfg = Release|Any CPU
50+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C}.Release|x86.Build.0 = Release|Any CPU
51+
EndGlobalSection
52+
GlobalSection(NestedProjects) = preSolution
53+
{70A618E2-11BC-454B-84D4-A0DE26F2D296} = {26CCBDA1-0811-47E7-92BA-A4749674B8E4}
54+
{7B3CC2C7-A8EF-4538-AD15-229794D1F16C} = {4E771359-5709-4FE7-A7B4-A956EC611D14}
55+
EndGlobalSection
56+
EndGlobal
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
3+
namespace CodelyTv.Booking
4+
{
5+
public sealed class Booking
6+
{
7+
private readonly BookingId id;
8+
private readonly DateTime startDate;
9+
private readonly DateTime endDate;
10+
private readonly CustomerId customerId;
11+
private readonly CustomerName customerName;
12+
private readonly EmailAddress customerEmail;
13+
private readonly BookingType bookingType;
14+
private readonly DiscountType discountType;
15+
private readonly DiscountValue discountValue;
16+
private readonly TaxType taxType;
17+
private readonly TaxValue taxValue;
18+
19+
public Booking(
20+
BookingId id,
21+
DateRange bookingDateRange,
22+
Customer customer,
23+
BookingType bookingType,
24+
Discount discount,
25+
Tax tax
26+
)
27+
{
28+
this.id = id;
29+
this.startDate = bookingDateRange.StartDate;
30+
this.endDate = bookingDateRange.EndDate;
31+
this.customerId = customer.Id;
32+
this.customerName = customer.Name;
33+
this.customerEmail = customer.EmailAddress;
34+
this.bookingType = bookingType;
35+
this.discountType = discount.Type;
36+
this.discountValue = discount.Value;
37+
this.taxType = tax.Type;
38+
this.taxValue = tax.Value;
39+
}
40+
41+
public BookingStatus StatusFor(DateTime date)
42+
{
43+
if (date < startDate)
44+
{
45+
return BookingStatus.NOT_STARTED;
46+
}
47+
48+
if (date > startDate && date < endDate)
49+
{
50+
return BookingStatus.ACTIVE;
51+
}
52+
53+
return BookingStatus.FINISHED;
54+
}
55+
}
56+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<RootNamespace>CodelyTv.Booking</RootNamespace>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CodelyTv.Booking
4+
{
5+
public sealed class BookingId
6+
{
7+
private readonly string value;
8+
9+
public BookingId(string value) => this.value = value;
10+
}
11+
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public enum BookingStatus { NOT_STARTED, ACTIVE, FINISHED }
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public enum BookingType { VACATION, WORK }
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public sealed class Customer
4+
{
5+
public CustomerId Id { get; }
6+
public CustomerName Name { get; }
7+
public EmailAddress EmailAddress { get; }
8+
9+
public Customer(CustomerId id, CustomerName name, EmailAddress emailAddress)
10+
{
11+
this.Id = id;
12+
this.Name = name;
13+
this.EmailAddress = emailAddress;
14+
}
15+
}
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public sealed class CustomerId
4+
{
5+
private readonly string value;
6+
7+
public CustomerId(string value) => this.value = value;
8+
}
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace CodelyTv.Booking
4+
{
5+
public sealed class CustomerName
6+
{
7+
private readonly string value;
8+
9+
public CustomerName(string value) => this.value = value;
10+
}
11+
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CodelyTv.Booking
8+
{
9+
public sealed class DateRange
10+
{
11+
public DateTime StartDate { get; }
12+
public DateTime EndDate { get; }
13+
14+
public DateRange(DateTime startDate, DateTime endDate)
15+
{
16+
this.StartDate = startDate;
17+
this.EndDate = endDate;
18+
}
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CodelyTv.Booking
8+
{
9+
public sealed class Discount
10+
{
11+
public DiscountType Type { get; }
12+
public DiscountValue Value { get; }
13+
14+
public Discount(DiscountType type, DiscountValue value)
15+
{
16+
this.Type = type;
17+
this.Value = value;
18+
}
19+
}
20+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public enum DiscountType { NONE }
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public sealed class DiscountValue
4+
{
5+
private readonly int value;
6+
7+
public DiscountValue(int value) => this.value = value;
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public sealed class EmailAddress
4+
{
5+
private readonly string value;
6+
7+
public EmailAddress(string value) => this.value = value;
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public sealed class Tax
4+
{
5+
public TaxType Type { get; }
6+
public TaxValue Value { get; }
7+
8+
public Tax(TaxType type, TaxValue value)
9+
{
10+
this.Type = type;
11+
this.Value = value;
12+
}
13+
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public enum TaxType { NONE }
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace CodelyTv.Booking
2+
{
3+
public sealed class TaxValue
4+
{
5+
private readonly int value;
6+
7+
public TaxValue(int value) => this.value = value;
8+
}
9+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<RootNamespace>CodelyTv.Booking.Tests</RootNamespace>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
10+
<PackageReference Include="xunit" Version="2.4.1" />
11+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\Booking\Booking.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using Xunit;
3+
4+
namespace CodelyTv.Booking.Tests
5+
{
6+
public sealed class BookingShould
7+
{
8+
[Fact]
9+
private void GetTheCorrectStatusWhenTheBookingHasNotStartedYet()
10+
{
11+
var dateBeforeBookingHasStarted = new DateTime(2020, 5, 1, 12, 0, 0);
12+
13+
var bookingStartDate = new DateTime(2020, 6, 26, 19, 0, 0);
14+
var bookingEndDate = new DateTime(2020, 7, 14, 16, 0, 0);
15+
16+
var booking = new Booking(
17+
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
18+
new DateRange(bookingStartDate, bookingEndDate),
19+
new Customer(
20+
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
21+
new CustomerName("Perico Los Palotes"),
22+
new EmailAddress("perico.los.palotes@mail.com")
23+
),
24+
BookingType.VACATION,
25+
new Discount(DiscountType.NONE, new DiscountValue(0)),
26+
new Tax(TaxType.NONE, new TaxValue(0))
27+
);
28+
29+
Assert.Equal(BookingStatus.NOT_STARTED, booking.StatusFor(dateBeforeBookingHasStarted));
30+
}
31+
32+
[Fact]
33+
private void GetTheCorrectStatusWhenTheBookingIsCurrentlyActive()
34+
{
35+
var dateBeforeBookingHasStarted = new DateTime(2020, 6, 29, 15, 0, 0);
36+
37+
var bookingStartDate = new DateTime(2020, 6, 26, 19, 0, 0);
38+
var bookingEndDate = new DateTime(2020, 7, 14, 16, 0, 0);
39+
40+
var booking = new Booking(
41+
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
42+
new DateRange(bookingStartDate, bookingEndDate),
43+
new Customer(
44+
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
45+
new CustomerName("Perico Los Palotes"),
46+
new EmailAddress("perico.los.palotes@mail.com")
47+
),
48+
BookingType.VACATION,
49+
new Discount(DiscountType.NONE, new DiscountValue(0)),
50+
new Tax(TaxType.NONE, new TaxValue(0))
51+
);
52+
53+
Assert.Equal(BookingStatus.ACTIVE, booking.StatusFor(dateBeforeBookingHasStarted));
54+
}
55+
56+
[Fact]
57+
private void GetTheCorrectStatusWhenTheBookingIsFinished()
58+
{
59+
var dateBeforeBookingHasStarted = new DateTime(2020, 8, 30, 19, 0, 0);
60+
61+
var bookingStartDate = new DateTime(2020, 6, 26, 19, 0, 0);
62+
var bookingEndDate = new DateTime(2020, 7, 14, 16, 0, 0);
63+
64+
var booking = new Booking(
65+
new BookingId("2c1e34d0-1430-4307-80bf-a71761f71390"),
66+
new DateRange(bookingStartDate, bookingEndDate),
67+
new Customer(
68+
new CustomerId("72cf3524-7838-45f3-8179-2e75abe5e81c"),
69+
new CustomerName("Perico Los Palotes"),
70+
new EmailAddress("perico.los.palotes@mail.com")
71+
),
72+
BookingType.VACATION,
73+
new Discount(DiscountType.NONE, new DiscountValue(0)),
74+
new Tax(TaxType.NONE, new TaxValue(0))
75+
);
76+
77+
Assert.Equal(BookingStatus.FINISHED, booking.StatusFor(dateBeforeBookingHasStarted));
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)