| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using ProductStore = qdr.app.studiou.orders2printpack.ProductStorage.ProductStorage;
- namespace qdr.app.studiou.orders2printpack.Test
- {
- /// <summary>
- /// Tests around the variant price behaviour when products are imported.
- /// Import creates product variants with Price = 0; the predefined variant
- /// prices (loaded from settings) must survive that, otherwise the user has
- /// to re-enter every price by hand after each import.
- /// </summary>
- [TestFixture]
- public class ProductStorageTests
- {
- // Mirrors how ImportProducts adds a variant: a parent product plus a
- // variation row whose VariantName matches a predefined variant, Price = 0.
- private static void SimulateImportedVariant(ProductStore storage, string parentSku, string variantName, decimal price = 0m)
- {
- var parent = storage.AddNewProduct();
- parent.Sku = parentSku;
- var variant = storage.AddNewProductVariant(parentSku);
- variant.VariantName = variantName;
- variant.Price = price;
- }
- [Test]
- public void Import_DoesNotResetPredefinedVariantPrice()
- {
- // Arrange: predefined variants with prices, as restored from settings.
- var storage = new ProductStore();
- storage.AppendVariantsFromString("Foto 10x15cm=150;Foto 15x23cm=120");
- // Act: import brings in a matching variant priced at 0.
- SimulateImportedVariant(storage, "P1", "Foto 10x15cm", price: 0m);
- var variants = storage.Variants.ToList();
- // Assert: the configured price is kept, not overwritten with 0.
- var imported = variants.Single(x => x.Name == "Foto 10x15cm");
- Assert.That(imported.Price, Is.EqualTo(150m));
- // The untouched predefined variant is unaffected too.
- var other = variants.Single(x => x.Name == "Foto 15x23cm");
- Assert.That(other.Price, Is.EqualTo(120m));
- }
- [Test]
- public void Import_PersistsPredefinedPriceAfterRoundTrip()
- {
- // Arrange
- var storage = new ProductStore();
- storage.AppendVariantsFromString("Foto 10x15cm=150");
- // Act: import (price 0) then serialise as settings would on form close.
- SimulateImportedVariant(storage, "P1", "Foto 10x15cm", price: 0m);
- _ = storage.Variants.ToList();
- var persisted = storage.GetVariantsAsString();
- // Assert: the price written back to settings is still 150, not 0.
- Assert.That(persisted, Does.Contain("Foto 10x15cm=150"));
- }
- [Test]
- public void Variants_StillSyncsRealNonZeroProductPrice()
- {
- // Guard against over-correcting: a genuine non-zero product price
- // must still update the variant, as it did before the fix.
- var storage = new ProductStore();
- storage.AppendVariantsFromString("Foto 10x15cm=150");
- SimulateImportedVariant(storage, "P1", "Foto 10x15cm", price: 99m);
- var imported = storage.Variants.Single(x => x.Name == "Foto 10x15cm");
- Assert.That(imported.Price, Is.EqualTo(99m));
- }
- [Test]
- public void Variants_AddsBrandNewVariantFromImport()
- {
- // A variant name that isn't predefined should still appear in the list.
- var storage = new ProductStore();
- storage.AppendVariantsFromString("Foto 10x15cm=150");
- SimulateImportedVariant(storage, "P1", "Plakát A2", price: 0m);
- var variants = storage.Variants.ToList();
- Assert.That(variants.Select(x => x.Name), Does.Contain("Plakát A2"));
- }
- }
- }
|