Skip to content

Commit

Permalink
Add tests for DocumentModelFactory #237
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacelord-XaN committed Feb 4, 2024
1 parent e455bb4 commit ec24910
Show file tree
Hide file tree
Showing 3 changed files with 484 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ namespace BraunauMobil.VeloBasar.Tests.BusinessLogic.DocumentModelFactoryTests;
public class CreateAcceptanceModel
: TestBase
{
#warning @todo NEXT: With status link, and throw exception
[Fact]
public void NoSellerThrowsInvalidOperationException()
{
// Arrange
TransactionEntity acceptance = Fixture.BuildTransaction()
.Without(transaction => transaction.Seller)
.Create();

// Act
Action act = () => Sut.CreateAcceptanceModel(acceptance);

// Assert
act.Should().Throw<InvalidOperationException>().WithMessage("Cannot create Acceptance Document without Seller");
}

[Fact]
public void NoStatusLink()
Expand All @@ -32,7 +45,7 @@ public void NoStatusLink()
.With(acceptance => acceptance.Seller, seller)
.With(acceptance => acceptance.TimeStamp, X.FirstContactDay.AddHours(2))
.Create();

ProductTypeEntity rennradType = Fixture.BuildProductType()
.With(type => type.Name, "Rennrad")
.Create();
Expand Down Expand Up @@ -69,14 +82,17 @@ public void NoStatusLink()
AcceptanceDocumentModel result = Sut.CreateAcceptanceModel(acceptance);

// Assert
AcceptanceDocumentModel expectedModel = new (
AcceptanceDocumentModel expectedModel = new(
Settings.Acceptance.TitleFormat,
"Wasserau, 05.04.2063",
"VeloBasar_PageNumberFromOverall",
" - powered by https://github.com/braunau-mobil/velo-basar",
Settings.PageMargins,
Settings.Acceptance.SubTitle,
"Hamfast Gamdschie\r\nBeutelsend 4\r\nA457857 Hobbingen\r\n",
@"Hamfast Gamdschie
Beutelsend 4
A457857 Hobbingen
",
"VeloBasar_SellerIdShort_0",
false,
string.Empty,
Expand All @@ -103,4 +119,102 @@ public void NoStatusLink()
);
result.Should().BeEquivalentTo(expectedModel);
}

[Fact]
public void WithStatusLink()
{
// Arrange
Settings.Acceptance.SignatureText = "Unterschrift";
Settings.Acceptance.StatusLinkFormat = "StatusLinkFormat_{0}";

BasarEntity basar = Fixture.BuildBasar()
.With(basar => basar.Name, "4. Basar")
.With(basar => basar.Location, "Wasserau")
.With(basar => basar.Date, X.FirstContactDay)
.Create();

SellerEntity seller = Fixture.BuildSeller()
.With(seller => seller.City, "Hobbingen")
.With(seller => seller.FirstName, "Hamfast")
.With(seller => seller.LastName, "Gamdschie")
.With(seller => seller.Street, "Beutelsend 4")
.With(seller => seller.ZIP, "A457857")
.With(seller => seller.Token, "X1234")
.Create();

TransactionEntity acceptance = Fixture.BuildTransaction(basar)
.With(acceptance => acceptance.Seller, seller)
.With(acceptance => acceptance.TimeStamp, X.FirstContactDay.AddHours(2))
.Create();

ProductTypeEntity rennradType = Fixture.BuildProductType()
.With(type => type.Name, "Rennrad")
.Create();
ProductEntity rennrad = Fixture.BuildProduct()
.With(product => product.Id, 1)
.With(product => product.Brand, "Harlond Räder")
.With(product => product.Color, "blau")
.With(product => product.Description, "Mein tolles Rennrad")
.With(product => product.DonateIfNotSold, false)
.With(product => product.FrameNumber, "123456")
.With(product => product.Price, 12.34m)
.With(product => product.TireSize, "29")
.With(product => product.Type, rennradType)
.Create();
acceptance.Products.Add(new ProductToTransactionEntity { Product = rennrad, Transaction = acceptance });

ProductTypeEntity cityBikeType = Fixture.BuildProductType()
.With(type => type.Name, "City Bike")
.Create();
ProductEntity cityBike = Fixture.BuildProduct()
.With(product => product.Id, 2)
.With(product => product.Brand, "GCB")
.With(product => product.Color, "grün")
.With(product => product.Description, "Das schönste City Bike")
.With(product => product.DonateIfNotSold, true)
.With(product => product.FrameNumber, "XYZ")
.With(product => product.Price, 154.23m)
.With(product => product.TireSize, "28")
.With(product => product.Type, cityBikeType)
.Create();
acceptance.Products.Add(new ProductToTransactionEntity { Product = cityBike, Transaction = acceptance });

// Act
AcceptanceDocumentModel result = Sut.CreateAcceptanceModel(acceptance);

// Assert
AcceptanceDocumentModel expectedModel = new(
Settings.Acceptance.TitleFormat,
"Wasserau, 05.04.2063",
"VeloBasar_PageNumberFromOverall",
" - powered by https://github.com/braunau-mobil/velo-basar",
Settings.PageMargins,
Settings.Acceptance.SubTitle,
"Hamfast Gamdschie\r\nBeutelsend 4\r\nA457857 Hobbingen\r\n",
"VeloBasar_SellerIdShort_0",
true,
"StatusLinkFormat_X1234",
Settings.Acceptance.TokenTitle,
seller.Token,
"Unterschrift ______________________________",
"VeloBasar_AtLocationAndDateAndTime_Wasserau_05.04.2063 13:22:33",
Settings.QrCodeLengthMillimeters,
new ProductsTableDocumentModel(
"VeloBasar_Id",
"VeloBasar_ProductDescription",
"VeloBasar_Size",
"VeloBasar_Price",
"VeloBasar_Sum:",
"VeloBasar_ProductCounter_2",
"€ 166,57",
null,
new[]
{
new ProductTableRowDocumentModel("1", "Harlond Räder - Rennrad\r\nMein tolles Rennrad\r\n blau 123456", "29", "€ 12,34", null),
new ProductTableRowDocumentModel("2", "GCB - City Bike\r\nDas schönste City Bike\r\n grün XYZ\r\nVeloBasar_DonateIfNotSoldOnProductTable\r\n", "28", "€ 154,23", null),
}
)
);
result.Should().BeEquivalentTo(expectedModel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using BraunauMobil.VeloBasar.Models.Documents;

namespace BraunauMobil.VeloBasar.Tests.BusinessLogic.DocumentModelFactoryTests;

public class CreateProductLabelModel
: TestBase
{
[Fact]
public void NoFrameNumberNoTireSize()
{
// Arrange
Settings.Label.TitleFormat = "TitleFormat_{0}";
Settings.Label.MaxDescriptionLength = 30;

ProductTypeEntity productType = Fixture.BuildProductType()
.With(productType => productType.Name, "City-Bike")
.Create();

ProductEntity product = Fixture.BuildProduct()
.With(product => product.Id, 666)
.With(product => product.Brand, "Cube")
.With(product => product.Description, "This is a really great Bike. I like it a lot, but unfortunatley the description is way to long to fit on the tiny label that gets printed out.")
.With(product => product.Type, productType)
.With(product => product.Price, 123.45m)
.Without(product => product.FrameNumber)
.Without(product => product.TireSize)
.Create();
product.Session.Basar.Name = "1. Basar";

// Act
ProductLabelDocumentModel result = Sut.CreateProductLabelModel(product);

// Assert
ProductLabelDocumentModel expectedModel = new(
"TitleFormat_1. Basar",
"Cube - City-Bike",
"This is a really great Bike. I",
product.Color,
null,
null,
"666",
"€ 123,45"
);

result.Should().BeEquivalentTo(expectedModel);
}

[Fact]
public void WithFrameNumberNoTireSize()
{
// Arrange
Settings.Label.TitleFormat = "TitleFormat_{0}";
Settings.Label.MaxDescriptionLength = 30;

ProductTypeEntity productType = Fixture.BuildProductType()
.With(productType => productType.Name, "City-Bike")
.Create();

ProductEntity product = Fixture.BuildProduct()
.With(product => product.Id, 666)
.With(product => product.Brand, "Cube")
.With(product => product.Description, "This is a really great Bike. I like it a lot, but unfortunatley the description is way to long to fit on the tiny label that gets printed out.")
.With(product => product.Type, productType)
.With(product => product.Price, 123.45m)
.With(product => product.FrameNumber, "1234567890")
.Without(product => product.TireSize)
.Create();
product.Session.Basar.Name = "1. Basar";

// Act
ProductLabelDocumentModel result = Sut.CreateProductLabelModel(product);

// Assert
ProductLabelDocumentModel expectedModel = new(
"TitleFormat_1. Basar",
"Cube - City-Bike",
"This is a really great Bike. I",
product.Color,
"VeloBasar_FrameNumberLabel_1234567890",
null,
"666",
"€ 123,45"
);

result.Should().BeEquivalentTo(expectedModel);
}

[Fact]
public void NoFrameNumberWithTireSize()
{
// Arrange
Settings.Label.TitleFormat = "TitleFormat_{0}";
Settings.Label.MaxDescriptionLength = 30;

ProductTypeEntity productType = Fixture.BuildProductType()
.With(productType => productType.Name, "City-Bike")
.Create();

ProductEntity product = Fixture.BuildProduct()
.With(product => product.Id, 666)
.With(product => product.Brand, "Cube")
.With(product => product.Description, "This is a really great Bike. I like it a lot, but unfortunatley the description is way to long to fit on the tiny label that gets printed out.")
.With(product => product.Type, productType)
.With(product => product.Price, 123.45m)
.Without(product => product.FrameNumber)
.With(product => product.TireSize, "28")
.Create();
product.Session.Basar.Name = "1. Basar";

// Act
ProductLabelDocumentModel result = Sut.CreateProductLabelModel(product);

// Assert
ProductLabelDocumentModel expectedModel = new(
"TitleFormat_1. Basar",
"Cube - City-Bike",
"This is a really great Bike. I",
product.Color,
null,
"VeloBasar_TireSizeLabel_28",
"666",
"€ 123,45"
);

result.Should().BeEquivalentTo(expectedModel);
}

[Fact]
public void WithFrameNumberAndTireSize()
{
// Arrange
Settings.Label.TitleFormat = "TitleFormat_{0}";
Settings.Label.MaxDescriptionLength = 30;

ProductTypeEntity productType = Fixture.BuildProductType()
.With(productType => productType.Name, "City-Bike")
.Create();

ProductEntity product = Fixture.BuildProduct()
.With(product => product.Id, 666)
.With(product => product.Brand, "Cube")
.With(product => product.Description, "This is a really great Bike. I like it a lot, but unfortunatley the description is way to long to fit on the tiny label that gets printed out.")
.With(product => product.Type, productType)
.With(product => product.FrameNumber, "ABCD")
.With(product => product.TireSize, "29")
.With(product => product.Price, 123.45m)
.Create();
product.Session.Basar.Name = "1. Basar";

// Act
ProductLabelDocumentModel result = Sut.CreateProductLabelModel(product);

// Assert
ProductLabelDocumentModel expectedModel = new(
"TitleFormat_1. Basar",
"Cube - City-Bike",
"This is a really great Bike. I",
product.Color,
"VeloBasar_FrameNumberLabel_ABCD",
"VeloBasar_TireSizeLabel_29",
"666",
"€ 123,45"
);

result.Should().BeEquivalentTo(expectedModel);
}
}
Loading

0 comments on commit ec24910

Please sign in to comment.