Skip to content

Commit

Permalink
Extend integration tests #255
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacelord-XaN committed Feb 25, 2024
1 parent 01582f7 commit 69afdd7
Show file tree
Hide file tree
Showing 12 changed files with 497 additions and 146 deletions.
2 changes: 1 addition & 1 deletion src/BraunauMobil.VeloBasar/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"AllowedHosts": "*",
"ApplicationSettings": {
"Culture": "de-AT",
"ConnectionString": "User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=velobasar-integration-test;Pooling=true;"
"ConnectionString": "User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=velobasar;Pooling=true;"
},
"Logging": {
"LogLevel": {
Expand Down
91 changes: 1 addition & 90 deletions test/BraunauMobil.VeloBasar.DataGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using Xan.Extensions;

namespace BraunauMobil.VeloBasar.DataGenerator;
Expand All @@ -24,94 +22,7 @@ public static async Task Main()
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");

Random rand = new();

StringBuilder sb = new();

string[] countries = ["Austria", "Germany"];

string firstName = rand.GetRandomElement(Names.FirstNames);
string lastName = rand.GetRandomElement(Names.FirstNames);
sb.AppendLine($"{{ \"BankAccountHolder\", \"{firstName} {firstName[0]}.{lastName[0]}. {lastName}\" }},");
sb.AppendLine($"{{ \"City\", \"{rand.GetRandomElement(Names.Cities)}\" }},");
sb.AppendLine($"{{ \"CountryId\", ID.Countries.{rand.GetRandomElement(countries)} }},");
sb.AppendLine($"{{ \"EMail\", \"{firstName.ToLower().Replace(" ", "")}@{lastName.ToLower().Replace(" ", "")}.me\" }},");
sb.AppendLine($"{{ \"FirstName\", \"{firstName}\" }},");
sb.AppendLine($"{{ \"HasNewsletterPermission\", {(rand.Next(0, 2) == 0).ToString().ToLower()} }},");
sb.AppendLine("{ \"IBAN\", \"\" },");
sb.AppendLine($"{{ \"LastName\", \"{lastName}\" }},");
sb.AppendLine($"{{ \"Street\", \"{rand.GetRandomElement(Names.Streets)} {rand.Next(1, 50)}\" }},");
sb.Append("{ \"PhoneNumber\", \"");
for (int counter = 0; counter < rand.Next(8, 11); counter++)
{
sb.Append(rand.Next(0, 10));
}
sb.AppendLine("\" },");
sb.AppendLine($"{{ \"ZIP\", \"{rand.Next(1, 10)}{rand.Next(1, 10)}{rand.Next(1, 10)}{rand.Next(1, 10)}\" }},");

sb.AppendLine();

sb.AppendLine("--------------------------------------------------------------------------");
sb.AppendLine("Products");
sb.AppendLine();


string[] typeNames = [
"Unicycle",
"RoadBike",
"MansCityBike",
"WomansCityBike",
"ChildrensBike",
"Scooter",
"EBike",
"SteelSteed",
];
string[] colors = [
"red",
"blue",
"green",
"yellow",
"orange",
"purple",
"pink",
"brown",
"gray",
"turquoise",
"lavender",
"maroon",
"indigo",
"cyan",
"olive",
"peach",
"teal",
"magenta",
"beige",
"slate",
];

foreach (int _ in Enumerable.Range(0, 4))
{
string brand = rand.GetRandomElement(Names.BrandNames);
sb.AppendLine($"{{ \"TypeId\", ID.ProductTypes.{rand.GetRandomElement(typeNames)} }},");
sb.AppendLine($"{{ \"Brand\", \"{brand}\" }},");
sb.AppendLine($"{{ \"Color\", \"{rand.GetRandomElement(colors)}\" }},");
if (rand.Next(0, 2) == 0)
{
sb.AppendLine($"{{ \"FrameNumber\", \"{Guid.NewGuid().ToString()[..rand.Next(7, 10)]}\" }},");
}
sb.AppendLine($"{{ \"Description\", \"{brand[..].ToUpper()}_{rand.Next(10000, 999999)}\" }},");
sb.AppendLine($"{{ \"TireSize\", \"{rand.GetRandomElement(Names.TireSizes)}\" }},");
sb.AppendLine($"{{ \"Price\", {Math.Round((decimal)rand.GetGaussian(100, 50), 2)}M }},");
sb.AppendLine();
}

string fileName = @"c:\temp\testData.txt";
File.WriteAllText(fileName, sb.ToString());
ProcessStartInfo info = new(fileName)
{
UseShellExecute = true
};
Process.Start(info);
await GeneratePostgresAsync("User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=velobasar;Pooling=true;");
}

private static async Task GeneratePostgresAsync(string connectionString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ public static IHtmlAnchorElement QueryTableApplyLink(this IParentNode node, int
{
ArgumentNullException.ThrowIfNull(node);

IHtmlTableElement? table = node.QuerySelector<IHtmlTableElement>("table");
table.Should().NotBeNull();
IHtmlTableRowElement headerRow = table!.Rows[0];
INode idHeaderCell = headerRow.Cells.Should().ContainSingle(cell => cell.TextContent == "Id").Subject;
int idColumnIndex = headerRow.Cells.Index(idHeaderCell);

IHtmlTableRowElement row = table.Rows.Should().ContainSingle(row => row.Cells[idColumnIndex].TextContent == rowId.ToString()).Subject;
return row.QueryAnchorByText("Apply");
return node.QueryTableLinkByIdAndText(rowId, "Apply");
}

public static IHtmlAnchorElement QueryTableDetailsLink(this IParentNode node, int rowId)
{
ArgumentNullException.ThrowIfNull(node);

return node.QueryTableLinkByIdAndText(rowId, "Details");
}

public static IHtmlAnchorElement QueryTableLinkByIdAndText(this IParentNode node, int rowId, string linkText)
{
ArgumentNullException.ThrowIfNull(node);

IHtmlTableElement? table = node.QuerySelector<IHtmlTableElement>("table");
table.Should().NotBeNull();
table!.Should().NotBeNull();
IHtmlTableRowElement headerRow = table!.Rows[0];
INode idHeaderCell = headerRow.Cells.Should().ContainSingle(cell => cell.TextContent == "Id").Subject;
int idColumnIndex = headerRow.Cells.Index(idHeaderCell);

IHtmlTableRowElement row = table.Rows.Should().ContainSingle(row => row.Cells[idColumnIndex].TextContent == rowId.ToString()).Subject;
return row.QueryAnchorByText("Details");
return row.QueryAnchorByText(linkText);
}

public static IHtmlFormElement QueryForm(this IParentNode node, string selector = "form")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BraunauMobil.VeloBasar.IntegrationTests.Steps.FirstBasar;

public class AcceptSellers(TestContext context)
public class Acccept(TestContext context)
{
public async Task Run()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BraunauMobil.VeloBasar.IntegrationTests.Steps.FirstBasar;

public class Creation(TestContext context)
public class Create(TestContext context)
{
public async Task Run()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BraunauMobil.VeloBasar.IntegrationTests.Steps.FirstBasar;

public class SellProducts(TestContext context)
public class Sell(TestContext context)
{
public async Task Run()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BraunauMobil.VeloBasar.IntegrationTests.Steps.FirstBasar;

public class SettleSellers(TestContext context)
public class Settle(TestContext context)
{
public async Task Run()
{
Expand All @@ -17,7 +17,8 @@ public async Task Run()

IHtmlAnchorElement voucherAnchor = successDocument.QueryAnchorByText("Voucher");
SettlementDocumentModel document = await context.HttpClient.GetSettlementDocumentAsync(voucherAnchor.Href);
document.Should().BeEquivalentTo(context.SettlementDocument("XYZ - First Bazaar : Settlement #1",
document.Should().BeEquivalentTo(context.SettlementDocument(
"XYZ - First Bazaar : Settlement #1",
"Edoras, 5/4/2063",
"Schattenfell Magsame".Line("Heidenschuss 41").Line("6295 Hobbingen").Line(),
"Seller.-ID: 1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BraunauMobil.VeloBasar.IntegrationTests.Steps.SecondBasar;

public class Creation(TestContext context)
public class Create(TestContext context)
{
public async Task Run()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,79 @@ public async Task Run()
await new LockProductUnlockAndSellIt(context).Run();
await new LooseProductUnlockAndSellIt(context).Run();
await new SellTwoProductsCancelOneSellItAgainCancelItAndFinallySellIt(context).Run();

await AssertBasarDetails();
}

private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(false,
new SellerGroupSettlementStatus(7, 0),
new SellerGroupSettlementStatus(6, 0),
new SellerGroupSettlementStatus(1, 0)
);
BasarDetailsModel expectedDetails = new(new BasarEntity(), basarSettlementStatus)
{
AcceptanceCount = 9,
AcceptedProductsAmount = 1369.43M,
AcceptedProductsCount = 14,
AcceptedProductTypesByAmount = [
new ChartDataPoint(172.10M, "Scooter", X.AnyColor),
new ChartDataPoint(69.54M, "E-bike", X.AnyColor),
new ChartDataPoint(125.97M, "Road bike", X.AnyColor),
new ChartDataPoint(151.34M, "Steel steed", X.AnyColor),
new ChartDataPoint(333.40M, "Men's city bike", X.AnyColor),
new ChartDataPoint(183.90M, "Woman's city bike", X.AnyColor),
new ChartDataPoint(189.54M, "Unicycle", X.AnyColor),
new ChartDataPoint(143.64M, "Children's bike", X.AnyColor),
],
AcceptedProductTypesByCount = [
new ChartDataPoint(3, "Scooter", X.AnyColor),
new ChartDataPoint(1, "E-bike", X.AnyColor),
new ChartDataPoint(2, "Road bike", X.AnyColor),
new ChartDataPoint(1, "Steel steed", X.AnyColor),
new ChartDataPoint(2, "Men's city bike", X.AnyColor),
new ChartDataPoint(2, "Woman's city bike", X.AnyColor),
new ChartDataPoint(2, "Unicycle", X.AnyColor),
new ChartDataPoint(1, "Children's bike", X.AnyColor),
],
LockedProductsCount = 0,
LostProductsCount = 0,
PriceDistribution = [
new ChartDataPoint(1, "$10.00", X.AnyColor),
new ChartDataPoint(1, "$50.00", X.AnyColor),
new ChartDataPoint(1, "$60.00", X.AnyColor),
new ChartDataPoint(2, "$70.00", X.AnyColor),
new ChartDataPoint(1, "$80.00", X.AnyColor),
new ChartDataPoint(1, "$90.00", X.AnyColor),
new ChartDataPoint(1, "$110.00", X.AnyColor),
new ChartDataPoint(2, "$120.00", X.AnyColor),
new ChartDataPoint(2, "$150.00", X.AnyColor),
new ChartDataPoint(1, "$160.00", X.AnyColor),
new ChartDataPoint(1, "$190.00", X.AnyColor),
],
SaleCount = 6,
SaleDistribution = [
new ChartDataPoint(554.89M, "12:23 PM", X.AnyColor),
],
SoldProductsAmount = 554.89M,
SoldProductsCount = 6,
SoldProductTypesByAmount = [
new ChartDataPoint(51.06M, "Scooter", X.AnyColor),
new ChartDataPoint(69.54M, "E-bike", X.AnyColor),
new ChartDataPoint(183.90M, "Woman's city bike", X.AnyColor),
new ChartDataPoint(106.75M, "Unicycle", X.AnyColor),
new ChartDataPoint(143.64M, "Children's bike", X.AnyColor),
],
SoldProductTypesByCount = [
new ChartDataPoint(1, "Scooter", X.AnyColor),
new ChartDataPoint(1, "E-bike", X.AnyColor),
new ChartDataPoint(2, "Woman's city bike", X.AnyColor),
new ChartDataPoint(1, "Unicycle", X.AnyColor),
new ChartDataPoint(1, "Children's bike", X.AnyColor),
],
};

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

0 comments on commit 69afdd7

Please sign in to comment.