Skip to content

Commit

Permalink
Tidy up code and syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
MJB222398 committed Oct 29, 2021
1 parent d53812b commit 81ae863
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 30 deletions.
12 changes: 6 additions & 6 deletions Abstractions.DateAndTime.ExampleApp.Tests/DateTimeHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ public DateTimeHelperTests()
[Test]
public void FormatCurrentDateTime_ReturnsCorrectlyFormattedDateTime()
{
// ARRANGE
// Arrange
A.CallTo(() => _dateTimeService.Now()).Returns(new DateTime(2021, 6, 20, 13, 21, 04));

// ACT
// Act
var formattedCurrentDateTime = _dateTimeHelper.FormatCurrentDateTime();

//ASSERT
// Assert
Assert.That(formattedCurrentDateTime, Is.EqualTo("20/06/2021 13:21:04"));
}

[Test]
public void FormatCurrentOffsetDateTime_ReturnsCorrectlyFormattedDateTime()
{
// ARRANGE
// Arrange
A.CallTo(() => _dateTimeOffsetService.Now()).Returns(new DateTimeOffset(2021, 6, 20, 13, 21, 04, new TimeSpan(2, 0, 0)));

// ACT
// Act
var formattedCurrentOffsetDateTime = _dateTimeHelper.FormatCurrentOffsetDateTime();

//ASSERT
// Assert
Assert.That(formattedCurrentOffsetDateTime, Is.EqualTo("20/06/2021 13:21:04 +02:00"));
}
}
Expand Down
13 changes: 6 additions & 7 deletions Abstractions.DateAndTime.ExampleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ static void Main(string[] args)

private static IServiceProvider GetServiceProvider()
{
var services = new ServiceCollection();
services.AddSingleton<IConsoleOutputManager, ConsoleOutputManager>();
services.AddSingleton<IDateTimeHelper, DateTimeHelper>();
services.AddDateTimeService();
services.AddDateTimeOffsetService();

return services.BuildServiceProvider();
return new ServiceCollection()
.AddSingleton<IConsoleOutputManager, ConsoleOutputManager>()
.AddSingleton<IDateTimeHelper, DateTimeHelper>()
.AddDateTimeService()
.AddDateTimeOffsetService()
.BuildServiceProvider();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ namespace Abstractions.DateAndTime.Services
{
public class DateTimeOffsetService : IDateTimeOffsetService
{
public DateTimeOffsetService()
{
}

public DateTimeOffset Now()
{
return DateTimeOffset.Now;
Expand Down
4 changes: 0 additions & 4 deletions Abstractions.DateAndTime/DateTimeService/DateTimeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ namespace Abstractions.DateAndTime.Services
{
public class DateTimeService : IDateTimeService
{
public DateTimeService()
{
}

public DateTime Now()
{
return DateTime.Now;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ public static IServiceCollection AddDateTimeService(this IServiceCollection serv
if (services == null)
throw new ArgumentNullException(nameof(services));

services.AddSingleton<IDateTimeService, DateTimeService>();

return services;
return services.AddSingleton<IDateTimeService, DateTimeService>();
}

public static IServiceCollection AddDateTimeOffsetService(this IServiceCollection services)
{
if (services == null)
throw new ArgumentNullException(nameof(services));

services.AddSingleton<IDateTimeOffsetService, DateTimeOffsetService>();

return services;
return services.AddSingleton<IDateTimeOffsetService, DateTimeOffsetService>();
}
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public DateTimeHelperTests()
[Test]
public void FormatCurrentDateTime_ReturnsCorrectlyFormattedDateTime()
{
// ARRANGE
// Arrange
A.CallTo(() => _dateTimeService.Now()).Returns(new DateTime(2021, 6, 20, 13, 21, 04));

// ACT
// Act
var formattedCurrentDateTime = _dateTimeHelper.FormatCurrentDateTime();

//ASSERT
// Assert
Assert.That(formattedCurrentDateTime, Is.EqualTo("20/06/2021 13:21:04"));
}
```
Expand Down

0 comments on commit 81ae863

Please sign in to comment.