Skip to content

Commit

Permalink
HalfOfMonth variable not being used (#363)
Browse files Browse the repository at this point in the history
* fix: halfOfMonth var was not being used

* refactor: halfOfMonth → Today

* refactor: use TODAY and add comment to it

* fix: bad replace

* fix: today must have right hours/minutes

* fix: hour test must have its day set to TODAY

* refactor: hard code Today to a date
  • Loading branch information
Dannyps authored Nov 2, 2023
1 parent ef50aca commit a05826f
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Backbone.DevelopmentKit.Identity.ValueObjects;
using Backbone.Modules.Messages.Domain.Entities;
using Backbone.Modules.Messages.Infrastructure.Persistence.Database;
using Backbone.Modules.Quotas.Domain.Aggregates;
using Backbone.Modules.Quotas.Domain.Aggregates.Identities;
using Backbone.Modules.Quotas.Infrastructure.Persistence.Database;
using Backbone.Modules.Quotas.Infrastructure.Persistence.Repository;
Expand All @@ -14,16 +15,24 @@
namespace Backbone.Modules.Quotas.Application.Tests.Tests.Repositories;
public class MessagesRepositoryTests
{

private readonly IdentityAddress _identityAddress1 = TestDataGenerator.CreateRandomIdentityAddress();
private readonly IdentityAddress _identityAddress2 = TestDataGenerator.CreateRandomIdentityAddress();

private readonly MessagesDbContext _messagesArrangeContext;
private readonly QuotasDbContext _actContext;

private static readonly DateTime YESTERDAY = DateTime.UtcNow.AddDays(-1);
private static readonly DateTime TOMORROW = DateTime.UtcNow.AddDays(1);
private static readonly DateTime LAST_YEAR = DateTime.UtcNow.AddYears(-1);
private static readonly DateTime NEXT_YEAR = DateTime.UtcNow.AddYears(1);
/**
* <summary>
* TODAY is set to the 15th of the current month so that we can use notions
* such as TOMORROW or YESTERDAY and be certain that those dates fall on the same Month.
* </summary>
*/
private static readonly DateTime TODAY = new(2020, 02, 15, 10, 30, 00);
private static readonly DateTime YESTERDAY = TODAY.AddDays(-1);
private static readonly DateTime TOMORROW = TODAY.AddDays(1);
private static readonly DateTime LAST_YEAR = TODAY.AddYears(-1);
private static readonly DateTime NEXT_YEAR = TODAY.AddYears(1);

public MessagesRepositoryTests()
{
Expand All @@ -32,14 +41,16 @@ public MessagesRepositoryTests()
var connection = FakeDbContextFactory.CreateDbConnection();
(_messagesArrangeContext, _, _) = FakeDbContextFactory.CreateDbContexts<MessagesDbContext>(connection);
(_, _, _actContext) = FakeDbContextFactory.CreateDbContexts<QuotasDbContext>(connection);

SystemTime.Set(TODAY);
}

[Fact]
public async Task Counts_entities_within_timeframe_hour_quotaPeriod()
{
// Arrange
var messages = new List<Message>() {
CreateMessage(DateTime.Now, _identityAddress1),
CreateMessage(TODAY, _identityAddress1),
CreateMessage(YESTERDAY, _identityAddress1),
CreateMessage(TOMORROW, _identityAddress1)
};
Expand All @@ -60,11 +71,8 @@ public async Task Counts_entities_within_timeframe_hour_quotaPeriod()
public async Task Counts_entities_within_timeframe_month_quotaPeriod()
{
// Arrange
var halfOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15);
SystemTime.Set(halfOfMonth);

var messages = new List<Message>() {
CreateMessage(DateTime.Now, _identityAddress1),
CreateMessage(TODAY, _identityAddress1),
CreateMessage(YESTERDAY, _identityAddress1),
CreateMessage(TOMORROW, _identityAddress1),
CreateMessage(LAST_YEAR, _identityAddress1),
Expand All @@ -88,7 +96,7 @@ public async Task Counts_entities_total_quotaPeriod()
{
// Arrange
var messages = new List<Message>() {
CreateMessage(DateTime.Now, _identityAddress1),
CreateMessage(TODAY, _identityAddress1),
CreateMessage(TOMORROW, _identityAddress1),
CreateMessage(NEXT_YEAR, _identityAddress1)
};
Expand All @@ -110,7 +118,7 @@ public async Task Counts_entities_only_for_requested_identityAddress()
{
// Arrange
var messages = new List<Message>() {
CreateMessage(DateTime.Now, _identityAddress1),
CreateMessage(TODAY, _identityAddress1),
CreateMessage(TOMORROW, _identityAddress2),
CreateMessage(NEXT_YEAR, _identityAddress1)
};
Expand All @@ -129,6 +137,8 @@ public async Task Counts_entities_only_for_requested_identityAddress()

private static Message CreateMessage(DateTime createdAt, IdentityAddress identityAddress)
{
var savedDateTime = SystemTime.UtcNow;

SystemTime.Set(createdAt);

var message = new Message(
Expand All @@ -140,7 +150,7 @@ private static Message CreateMessage(DateTime createdAt, IdentityAddress identit
new List<RecipientInformation>()
);

SystemTime.Reset();
SystemTime.Set(savedDateTime);

return message;
}
Expand Down

0 comments on commit a05826f

Please sign in to comment.