-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix - Correction de la récupération des deliveries et ajout de TU
- Loading branch information
1 parent
c134f78
commit 26c6577
Showing
11 changed files
with
308 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 214 additions & 0 deletions
214
Sheaft.Application.Queries.Tests/GetProducerDeliveriesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Sheaft.Application.Interop; | ||
using Sheaft.Application.Models; | ||
using Sheaft.Application.Queries; | ||
using Sheaft.Domain.Enums; | ||
using Sheaft.Domain.Models; | ||
using Sheaft.Tests.Common; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Queries.Delivery.Tests | ||
{ | ||
[TestClass] | ||
public class GetProducerDeliveries | ||
{ | ||
private IAppDbContext _context; | ||
private IDeliveryQueries _queries; | ||
|
||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
_context = ContextHelper.GetInMemoryContext(); | ||
_queries = new DeliveryQueries(_context, null); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("3b5c008bb6a24f5c8cc8258b9e33105f", false, DeliveryKind.Farm)] | ||
[DataRow("6a209232b2184ae5bf8a1c26a7a74e8b", true, DeliveryKind.Farm)] | ||
[DataRow("3b5c008bb6a24f5c8cc8258b9e33105f", true, DeliveryKind.ProducerToStore)] | ||
public async Task Should_Return_No_Deliveries(string producerId, bool available, DeliveryKind kind) | ||
{ | ||
var token = CancellationToken.None; | ||
|
||
await _context.AddAsync(new DeliveryMode( | ||
Guid.NewGuid(), | ||
kind, | ||
new Producer(Guid.Parse("3b5c008bb6a24f5c8cc8258b9e33105f"), "prod1", "fa", "la", "[email protected]", new UserAddress("x", null, "x", "x", CountryIsoCode.FR, null)), | ||
available, | ||
0, | ||
new DeliveryAddress("x", null, "x", "x", CountryIsoCode.FR, null, null), | ||
new List<TimeSlotHour> | ||
{ | ||
new TimeSlotHour(DayOfWeek.Wednesday, TimeSpan.FromHours(8), TimeSpan.FromHours(12)) | ||
}, | ||
"delivery1"), token); | ||
|
||
await _context.SaveChangesAsync(token); | ||
|
||
//test | ||
var results = await _queries.GetProducersDeliveriesAsync( | ||
new List<Guid> { Guid.Parse(producerId) }, | ||
new List<DeliveryKind> { DeliveryKind.Farm }, | ||
DateTime.UtcNow, | ||
null, | ||
token); | ||
|
||
//assert | ||
results.Should().NotBeNull().And.BeEmpty(); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(0, 2020, 1, 1, 7, 59, 59, 1, 8)] | ||
[DataRow(0, 2020, 1, 1, 8, 0, 0, 8, 15)] | ||
[DataRow(24, 2019, 12, 31, 8, 0, 0, 8, 15)] | ||
[DataRow(24, 2019, 12, 31, 7, 0, 0, 1, 8)] | ||
public async Task Should_Return_Wednesday_DeliveryHours(int orderLockInHours, int year, int month, int day, int hour, int minute, int second, int expectedFirstDay, int expectedLastDay) | ||
{ | ||
var token = CancellationToken.None; | ||
var currentDate = new DateTime(year, month, day, hour, minute, second); | ||
var producerId = Guid.NewGuid(); | ||
|
||
await _context.AddAsync(new DeliveryMode( | ||
Guid.NewGuid(), | ||
DeliveryKind.Farm, | ||
new Producer(producerId, "prod1", "fa", "la", "[email protected]", new UserAddress("x", null, "x", "x", CountryIsoCode.FR, null)), | ||
true, | ||
orderLockInHours, | ||
new DeliveryAddress("x", null, "x", "x", CountryIsoCode.FR, null, null), | ||
new List<TimeSlotHour> { new TimeSlotHour(DayOfWeek.Wednesday, TimeSpan.FromHours(8), TimeSpan.FromHours(12)) }, | ||
"delivery1"), token); | ||
|
||
await _context.SaveChangesAsync(token); | ||
|
||
//test | ||
var results = await _queries.GetProducersDeliveriesAsync( | ||
new List<Guid> { producerId }, | ||
new List<DeliveryKind> { DeliveryKind.Farm }, | ||
currentDate, | ||
null, | ||
token); | ||
|
||
//assert | ||
var deliveryHoursResults = results | ||
.Should().NotBeNull().And.ContainSingle() | ||
.And.Subject.First().Deliveries.Should().HaveCount(1) | ||
.And.Subject.First().DeliveryHours.Should().HaveCount(2) | ||
.And.Subject.Should().OnlyContain(c => c.Day == DayOfWeek.Wednesday); | ||
|
||
deliveryHoursResults.And.Subject.First().ExpectedDeliveryDate.Day.Should().Be(expectedFirstDay); | ||
deliveryHoursResults.And.Subject.Last().ExpectedDeliveryDate.Day.Should().Be(expectedLastDay); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(0, 2020, 1, 1, 7, 59, 59, 1, 8, 4, 11)] | ||
[DataRow(0, 2020, 1, 1, 8, 0, 0, 8, 15, 4, 11)] | ||
[DataRow(24, 2019, 12, 31, 8, 0, 0, 8, 15, 4, 11)] | ||
[DataRow(24, 2019, 12, 31, 7, 0, 0, 1, 8, 4, 11)] | ||
[DataRow(0, 2020, 1, 8, 8, 0, 0, 15, 22, 11, 18)] | ||
public async Task Should_Return_Multiple_Days_DeliveryHours(int orderLockInHours, int year, int month, int day, int hour, int minute, int second, int expectedFirstDay, int expectedSecondDay, int expectedThirdDay, int expectedLastDay) | ||
{ | ||
var token = CancellationToken.None; | ||
var currentDate = new DateTime(year, month, day, hour, minute, second); | ||
var producerId = Guid.NewGuid(); | ||
|
||
await _context.AddAsync(new DeliveryMode( | ||
Guid.NewGuid(), | ||
DeliveryKind.Farm, | ||
new Producer(producerId, "prod1", "fa", "la", "[email protected]", new UserAddress("x", null, "x", "x", CountryIsoCode.FR, null)), | ||
true, | ||
orderLockInHours, | ||
new DeliveryAddress("x", null, "x", "x", CountryIsoCode.FR, null, null), | ||
new List<TimeSlotHour> { | ||
new TimeSlotHour(DayOfWeek.Wednesday, TimeSpan.FromHours(8), TimeSpan.FromHours(12)), | ||
new TimeSlotHour(DayOfWeek.Saturday, TimeSpan.FromHours(10), TimeSpan.FromHours(16)) | ||
}, | ||
"delivery1"), token); | ||
|
||
await _context.SaveChangesAsync(token); | ||
|
||
//test | ||
var results = await _queries.GetProducersDeliveriesAsync( | ||
new List<Guid> { producerId }, | ||
new List<DeliveryKind> { DeliveryKind.Farm }, | ||
currentDate, | ||
null, | ||
token); | ||
|
||
//assert | ||
var deliveryHoursResults = results | ||
.Should().NotBeNull().And.ContainSingle() | ||
.And.Subject.First().Deliveries.Should().HaveCount(1) | ||
.And.Subject.First().DeliveryHours.Should().HaveCount(4) | ||
.And.Subject.Should().OnlyContain(c => c.Day == DayOfWeek.Wednesday || c.Day == DayOfWeek.Saturday); | ||
|
||
deliveryHoursResults.And.Subject.ElementAt(0).ExpectedDeliveryDate.Day.Should().Be(expectedFirstDay); | ||
deliveryHoursResults.And.Subject.ElementAt(1).ExpectedDeliveryDate.Day.Should().Be(expectedSecondDay); | ||
deliveryHoursResults.And.Subject.ElementAt(2).ExpectedDeliveryDate.Day.Should().Be(expectedThirdDay); | ||
deliveryHoursResults.And.Subject.ElementAt(3).ExpectedDeliveryDate.Day.Should().Be(expectedLastDay); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(0, 2020, 1, 1, 7, 59, 59, 1, 8, 3, 10)] | ||
[DataRow(0, 2020, 1, 1, 8, 0, 0, 8, 15, 3, 10)] | ||
[DataRow(24, 2019, 12, 31, 8, 0, 0, 8, 15, 3, 10)] | ||
[DataRow(24, 2019, 12, 31, 7, 0, 0, 1, 8, 3, 10)] | ||
[DataRow(0, 2020, 1, 8, 8, 0, 0, 15, 22, 10, 17)] | ||
public async Task Should_Return_Multiple_Deliveries(int orderLockInHours, int year, int month, int day, int hour, int minute, int second, int expectedFarmDelivery_FirstDay, int expectedFarmDelivery_SecondDay, int expectedMarketDelivery_FirstDay, int expectedMarketDelivery_SecondDay) | ||
{ | ||
var token = CancellationToken.None; | ||
var currentDate = new DateTime(year, month, day, hour, minute, second); | ||
var producerId = Guid.NewGuid(); | ||
|
||
await _context.AddAsync(new DeliveryMode( | ||
Guid.NewGuid(), | ||
DeliveryKind.Farm, | ||
new Producer(producerId, "prod1", "fa", "la", "[email protected]", new UserAddress("x", null, "x", "x", CountryIsoCode.FR, null)), | ||
true, | ||
orderLockInHours, | ||
new DeliveryAddress("x", null, "x", "x", CountryIsoCode.FR, null, null), | ||
new List<TimeSlotHour> { new TimeSlotHour(DayOfWeek.Wednesday, TimeSpan.FromHours(8), TimeSpan.FromHours(12)) }, | ||
"delivery1"), token); | ||
|
||
await _context.AddAsync(new DeliveryMode( | ||
Guid.NewGuid(), | ||
DeliveryKind.Market, | ||
new Producer(producerId, "prod1", "fa", "la", "[email protected]", new UserAddress("x", null, "x", "x", CountryIsoCode.FR, null)), | ||
true, | ||
orderLockInHours, | ||
new DeliveryAddress("x", null, "x", "x", CountryIsoCode.FR, null, null), | ||
new List<TimeSlotHour> { new TimeSlotHour(DayOfWeek.Friday, TimeSpan.FromHours(16), TimeSpan.FromHours(18)) }, | ||
"delivery2"), token); | ||
|
||
await _context.SaveChangesAsync(token); | ||
|
||
//test | ||
var results = await _queries.GetProducersDeliveriesAsync( | ||
new List<Guid> { producerId }, | ||
new List<DeliveryKind> { DeliveryKind.Farm, DeliveryKind.Market }, | ||
currentDate, | ||
null, | ||
token); | ||
|
||
//assert | ||
var deliveriesResults = results | ||
.Should().NotBeNull().And.ContainSingle() | ||
.And.Subject.First().Deliveries.Should().HaveCount(2); | ||
|
||
var marketDelivery = deliveriesResults.And.Subject.First(c => c.Kind == DeliveryKind.Market); | ||
var farmDelivery = deliveriesResults.And.Subject.First(c => c.Kind == DeliveryKind.Farm); | ||
|
||
marketDelivery.DeliveryHours.Should().OnlyContain(c => c.Day == DayOfWeek.Friday); | ||
marketDelivery.DeliveryHours.ElementAt(0).ExpectedDeliveryDate.Day.Should().Be(expectedMarketDelivery_FirstDay); | ||
marketDelivery.DeliveryHours.ElementAt(1).ExpectedDeliveryDate.Day.Should().Be(expectedMarketDelivery_SecondDay); | ||
|
||
farmDelivery.DeliveryHours.Should().OnlyContain(c => c.Day == DayOfWeek.Wednesday); | ||
farmDelivery.DeliveryHours.ElementAt(0).ExpectedDeliveryDate.Day.Should().Be(expectedFarmDelivery_FirstDay); | ||
farmDelivery.DeliveryHours.ElementAt(1).ExpectedDeliveryDate.Day.Should().Be(expectedFarmDelivery_SecondDay); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Sheaft.Application.Queries.Tests/Sheaft.Application.Queries.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="5.10.3" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" /> | ||
<PackageReference Include="coverlet.collector" Version="1.3.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Sheaft.Application.Interop\Sheaft.Application.Interop.csproj" /> | ||
<ProjectReference Include="..\Sheaft.Application.Queries\Sheaft.Application.Queries.csproj" /> | ||
<ProjectReference Include="..\Sheaft.Tests.Common\Sheaft.Tests.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Localization; | ||
using Moq; | ||
using Sheaft.Application.Interop; | ||
using Sheaft.Infrastructure.Persistence; | ||
using Sheaft.Localization; | ||
using System; | ||
|
||
namespace Sheaft.Tests.Common | ||
{ | ||
public static class ContextHelper | ||
{ | ||
public static IAppDbContext GetInMemoryContext() | ||
{ | ||
var options = new DbContextOptionsBuilder<AppDbContext>() | ||
.UseInMemoryDatabase(Guid.NewGuid().ToString("N")) | ||
.Options; | ||
|
||
return new AppDbContext(options, Mock.Of<IStringLocalizer<MessageResources>>()); | ||
} | ||
} | ||
} |
Oops, something went wrong.