Skip to content

Commit

Permalink
Extend integration test #255
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacelord-XaN committed Feb 25, 2024
1 parent 1201092 commit 0a9554b
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public IReadOnlyList<ChartDataPoint> GetPriceDistribution(IEnumerable<ProductEnt
}

decimal step = 10.0m;
decimal maxPrice = productPrices.Max();
decimal maxPrice = ((int)(productPrices.Max() / step) + 1) * step;
decimal currentMin = 0;
decimal currentMax = Math.Min(step, maxPrice);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using AngleSharp.Dom;
using AngleSharp.Io;
using BraunauMobil.VeloBasar.Models.Documents;
using AngleSharp.Io;

namespace BraunauMobil.VeloBasar.IntegrationTests;

Expand All @@ -13,6 +11,7 @@ public static async Task<IHtmlDocument> GetDocumentAsync(this HttpClient client,

HttpResponseMessage response = await client.GetAsync(requestUri);
response.EnsureSuccessStatusCode();

return await response.GetDocumentAsync();
}

Expand All @@ -23,6 +22,7 @@ public static async Task<IHtmlDocument> GetDocumentAsync(this HttpClient client,

HttpResponseMessage response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();

return await response.GetDocumentAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace BraunauMobil.VeloBasar.IntegrationTests.Mockups;

public class ClockMock(Func<DateTime> getDateTime)
public class ClockMock(DateTime now)
: IClock
{
public DateTimeOffset Now { get => getDateTime(); }
public DateTimeOffset Now { get; set; } = now;

public DateOnly GetCurrentDate()
=> DateOnly.FromDateTime(Now.DateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
public class AcceptSellers(TestContext context)
{
public async Task Run()
{
await AcceptSeller1(context);

await AssertBasarDetails();
}

private async Task AcceptSeller1(TestContext context)
{
IHtmlDocument newAcceptanceDocument = await context.HttpClient.NavigateMenuAsync("New Acceptance");
newAcceptanceDocument.Title.Should().Be("Acceptance - Enter seller - Velo Basar");
Expand All @@ -27,7 +34,7 @@ public async Task Run()
enterProductsDocument = await EnterProduct2(enterProductsDocument);

IHtmlAnchorElement saveAnchor = enterProductsDocument.QueryAnchorByText("Save accept session");

IHtmlDocument successDocument = await context.HttpClient.GetDocumentAsync(saveAnchor.Href);
successDocument.Title.Should().Be("Acceptance #1 - Velo Basar");

Expand Down Expand Up @@ -86,4 +93,40 @@ private async Task<IHtmlDocument> EnterProduct2(IHtmlDocument enterProductsDocum
postDocument.Title.Should().Be("Acceptance for seller with ID: 1 - Enter products - Velo Basar");
return postDocument;
}

private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(false,
new SellerGroupSettlementStatus(1, 0),
new SellerGroupSettlementStatus(1, 0),
new SellerGroupSettlementStatus(0, 0)
);
BasarDetailsModel expectedDetails = new(new BasarEntity(), basarSettlementStatus)
{
AcceptanceCount = 1,
AcceptedProductsAmount = 191.88M,
AcceptedProductsCount = 2,
AcceptedProductTypesByAmount = [
new ChartDataPoint(92.99m, "Children's bike", X.AnyColor),
new ChartDataPoint(98.89m, "Steel steed", X.AnyColor)
],
AcceptedProductTypesByCount = [
new ChartDataPoint(1, "Children's bike", X.AnyColor),
new ChartDataPoint(1, "Steel steed", X.AnyColor)
],
LockedProductsCount = 0,
LostProductsCount = 0,
PriceDistribution = [
new ChartDataPoint(2, "$100.00", X.AnyColor)
],
SaleCount = 0,
SaleDistribution = [],
SoldProductsAmount = 0,
SoldProductsCount = 0,
SoldProductTypesByCount = [],
SoldProductTypesByAmount = [],
};

await context.AssertBasarDetails(ID.FirstBasar, expectedDetails);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,49 @@ public async Task Run()
new ProductTableRowDocumentModel("1", "Votec - Children's bike".Line("Votec VRC Comp").Line(" green 1067425379"), "24", "$92.99", "* Schattenfell Magsame, Heidenschuss 41, 6295 Hobbingen")
])
);

await AssertBasarDetails();
}

private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(false,
new SellerGroupSettlementStatus(1, 0),
new SellerGroupSettlementStatus(1, 0),
new SellerGroupSettlementStatus(0, 0)
);
BasarDetailsModel expectedDetails = new(new BasarEntity(), basarSettlementStatus)
{
AcceptanceCount = 1,
AcceptedProductsAmount = 191.88M,
AcceptedProductsCount = 2,
AcceptedProductTypesByAmount = [
new ChartDataPoint(92.99m, "Children's bike", X.AnyColor),
new ChartDataPoint(98.89m, "Steel steed", X.AnyColor),
],
AcceptedProductTypesByCount = [
new ChartDataPoint(1, "Children's bike", X.AnyColor),
new ChartDataPoint(1, "Steel steed", X.AnyColor)
],
LockedProductsCount = 0,
LostProductsCount = 0,
PriceDistribution = [
new ChartDataPoint(2, "$100.00", X.AnyColor)
],
SaleCount = 1,
SaleDistribution = [
new ChartDataPoint(92.99M, "11:22 AM", X.AnyColor),
],
SoldProductsAmount = 92.99m,
SoldProductsCount = 1,
SoldProductTypesByCount = [
new ChartDataPoint(1, "Children's bike", X.AnyColor),
],
SoldProductTypesByAmount = [
new ChartDataPoint(92.99m, "Children's bike", X.AnyColor),
],
};

await context.AssertBasarDetails(ID.FirstBasar, expectedDetails);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,49 @@ public async Task Run()
"Edoras on Thursday, April 5, 2063 at 11:22 AM"
)
);

await AssertBasarDetails();
}

private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(true,
new SellerGroupSettlementStatus(1, 1),
new SellerGroupSettlementStatus(1, 1),
new SellerGroupSettlementStatus(0, 0)
);
BasarDetailsModel expectedDetails = new(new BasarEntity(), basarSettlementStatus)
{
AcceptanceCount = 1,
AcceptedProductsAmount = 191.88M,
AcceptedProductsCount = 2,
AcceptedProductTypesByAmount = [
new ChartDataPoint(92.99m, "Children's bike", X.AnyColor),
new ChartDataPoint(98.89m, "Steel steed", X.AnyColor)
],
AcceptedProductTypesByCount = [
new ChartDataPoint(1, "Children's bike", X.AnyColor),
new ChartDataPoint(1, "Steel steed", X.AnyColor)
],
LockedProductsCount = 0,
LostProductsCount = 0,
PriceDistribution = [
new ChartDataPoint(2, "$100.00", X.AnyColor)
],
SaleCount = 1,
SaleDistribution = [
new ChartDataPoint(92.99M, "11:22 AM", X.AnyColor),
],
SoldProductsAmount = 92.99m,
SoldProductsCount = 1,
SoldProductTypesByCount = [
new ChartDataPoint(1, "Children's bike", X.AnyColor),
],
SoldProductTypesByAmount = [
new ChartDataPoint(92.99m, "Children's bike", X.AnyColor),
],
};

await context.AssertBasarDetails(ID.FirstBasar, expectedDetails);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class AcceptSellers(TestContext context)
public async Task Run()
{
await Seller2();
await AssertOverview();
await AssertBasarDetails();
}

private async Task Seller2()
Expand Down Expand Up @@ -75,7 +75,7 @@ private async Task Seller2()
);
}

private async Task AssertOverview()
private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(false,
new SellerGroupSettlementStatus(1, 0),
Expand All @@ -88,15 +88,16 @@ private async Task AssertOverview()
AcceptedProductsAmount = 96.81M,
AcceptedProductsCount = 2,
AcceptedProductTypesByAmount = [
new ChartDataPoint(96.81M, "Scooter", Color.FromArgb(0xFF, 0x00, 0x7B, 0xFF))
new ChartDataPoint(96.81M, "Scooter", X.AnyColor)
],
AcceptedProductTypesByCount = [
new ChartDataPoint(2M, "Scooter", Color.FromArgb(0xFF, 0x00, 0x7B, 0xFF))
new ChartDataPoint(2M, "Scooter", X.AnyColor)
],
LockedProductsCount = 0,
LostProductsCount = 0,
PriceDistribution = [
new ChartDataPoint(1, "$50.00", Color.FromArgb(0xFF, 0x00, 0x7B, 0xFF))
new ChartDataPoint(1, "$50.00", X.AnyColor),
new ChartDataPoint(1, "$60.00", X.AnyColor)
],
SaleCount = 0,
SaleDistribution = [],
Expand All @@ -106,7 +107,7 @@ private async Task AssertOverview()
SoldProductTypesByAmount = [],
};

await context.AssertBasarDetails(2, expectedDetails);
await context.AssertBasarDetails(ID.SecondBasar, expectedDetails);
}

private async Task<IHtmlDocument> EnterProduct(IHtmlDocument enterProductsDocument, string expectedTitle, IDictionary<string, object> values)
Expand Down
18 changes: 17 additions & 1 deletion test/BraunauMobil.VeloBasar.IntegrationTests/TestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,23 @@ public async Task AssertBasarDetails(int basarId, BasarDetailsModel expectedDeta
IBasarService basarService = ServiceProvider.GetRequiredService<IBasarService>();
BasarDetailsModel result = await basarService.GetDetailsAsync(basarId);

result.Should().BeEquivalentTo(expectedDetails, options => options.Excluding(details => details.Entity));
result.Should().BeEquivalentTo(expectedDetails, options =>
{
return options.Excluding(details => details.Entity)
.For(details => details.AcceptedProductTypesByAmount)
.Exclude(chartData => chartData.Color)
.For(details => details.AcceptedProductTypesByCount)
.Exclude(chartData => chartData.Color)
.For(details => details.PriceDistribution)
.Exclude(chartData => chartData.Color)
.For(details => details.SaleDistribution)
.Exclude(chartData => chartData.Color)
.For(details => details.SoldProductTypesByAmount)
.Exclude(chartData => chartData.Color)
.For(details => details.SoldProductTypesByCount)
.Exclude(chartData => chartData.Color)
;
});
}

public string BankingQrCode(string seller, string amount, string decscription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ public async Task Run()
await new Steps.FirstBasar.SellProducts(_context).Run();
await new Steps.FirstBasar.SettleSellers(_context).Run();

X.FirstContactDay = X.FirstContactDay.AddYears(1).AddMonths(1).AddDays(1).AddHours(1).AddMinutes(1).AddSeconds(1);
X.Clock.Now = X.FirstContactDay.AddYears(1).AddMonths(1).AddDays(1).AddHours(1).AddMinutes(1).AddSeconds(1);

await new Steps.SecondBasar.Creation(_context).Run();
await new Steps.SecondBasar.AcceptSellers(_context).Run();

}

private async Task Login()
Expand Down
4 changes: 3 additions & 1 deletion test/BraunauMobil.VeloBasar.IntegrationTests/X.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ public static class X
{
public static DateTime FirstContactDay { get; set; } = new DateTime(2063, 04, 05, 11, 22, 33);

public static ClockMock Clock { get; } = new (() => FirstContactDay);
public static ClockMock Clock { get; } = new (FirstContactDay);

public static Color AnyColor { get; } = new Color();

public static string Line(this string s, string nextLine = "")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void Products_ShouldReturnDistribution(Color primaryColor)
{
// Arrange
A.CallTo(() => ColorProvider.Primary).Returns(primaryColor);
ProductEntity[] products = new[]
{
ProductEntity[] products =
[
CreateProduct(0),
CreateProduct(0),
CreateProduct(1),
Expand All @@ -37,7 +37,9 @@ public void Products_ShouldReturnDistribution(Color primaryColor)
CreateProduct(11),
CreateProduct(100),
CreateProduct(1000),
};
CreateProduct(9989.89M),
CreateProduct(9999.99M),
];

// Act
IReadOnlyList<ChartDataPoint> result = Sut.GetPriceDistribution(products);
Expand All @@ -49,32 +51,58 @@ public void Products_ShouldReturnDistribution(Color primaryColor)
new ChartDataPoint(2, "€ 20,00", primaryColor),
new ChartDataPoint(1, "€ 100,00", primaryColor),
new ChartDataPoint(1, "€ 1.000,00", primaryColor),
new ChartDataPoint(1, "€ 9.990,00", primaryColor),
new ChartDataPoint(1, "€ 10.000,00", primaryColor),
});

A.CallTo(() => ColorProvider.Primary).MustHaveHappened(4, Times.Exactly);
A.CallTo(() => ColorProvider.Primary).MustHaveHappened(result.Count, Times.Exactly);
}

[Theory]
[VeloAutoData]
public void ProductsWithPricesLowerThan10_ShouldReturnDistribution(Color primaryColor)
public void ProductsWithTwoPricesInTheSameRange_ShouldReturnDistribution(Color primaryColor)
{
// Arrange
A.CallTo(() => ColorProvider.Primary).Returns(primaryColor);
ProductEntity[] products = new[]
ProductEntity[] products =
[
CreateProduct(92.99M),
CreateProduct(98.89M)
];

// Act
IReadOnlyList<ChartDataPoint> result = Sut.GetPriceDistribution(products);

// Assert
result.Should().BeEquivalentTo(new[]
{
new ChartDataPoint(2, "€ 100,00", primaryColor)
});

A.CallTo(() => ColorProvider.Primary).MustHaveHappened(1, Times.Exactly);
}

[Theory]
[VeloAutoData]
public void ProductsWithPricesLowerThan10_ShouldReturnDistribution(Color primaryColor)
{
// Arrange
A.CallTo(() => ColorProvider.Primary).Returns(primaryColor);
ProductEntity[] products =
[
CreateProduct(0),
CreateProduct(0),
CreateProduct(1),
CreateProduct(5)
};
];

// Act
IReadOnlyList<ChartDataPoint> result = Sut.GetPriceDistribution(products);

// Assert
result.Should().BeEquivalentTo(new[]
{
new ChartDataPoint(4, "€ 5,00", primaryColor),
new ChartDataPoint(4, "€ 10,00", primaryColor),
});

A.CallTo(() => ColorProvider.Primary).MustHaveHappenedOnceExactly();
Expand Down

0 comments on commit 0a9554b

Please sign in to comment.