QuellCode/CentronERP war nur als Gitlink (Submodul-Referenz auf 79c1142) getrackt, ohne .gitmodules und ohne erreichbares Remote. Der Untersuchungsgegenstand der Versuchsreihe war damit nicht reproduzierbar gesichert: Ein Klon haette ein leeres Verzeichnis erhalten, und die Belege der 3.287 Anforderungen waeren nicht ueberpruefbar gewesen. Umstellung: - Historie nach c:\DEV\CentronERP_git_snapshot_79c1142 ausgelagert (vollstaendig lesbar, enthaelt 79c1142 und Vorgaenger 89ccfd6) - Gitlink aus dem Index entfernt - Dateiinhalt aufgenommen: 24.557 Dateien, rund 333 MB Die verschachtelte .gitignore der Codebasis gilt weiter, Build-Artefakte bleiben ausgeschlossen. Details in Versuche/Versuch_01/_Codebasis-Nachweis.md
442 lines
26 KiB
C#
442 lines
26 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using Centron.BusinessLogic;
|
|
using Centron.BusinessLogic.Mail.Factory;
|
|
using Centron.BusinessLogic.WebServices.Accounts.SpecialPrices;
|
|
using Centron.BusinessLogic.WebServices.Sales.Receipts;
|
|
using Centron.Data.WebServices.Sales.Receipts.Orders;
|
|
using Centron.Interfaces;
|
|
using Centron.Interfaces.Accounts.SpecialPrices;
|
|
using Centron.Interfaces.BL;
|
|
using Centron.Tests.EndToEnd.Infrastructure;
|
|
using CentronSoftware.Centron.WebServices.Entities.Accounts.SpecialPrices;
|
|
using CentronSoftware.Centron.WebServices.Entities.Sales.Receipts;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Centron.Tests.EndToEnd.Tests.ReceiptCarts;
|
|
|
|
public class ReceiptCartTests : EndToEndTest
|
|
{
|
|
public ReceiptCartTests(ITestOutputHelper testOutputHelper)
|
|
: base(testOutputHelper)
|
|
{
|
|
this.Verifier.Settings.IgnoreColumn("Date");
|
|
this.Verifier.Settings.IgnoreColumn("CreatedAt");
|
|
this.Verifier.Settings.IgnoreColumn("ChangedAt");
|
|
this.Verifier.Settings.IgnoreColumn("ReminderDate");
|
|
this.Verifier.Settings.IgnoreColumn("ConcurrencyControlGuid");
|
|
this.Verifier.Settings.IgnoreColumn("RichText");
|
|
this.Verifier.Settings.IgnoreColumn("PaymentConditionText");
|
|
this.Verifier.Settings.IgnoreColumn("ToDoI3D");
|
|
this.Verifier.Settings.IgnoreColumn("CreatedThroughApplicationVersion");
|
|
this.Verifier.Settings.IgnoreColumn("ChangedThroughApplicationVersion");
|
|
this.Verifier.Settings.IgnoreColumn("CreatedDate");
|
|
this.Verifier.Settings.IgnoreColumn("ChangedDate");
|
|
this.Verifier.Settings.IgnoreColumn("GeaendertVersion");
|
|
this.Verifier.Settings.IgnoreColumn("ChangedVersion");
|
|
this.Verifier.Settings.IgnoreColumn("GeaendertDatum");
|
|
this.Verifier.Settings.IgnoreColumn("AnlaDatum");
|
|
this.Verifier.Settings.IgnoreColumn("ErstelltVersion");
|
|
this.Verifier.Settings.IgnoreColumn("CreatedVersion");
|
|
}
|
|
|
|
private const int ArticleI3D = 80;
|
|
|
|
public override void Execute()
|
|
{
|
|
this.PrepareDatabase();
|
|
|
|
var cart = this.CreateCart(1);
|
|
var allCarts1 = this.GetAllCarts(2);
|
|
this.UpdateCart(3, cart);
|
|
this.DeleteCart(4, cart);
|
|
var otherCart = this.CreateCart(5);
|
|
var allCarts2 = this.GetAllCarts(6);
|
|
this.AddArticlesToCart(7, otherCart);
|
|
var otherCartUpdated = this.AddArticlesToCart(8, otherCart); //lets add the same articles again, they should get merged into 1 item
|
|
this.UpdateArticleInCart(9, otherCartUpdated);
|
|
this.RemoveArticleFromCart(10, otherCartUpdated);
|
|
|
|
this.CanNotDoStupidThings(11);
|
|
|
|
this.SearchArticles(12);
|
|
|
|
this.DuplicateCart(13);
|
|
|
|
this.TestUsers(14);
|
|
|
|
this.TestAddresses(15);
|
|
|
|
this.TestArticleImport(16);
|
|
|
|
this.TestPdfExport(17);
|
|
}
|
|
|
|
private void PrepareDatabase()
|
|
{
|
|
// Create some special-prices for 2 customers, so we can test
|
|
using var session = new BLSession();
|
|
session.GetBL<AccountSpecialPriceWebServiceBL>().SaveAccountSpecialPrice(this.GetLoggedInUser().User, new AccountSpecialPriceDTO
|
|
{
|
|
ObjectKind = CentronObjectKindNumeric.CustomerClass,
|
|
ObjectI3D = 10000,
|
|
ValueKind = SpecialPriceKind.ReduceListPrice,
|
|
Value = 10,
|
|
ArticleI3D = ArticleI3D,
|
|
CreatedByI3D = 1,
|
|
CreatedDate = new DateTime(2022, 1, 1)
|
|
});
|
|
session.GetBL<AccountSpecialPriceWebServiceBL>().SaveAccountSpecialPrice(this.GetLoggedInUser().User, new AccountSpecialPriceDTO
|
|
{
|
|
ObjectKind = CentronObjectKindNumeric.CustomerClass,
|
|
ObjectI3D = 10012,
|
|
ValueKind = SpecialPriceKind.ReduceListPrice,
|
|
Value = 10,
|
|
ArticleI3D = ArticleI3D,
|
|
CreatedByI3D = 1,
|
|
CreatedDate = new DateTime(2022, 1, 1)
|
|
});
|
|
|
|
// Set a easy list-price to calculate with
|
|
this.Sql($"UPDATE dbo.ARTIK SET Listenpreis = 600, WebCartAdditionalInfo = 'Heyaaa' WHERE I3D = {ArticleI3D}");
|
|
|
|
// Prepare a external-article that provides available quantities from the distributor
|
|
var settings = session.GetBL<ReceiptCartWebServiceBL>().GetWebCartSettings(this.GetLoggedInUser());
|
|
settings.DistributorI3DForAdditionalData = 90;
|
|
settings.CartOrderedEmailSender = "test-from@c-entron.de";
|
|
settings.CartOrderedInternalEmailReceiver = "vertrieb@c-entron.de";
|
|
session.GetBL<ReceiptCartWebServiceBL>().UpdateWebCartSettings(settings);
|
|
|
|
this.Sql($"UPDATE dbo.HerstellerArtik SET Code = 'KU206ET#ABD', Datenblatt = 'http://google.de', Bild = 'https://www.google.de/logos/doodles/2022/seasonal-holidays-2022-6753651837109831.7-ladc.gif' WHERE I3D0 = 4771366");
|
|
}
|
|
|
|
private ReceiptCartDTO CreateCart(int step)
|
|
{
|
|
using var session = new BLSession();
|
|
var newCart = session.GetBL<ReceiptCartWebServiceBL>().CreateNewCart(this.GetLoggedInUserWebAccount(), null, null);
|
|
|
|
this.Verifier.Verify($"{step}_NewCart", newCart);
|
|
|
|
return newCart;
|
|
}
|
|
|
|
private List<ReceiptCartDTO> GetAllCarts(int step)
|
|
{
|
|
using var session = new BLSession();
|
|
var allCarts = session.GetBL<ReceiptCartWebServiceBL>().GetAllCarts(this.GetLoggedInUserWebAccount());
|
|
|
|
this.Verifier.Verify($"{step}_AllCarts", allCarts);
|
|
|
|
if (allCarts.Any())
|
|
{
|
|
this.Verifier.VerifySql($"{step}_Offers", $"SELECT * FROM dbo.Offers O WHERE O.I3D IN ({string.Join(", ", allCarts.Select(f => f.I3D))})");
|
|
this.Verifier.VerifySql($"{step}_OfferItems", $"SELECT * FROM dbo.OfferItems OI WHERE OI.ReceiptI3D IN ({string.Join(", ", allCarts.Select(f => f.I3D))})");
|
|
}
|
|
|
|
return allCarts;
|
|
}
|
|
|
|
private void UpdateCart(int step, ReceiptCartDTO cart)
|
|
{
|
|
using var session = new BLSession();
|
|
|
|
var updateCartInfo = new UpdateCartInfoDTO
|
|
{
|
|
Name = "Neue Hardware für Abteilung Einkauf",
|
|
Description = "Test-Beschreibung",
|
|
|
|
ProjectNumber = "Projektnummer",
|
|
PurchaseOrderNumber = "Bestellnummer",
|
|
AssembleArticles = true,
|
|
IsPartialDeliveryPossible = true,
|
|
|
|
DeliveryAddressZip = "89186",
|
|
DeliveryAddressCity = "Vöhringen",
|
|
DeliveryAddressStreet = "Wielandstraße 12",
|
|
DeliveryAddressFirstName = "Jürgen",
|
|
DeliveryAddressLastName = "Fetzer",
|
|
DeliveryAddressDepartment = "1. Stock liefern bitte danke",
|
|
DeliveryAddressCountryI3D = 2,
|
|
DeliveryAddressSalutationI3D = 2,
|
|
};
|
|
session.GetBL<ReceiptCartWebServiceBL>().UpdateCartInfo(cart.I3D, updateCartInfo, this.GetLoggedInUserWebAccount());
|
|
this.GetAllCarts(step);
|
|
}
|
|
|
|
private void DeleteCart(int step, ReceiptCartDTO cart)
|
|
{
|
|
using var session = new BLSession();
|
|
session.GetBL<ReceiptCartWebServiceBL>().DeleteCart(cart.I3D, this.GetLoggedInUserWebAccount());
|
|
this.GetAllCarts(step);
|
|
}
|
|
|
|
private ReceiptCartDTO AddArticlesToCart(int step, ReceiptCartDTO cart)
|
|
{
|
|
using var session = new BLSession();
|
|
session.GetBL<ReceiptCartWebServiceBL>().AddArticleToCart(cart.I3D, ArticleI3D, 1, this.GetLoggedInUserWebAccount());
|
|
return this.GetAllCarts(step).First(f => f.I3D == cart.I3D);
|
|
}
|
|
|
|
private void UpdateArticleInCart(int step, ReceiptCartDTO cart)
|
|
{
|
|
var cartItemI3D = cart.Items.First(f => f.ArticleI3D == ArticleI3D).I3D;
|
|
|
|
using var session = new BLSession();
|
|
session.GetBL<ReceiptCartWebServiceBL>().UpdateArticleInfo(cart.I3D, cartItemI3D, new UpdateArticleInfoDTO { Quantity = 20, Description = "Beschreibung beim Artikel" }, this.GetLoggedInUserWebAccount());
|
|
this.GetAllCarts(step);
|
|
}
|
|
|
|
private void RemoveArticleFromCart(int step, ReceiptCartDTO cart)
|
|
{
|
|
var cartItemI3D = cart.Items.First(f => f.ArticleI3D == ArticleI3D).I3D;
|
|
|
|
using var session = new BLSession();
|
|
session.GetBL<ReceiptCartWebServiceBL>().RemoveArticleFromCart(cart.I3D, cartItemI3D, this.GetLoggedInUserWebAccount());
|
|
this.GetAllCarts(step);
|
|
}
|
|
|
|
private void CanNotDoStupidThings(int step)
|
|
{
|
|
const int DeactivatedCartI3D = 6751;
|
|
|
|
var (cartA, cartB) = PrepareDatabase();
|
|
|
|
// CreateNewCart
|
|
AssertException<ArgumentNullException>(f => f.CreateNewCart(null, null, null)); // Invalid user parameter
|
|
AssertException<ArgumentException>(f => f.CreateNewCart(this.GetLoggedInUser(), null, null), "Only web-account logins can create carts.");
|
|
|
|
// UpdateCartInfo
|
|
var updateCartInfo = new UpdateCartInfoDTO { Name = "Neuer Name" };
|
|
AssertException<ArgumentException>(f => f.UpdateCartInfo(-1, updateCartInfo, this.GetLoggedInUserWebAccount())); // Negative cartI3D
|
|
AssertException<ArgumentException>(f => f.UpdateCartInfo(0, updateCartInfo, this.GetLoggedInUserWebAccount())); // cartI3D is 0
|
|
AssertException<ArgumentNullException>(f => f.UpdateCartInfo(cartA.I3D, null, this.GetLoggedInUserWebAccount())); // updateCartInfo is null
|
|
AssertException<ArgumentException>(f => f.UpdateCartInfo(cartA.I3D, new UpdateCartInfoDTO(), this.GetLoggedInUserWebAccount())); // both newName and newDescription are NULL
|
|
AssertException<ArgumentNullException>(f => f.UpdateCartInfo(cartA.I3D, updateCartInfo, null)); // currentUser is null
|
|
AssertException<ArgumentException>(f => f.UpdateCartInfo(cartA.I3D, updateCartInfo, this.GetLoggedInUser()), "Only web-account logins can update carts.");
|
|
AssertException<ResultException>(f => f.UpdateCartInfo(999999, updateCartInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // cartI3D does not exist
|
|
AssertException<ResultException>(f => f.UpdateCartInfo(cartB.I3D, updateCartInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use cartI3D from another customer
|
|
AssertException<ResultException>(f => f.UpdateCartInfo(25, updateCartInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use a OfferI3D as cartI3D, that has "IsCart" set to false
|
|
AssertException<ResultException>(f => f.UpdateCartInfo(DeactivatedCartI3D, updateCartInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // the cartI3D is already deactivated
|
|
|
|
// DeleteCart
|
|
AssertException<ArgumentException>(f => f.DeleteCart(-1, this.GetLoggedInUserWebAccount())); // negative cartI3D
|
|
AssertException<ArgumentException>(f => f.DeleteCart(0, this.GetLoggedInUserWebAccount())); // cartI3D is 0
|
|
AssertException<ArgumentNullException>(f => f.DeleteCart(1, null)); // currentUser is null
|
|
AssertException<ArgumentException>(f => f.DeleteCart(1, this.GetLoggedInUser()), "Only web-account logins can delete carts.");
|
|
AssertException<ResultException>(f => f.DeleteCart(cartB.I3D, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use cartI3D from another customer
|
|
AssertException<ResultException>(f => f.DeleteCart(25, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use a OfferI3D as cartI3D, that has "IsCart" set to false
|
|
AssertException<ResultException>(f => f.DeleteCart(DeactivatedCartI3D, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // this cartI3D is already deactivated
|
|
|
|
// GetAllCarts
|
|
AssertException<ArgumentNullException>(f => f.GetAllCarts(null)); // currentUser is null
|
|
AssertException<ArgumentException>(f => f.GetAllCarts(this.GetLoggedInUser()), "Only web-account logins can get carts."); // currentUser is not a
|
|
AssertException<Exception>(f =>
|
|
{
|
|
var webAccountACarts = f.GetAllCarts(this.GetLoggedInUserWebAccount());
|
|
var webAccountBCarts = f.GetAllCarts(this.GetLoggedInUserWebAccount(8));
|
|
|
|
var noWebAccountAinB = webAccountACarts.All(f => webAccountBCarts.Any(d => d.I3D == f.I3D) == false);
|
|
var noWebAccountBinA = webAccountBCarts.All(f => webAccountACarts.Any(d => d.I3D == f.I3D) == false);
|
|
if (noWebAccountAinB && noWebAccountBinA)
|
|
throw new Exception();
|
|
});
|
|
|
|
// AddArticleToCart
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(-1, ArticleI3D, 1, this.GetLoggedInUserWebAccount())); // negative cartI3D
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(0, ArticleI3D, 1, this.GetLoggedInUserWebAccount())); // cartI3D is 0
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(cartA.I3D, -1, 1, this.GetLoggedInUserWebAccount())); // negative articleI3D
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(cartA.I3D, 0, 1, this.GetLoggedInUserWebAccount())); // articleI3D is 0
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(cartA.I3D, ArticleI3D, -1, this.GetLoggedInUserWebAccount())); // negative quantity
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(cartA.I3D, ArticleI3D, 0, this.GetLoggedInUserWebAccount())); // quantity is 0
|
|
AssertException<ArgumentNullException>(f => f.AddArticleToCart(cartA.I3D, ArticleI3D, 1, null)); // currentUser is null
|
|
AssertException<ArgumentException>(f => f.AddArticleToCart(cartA.I3D, ArticleI3D, 1, this.GetLoggedInUser()), "Only web-account logins can modify carts.");
|
|
AssertException<ResultException>(f => f.AddArticleToCart(cartB.I3D, ArticleI3D, 1, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use cartI3D from another customer
|
|
AssertException<ResultException>(f => f.AddArticleToCart(25, ArticleI3D, 1, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use a OfferI3D as cartI3D, that has "IsCart" set to false
|
|
AssertException<ResultException>(f => f.AddArticleToCart(DeactivatedCartI3D, ArticleI3D, 1, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // this cartI3D is already deactivated
|
|
AssertException<ResultException>(f => f.AddArticleToCart(cartA.I3D, 111, 1, this.GetLoggedInUserWebAccount()), "Dieser Artikel darf nicht in einen Warenkorb hinzugefügt werden."); // articleI3D that is not available to the customer through special-prices
|
|
|
|
// UpdateArticleQuantityInCart
|
|
var updateArticleInfo = new UpdateArticleInfoDTO { Quantity = 4 };
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(-1, cartA.Items[0].I3D, updateArticleInfo, this.GetLoggedInUserWebAccount())); // negative cartI3D
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(0, cartA.Items[0].I3D, updateArticleInfo, this.GetLoggedInUserWebAccount())); // cartI3D is 0
|
|
AssertException<ArgumentNullException>(f => f.UpdateArticleInfo(cartA.I3D, cartA.Items[0].I3D, null, this.GetLoggedInUserWebAccount())); // articleInfo is null
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(cartA.I3D, -1, updateArticleInfo, this.GetLoggedInUserWebAccount())); // negative itemI3D
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(cartA.I3D, 0, updateArticleInfo, this.GetLoggedInUserWebAccount())); // itemI3D is 0
|
|
AssertException<ResultException>(f => f.UpdateArticleInfo(cartA.I3D, 999, updateArticleInfo, this.GetLoggedInUserWebAccount()), "Der entsprechende Artikel wurde nicht im Warenkorb gefunden."); // itemI3D is invalid
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(cartA.I3D, cartA.Items[0].I3D, new UpdateArticleInfoDTO { Quantity = -1 }, this.GetLoggedInUserWebAccount())); // negative quantity
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(cartA.I3D, cartA.Items[0].I3D, new UpdateArticleInfoDTO { Quantity = 0 }, this.GetLoggedInUserWebAccount())); // quantity is 0
|
|
AssertException<ArgumentNullException>(f => f.UpdateArticleInfo(cartA.I3D, cartA.Items[0].I3D, updateArticleInfo, null)); // currentUser is null
|
|
AssertException<ArgumentException>(f => f.UpdateArticleInfo(cartA.I3D, cartA.Items[0].I3D, updateArticleInfo, this.GetLoggedInUser()), "Only web-account logins can modify carts.");
|
|
AssertException<ResultException>(f => f.UpdateArticleInfo(cartB.I3D, cartA.Items[0].I3D, updateArticleInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use cartI3D from another customer
|
|
AssertException<ResultException>(f => f.UpdateArticleInfo(25, ArticleI3D, updateArticleInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use a OfferI3D as cartI3D, that has "IsCart" set to false
|
|
AssertException<ResultException>(f => f.UpdateArticleInfo(DeactivatedCartI3D, ArticleI3D, updateArticleInfo, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // this cartI3D is already deactivated
|
|
|
|
// RemoveArticleFromCart
|
|
AssertException<ArgumentException>(f => f.RemoveArticleFromCart(-1, cartA.Items[0].I3D, this.GetLoggedInUserWebAccount())); // negative cartI3D
|
|
AssertException<ArgumentException>(f => f.RemoveArticleFromCart(0, cartA.Items[0].I3D, this.GetLoggedInUserWebAccount())); // cartI3D is 0
|
|
AssertException<ArgumentException>(f => f.RemoveArticleFromCart(cartA.I3D, -1, this.GetLoggedInUserWebAccount())); // negative itemI3D
|
|
AssertException<ArgumentException>(f => f.RemoveArticleFromCart(cartA.I3D, 0, this.GetLoggedInUserWebAccount())); // itemI3D is 0
|
|
AssertException<ResultException>(f => f.RemoveArticleFromCart(cartA.I3D, 999, this.GetLoggedInUserWebAccount()), "Der entsprechende Artikel wurde nicht im Warenkorb gefunden."); // itemI3D is invalid
|
|
AssertException<ArgumentNullException>(f => f.RemoveArticleFromCart(cartA.I3D, cartA.Items[0].I3D, null)); // currentUser is null
|
|
AssertException<ArgumentException>(f => f.RemoveArticleFromCart(cartA.I3D, cartA.Items[0].I3D, this.GetLoggedInUser()), "Only web-account logins can modify carts.");
|
|
AssertException<ResultException>(f => f.RemoveArticleFromCart(cartB.I3D, cartA.Items[0].I3D, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use cartI3D from another customer
|
|
AssertException<ResultException>(f => f.RemoveArticleFromCart(25, ArticleI3D, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // use a OfferI3D as cartI3D, that has "IsCart" set to false
|
|
AssertException<ResultException>(f => f.RemoveArticleFromCart(DeactivatedCartI3D, ArticleI3D, this.GetLoggedInUserWebAccount()), "Der Warenkorb wurde nicht gefunden."); // this cartI3D is already deactivated
|
|
|
|
(ReceiptCartDTO cartA, ReceiptCartDTO cartB) PrepareDatabase()
|
|
{
|
|
var firstCart = this.WithSession(session => session.GetBL<ReceiptCartWebServiceBL>().CreateNewCart(this.GetLoggedInUserWebAccount(), null, null));
|
|
this.WithSession(session => session.GetBL<ReceiptCartWebServiceBL>().AddArticleToCart(firstCart.I3D, ArticleI3D, 2, this.GetLoggedInUserWebAccount()));
|
|
var updatedFirstCart = this.WithSession(session => session.GetBL<ReceiptCartWebServiceBL>().GetAllCarts(this.GetLoggedInUserWebAccount())).First(f => f.I3D == firstCart.I3D);
|
|
|
|
var secondCart = this.WithSession(session => session.GetBL<ReceiptCartWebServiceBL>().CreateNewCart(this.GetLoggedInUserWebAccount(8), null, null));
|
|
this.WithSession(session => session.GetBL<ReceiptCartWebServiceBL>().AddArticleToCart(secondCart.I3D, ArticleI3D, 2, this.GetLoggedInUserWebAccount(8)));
|
|
var updatedSecondCart = this.WithSession(session => session.GetBL<ReceiptCartWebServiceBL>().GetAllCarts(this.GetLoggedInUserWebAccount(8))).First(f => f.I3D == secondCart.I3D);
|
|
|
|
return (updatedFirstCart, updatedSecondCart);
|
|
}
|
|
|
|
void AssertException<T>(Action<ReceiptCartWebServiceBL> action, string exceptionMessage = null)
|
|
where T : Exception
|
|
{
|
|
this.WithSession(session =>
|
|
{
|
|
var exception = Assert.Throws<T>(() =>
|
|
{
|
|
action(session.GetBL<ReceiptCartWebServiceBL>());
|
|
});
|
|
|
|
if (exceptionMessage is not null)
|
|
Assert.Equal(exceptionMessage, exception.Message);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void SearchArticles(int step)
|
|
{
|
|
using var session = new BLSession();
|
|
|
|
var articles = session.GetBL<ReceiptCartWebServiceBL>().SearchArticles(string.Empty, null, 1, int.MaxValue, this.GetLoggedInUserWebAccount());
|
|
this.Verifier.Verify($"{step}_AllArticles", articles);
|
|
|
|
var page1 = session.GetBL<ReceiptCartWebServiceBL>().SearchArticles(string.Empty, 1, 1, 2, this.GetLoggedInUserWebAccount());
|
|
this.Verifier.Verify($"{step}_Page1Articles", page1);
|
|
|
|
var page2 = session.GetBL<ReceiptCartWebServiceBL>().SearchArticles(string.Empty, 1.5m, 2, 2, this.GetLoggedInUserWebAccount());
|
|
this.Verifier.Verify($"{step}_Page2Articles", page2);
|
|
}
|
|
|
|
private void DuplicateCart(int step)
|
|
{
|
|
// Prepare a cart
|
|
var allCarts = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().GetAllCarts(this.GetLoggedInUserWebAccount()));
|
|
var currentCart = allCarts.Last().I3D;
|
|
|
|
var updateCartInfoDto = new UpdateCartInfoDTO
|
|
{
|
|
PurchaseOrderNumber = "Bestellnummer",
|
|
ProjectNumber = "Projektnummer",
|
|
AssembleArticles = true,
|
|
IsPartialDeliveryPossible = true,
|
|
DeliveryAddressFirstName = "Günther",
|
|
DeliveryAddressLastName = "Netzer",
|
|
DeliveryAddressStreet = "Musterstraße 1",
|
|
DeliveryAddressZip = "12345",
|
|
DeliveryAddressCity = "Musterstadt",
|
|
DeliveryAddressDepartment = "Beschreibung blabla",
|
|
DeliveryAddressCountryI3D = 2,
|
|
DeliveryAddressSalutationI3D = 2,
|
|
};
|
|
var updatedCart = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().UpdateCartInfo(currentCart, updateCartInfoDto, this.GetLoggedInUserWebAccount()));
|
|
this.Verifier.Verify($"{step}_OriginalCart", updatedCart);
|
|
|
|
var duplicate = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().DuplicateExistingCart(updatedCart.I3D, "New Name", this.GetLoggedInUserWebAccount()));
|
|
this.Verifier.Verify($"{step}_DuplicateCart", duplicate);
|
|
}
|
|
|
|
private void TestUsers(int step)
|
|
{
|
|
var users = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().GetAllUsers(this.GetLoggedInUserWebAccount()));
|
|
var user = users.First();
|
|
VerifyReceiptCartUser(user, "Before");
|
|
|
|
user.Username = "johndoe";
|
|
user.EmailAddress = "tester@test.de";
|
|
user.FirstName = "John";
|
|
user.LastName = "Doe";
|
|
user.HasCheckCartRight = true;
|
|
user.HasOrderCartRight = true;
|
|
user.HasCustomerAdministratorRight = true;
|
|
|
|
var saveResult = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().SaveUser(user, null, this.GetLoggedInUserWebAccount()));
|
|
VerifyReceiptCartUser(saveResult, "After");
|
|
|
|
var updatePasswordResult = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().SaveUser(saveResult, "new-password", this.GetLoggedInUserWebAccount()));
|
|
VerifyReceiptCartUser(updatePasswordResult, "AfterPasswordChange");
|
|
|
|
var newUser = new ReceiptCartUserDTO
|
|
{
|
|
I3D = 0,
|
|
Username = "Testerlei",
|
|
FirstName = "Tester",
|
|
LastName = "Lei",
|
|
EmailAddress = "tester@c-entron.de",
|
|
IsActive = true,
|
|
HasCheckCartRight = true,
|
|
HasOrderCartRight = false
|
|
};
|
|
var newUserResult = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().SaveUser(newUser, "some-password", this.GetLoggedInUserWebAccount()));
|
|
VerifyReceiptCartUser(newUserResult, "NewUser");
|
|
|
|
void VerifyReceiptCartUser(ReceiptCartUserDTO theUser, string label)
|
|
{
|
|
var webAccountI3D = this.Sql<int>($"SELECT I3D FROM dbo.WebAccounts WHERE PersonenI3D = {theUser.I3D}");
|
|
|
|
this.Verifier.Verify($"{step}_{label}_User", theUser);
|
|
this.Verifier.VerifySql($"{step}_{label}_WebAccounts", $"SELECT * FROM dbo.WebAccounts WHERE I3D = {webAccountI3D}");
|
|
this.Verifier.VerifySql($"{step}_{label}_AccountAddressContacts", $"SELECT * FROM dbo.AccountAddressContacts WHERE I3D = (SELECT AccountAddressContactI3D FROM dbo.WebAccounts WHERE I3D = {webAccountI3D})");
|
|
this.Verifier.VerifySql($"{step}_{label}_Personen", $"SELECT * FROM dbo.Personen WHERE I3D = {theUser.I3D}");
|
|
this.Verifier.VerifySql($"{step}_{label}_WebAccountRights", $"SELECT * FROM dbo.WebAccountsRights WHERE WebAccountsI3D = {webAccountI3D}");
|
|
}
|
|
}
|
|
|
|
private void TestAddresses(int step)
|
|
{
|
|
var addresses = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().GetAvailableDeliveryAddresses(this.GetLoggedInUserWebAccount()));
|
|
this.Verifier.Verify($"{step}_Addresses", addresses);
|
|
}
|
|
|
|
private void TestArticleImport(int step)
|
|
{
|
|
const int CartI3D = 6752;
|
|
|
|
var articles = new List<ReceiptCartArticleImportDTO>()
|
|
{
|
|
new()
|
|
{
|
|
ManufacturerCode = "KU206ET#ABD",
|
|
Quantity = 10
|
|
},
|
|
new()
|
|
{
|
|
ManufacturerCode = "KU206ET#ABD",
|
|
Quantity = 5
|
|
},
|
|
};
|
|
|
|
var importResult = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().ImportArticlesToCart(CartI3D, articles, this.GetLoggedInUserWebAccount()));
|
|
this.Verifier.Verify($"{step}_ImportResult", importResult);
|
|
}
|
|
|
|
private void TestPdfExport(int step)
|
|
{
|
|
const int CartI3D = 6752;
|
|
|
|
var exportResult = this.WithSession(s => s.GetBL<ReceiptCartWebServiceBL>().GetCartAsPdf(CartI3D, reportName:null, this.GetLoggedInUserWebAccount()));
|
|
Assert.NotNull(exportResult);
|
|
Assert.NotEmpty(exportResult);
|
|
}
|
|
} |