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 eee5a46 commit 977e5dc
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 147 deletions.
98 changes: 97 additions & 1 deletion test/BraunauMobil.VeloBasar.DataGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
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 @@ -22,8 +24,102 @@ public static async Task Main()
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");

Random rand = new();

await GeneratePostgresAsync("User ID=postgres;Password=postgres;Host=localhost;Port=5432;Database=velobasar;Pooling=true;");
StringBuilder sb = new();

sb.AppendLine("Sellers");
sb.AppendLine();

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

foreach (var x in Enumerable.Range(0, 8))
{
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 (var x in Enumerable.Range(0, 30))
{
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
2 changes: 2 additions & 0 deletions test/BraunauMobil.VeloBasar.IntegrationTests/ID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static class Sellers
public const int SchattenfellMagsame = 1;
public const int MeneldorBorondir = 2;
public const int AmrothGerstenmann = 3;
public const int LanghöhlenSiriondil = 4;
public const int FrórBilbo = 5;
}

public static class Products
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public async Task Run()

private async Task AcceptSeller1(TestContext context)
{
const string expectedTitle = "Acceptance for seller with ID: 1 - Enter products - Velo Basar";

IHtmlDocument newAcceptanceDocument = await context.HttpClient.NavigateMenuAsync("New Acceptance");
newAcceptanceDocument.Title.Should().Be("Acceptance - Enter seller - Velo Basar");

Expand All @@ -28,10 +30,28 @@ private async Task AcceptSeller1(TestContext context)
{ "PhoneNumber", "71904814" },
{ "EMail", "schattenfell@magsame.me" },
});
enterProductsDocument.Title.Should().Be("Acceptance for seller with ID: 1 - Enter products - Velo Basar");
enterProductsDocument.Title.Should().Be(expectedTitle);

enterProductsDocument = await EnterProduct1(enterProductsDocument);
enterProductsDocument = await EnterProduct2(enterProductsDocument);
enterProductsDocument = await context.EnterProduct(enterProductsDocument, expectedTitle, new Dictionary<string, object>
{
{ "TypeId", ID.ProductTypes.ChildrensBike },
{ "Brand", "Votec" },
{ "Color", "green" },
{ "FrameNumber", "1067425379" },
{ "Description", "Votec VRC Comp" },
{ "TireSize", "24" },
{ "Price", 92.99m }
});
enterProductsDocument = await context.EnterProduct(enterProductsDocument, expectedTitle, new Dictionary<string, object>
{
{ "TypeId", ID.ProductTypes.SteelSteed },
{ "Brand", "KTM" },
{ "Color", "red" },
{ "FrameNumber", "1239209209" },
{ "Description", "Steed 1" },
{ "TireSize", "22" },
{ "Price", 98.89m }
});

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

Expand All @@ -56,44 +76,6 @@ private async Task AcceptSeller1(TestContext context)
);
}

private async Task<IHtmlDocument> EnterProduct1(IHtmlDocument enterProductsDocument)
{
IHtmlFormElement form = enterProductsDocument.QueryForm();
IHtmlButtonElement submitButton = enterProductsDocument.QueryButtonByText("Add");

IHtmlDocument postDocument = await context.HttpClient.SendFormAsync(form, submitButton, new Dictionary<string, object>
{
{ "TypeId", ID.ProductTypes.ChildrensBike },
{ "Brand", "Votec" },
{ "Color", "green" },
{ "FrameNumber", "1067425379" },
{ "Description", "Votec VRC Comp" },
{ "TireSize", "24" },
{ "Price", 92.99m }
});
postDocument.Title.Should().Be("Acceptance for seller with ID: 1 - Enter products - Velo Basar");
return postDocument;
}

private async Task<IHtmlDocument> EnterProduct2(IHtmlDocument enterProductsDocument)
{
IHtmlFormElement form = enterProductsDocument.QueryForm();
IHtmlButtonElement submitButton = enterProductsDocument.QueryButtonByText("Add");

IHtmlDocument postDocument = await context.HttpClient.SendFormAsync(form, submitButton, new Dictionary<string, object>
{
{ "TypeId", ID.ProductTypes.SteelSteed },
{ "Brand", "KTM" },
{ "Color", "red" },
{ "FrameNumber", "1239209209" },
{ "Description", "Steed 1" },
{ "TireSize", "22" },
{ "Price", 98.89m }
});
postDocument.Title.Should().Be("Acceptance for seller with ID: 1 - Enter products - Velo Basar");
return postDocument;
}

private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
namespace BraunauMobil.VeloBasar.IntegrationTests.Steps.SecondBasar.AcceptSellers;

public class AcceptSellers(TestContext context)
{
public async Task Run()
{
await new Seller2_AcceptAndThenAcceptViaDetails(context).Run();
await new Seller3_CancelOnEnterProducts(context).Run();
await new Seller4(context).Run();
await new Seller5(context).Run();

await AssertBasarDetails();
}

private async Task AssertBasarDetails()
{
BasarSettlementStatus basarSettlementStatus = new(false,
new SellerGroupSettlementStatus(3, 0),
new SellerGroupSettlementStatus(3, 0),
new SellerGroupSettlementStatus(0, 0)
);
BasarDetailsModel expectedDetails = new(new BasarEntity(), basarSettlementStatus)
{
AcceptanceCount = 4,
AcceptedProductsAmount = 909.35M,
AcceptedProductsCount = 9,
AcceptedProductTypesByAmount = [
new ChartDataPoint(96.81M, "Scooter", X.AnyColor),
new ChartDataPoint(69.54M, "E-bike", X.AnyColor),
new ChartDataPoint(117.48M, "Road bike", X.AnyColor),
new ChartDataPoint(151.34M, "Steel steed", X.AnyColor),
new ChartDataPoint(183.53M, "Men's city bike", X.AnyColor),
new ChartDataPoint(183.90M, "Woman's city bike", X.AnyColor),
new ChartDataPoint(106.75M, "Unicycle", X.AnyColor),
],
AcceptedProductTypesByCount = [
new ChartDataPoint(2, "Scooter", X.AnyColor),
new ChartDataPoint(1, "E-bike", X.AnyColor),
new ChartDataPoint(1, "Road bike", X.AnyColor),
new ChartDataPoint(1, "Steel steed", X.AnyColor),
new ChartDataPoint(1, "Men's city bike", X.AnyColor),
new ChartDataPoint(2, "Woman's city bike", X.AnyColor),
new ChartDataPoint(1, "Unicycle", X.AnyColor),
],
LockedProductsCount = 0,
LostProductsCount = 0,
PriceDistribution = [
new ChartDataPoint(1, "$50.00", X.AnyColor),
new ChartDataPoint(1, "$60.00", X.AnyColor),
new ChartDataPoint(2, "$70.00", X.AnyColor),
new ChartDataPoint(1, "$110.00", X.AnyColor),
new ChartDataPoint(2, "$120.00", X.AnyColor),
new ChartDataPoint(1, "$160.00", X.AnyColor),
new ChartDataPoint(1, "$190.00", X.AnyColor),
],
SaleCount = 0,
SaleDistribution = [],
SoldProductsAmount = 0,
SoldProductsCount = 0,
SoldProductTypesByCount = [],
SoldProductTypesByAmount = [],
};

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

0 comments on commit 977e5dc

Please sign in to comment.