Files
Christoph Schwörer f045b99a25 Codebasis als Dateien ins Arbeitsrepo statt als Gitlink
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
2026-08-26 07:43:51 +02:00

205 lines
7.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Centron.BusinessLogic;
using Centron.BusinessLogic.EmployeeArea;
using Centron.BusinessLogic.Sales.Receipts.DataAndResults;
using Centron.BusinessLogic.WebServices.Sales.Receipts;
using Centron.BusinessLogic.WebServices.Sales.Receipts.DataAndResults;
using Centron.Data.Entities.Administration.Logins;
using Centron.Data.WebServices.Sales.Receipts;
using Centron.Interfaces;
using Centron.Interfaces.Administration.Environment;
using Centron.Interfaces.BL;
using Centron.Interfaces.Sales.Receipts;
using Centron.Interfaces.Sales.Receipts.InsertReceipts;
using Centron.Tests.EndToEnd.Infrastructure;
using CentronSoftware.Centron.WebServices.EntitiesWrongPlace.Sales.Receipts.DataAndResults;
using Xunit.Abstractions;
using Centron.Core.Extensions;
using CentronSoftware.Centron.WebServices.Extensions;
namespace Centron.Tests.EndToEnd.TicketTests.Ticket107258
{
public class Ticket107258Test : EndToEndTest
{
public Ticket107258Test(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}
const int ArticleI3D = 4348;
public override void Execute()
{
this.PrepareDatabase();
// Create delivery-list and invoice
var deliveryList = this.CreateDeliveryList();
var invoice = this.CreateInvoiceFromDeliveryList(deliveryList);
// Create new delivery-list version
var deliveryListVersion = this.CreateNewVersion(CentronObjectKindNumeric.DeliveryListClass, deliveryList.I3D);
// Remove already forwarded position
var items = deliveryListVersion.GetReceiptItems();
items.RemoveWhere(f => f.Kind == ReceiptItemKind.Article);
deliveryListVersion.SetReceiptItems(items);
// Try to save the delivery-list
var result = this.SaveReceipt(deliveryListVersion);
this.Verifier.Verify("CantRemoveForwardedPositionResult", result);
// Set invoice as cancelled
this.Sql($"UPDATE RechKopf SET Status = {(int)ReceiptState.Canceled} WHERE I3D = {invoice.I3D}");
// Try to save the delivery-list again
result = this.SaveReceipt(deliveryListVersion);
this.Verifier.Verify("SavedSuccessfully", result);
}
private ReceiptBaseDTO CreateDeliveryList()
{
// Create delivery-list
var deliveryList = this.CreateNewReceipt(CentronObjectKindNumeric.DeliveryListClass);
// Add position
var items = deliveryList.GetReceiptItems();
var item = this.CreateReceiptItem(deliveryList);
items.Add(item);
deliveryList.SetReceiptItems(items);
// Save delivery-list
return this.SaveReceipt(deliveryList).Data.Receipt;
}
private ReceiptBaseDTO CreateInvoiceFromDeliveryList(ReceiptBaseDTO savedDeliveryList)
{
// Create invoice
var invoice = this.ForwardReceipt(CentronObjectKindNumeric.InvoiceClass, savedDeliveryList);
// Save invoice
return this.SaveReceipt(invoice).Data.Receipt;
}
private void PrepareDatabase()
{
// Oops, I wrote this test using this article I3D
// But now when creating and saving a invoice, I notice that this article needs barcodes...
// So I deactivate it rather than re-create all the *.expected.txt files again
this.Sql($"UPDATE ARTIK SET BarcodeScanen = 0 WHERE I3D = {ArticleI3D}");
// There is no Bankverbindung for the customer 10022 - but we are creating invoices for him
// So we just move the existing Bankverbindung to customer 10022, so he can use it for this test
this.Sql("UPDATE dbo.Bankverbindungen SET ObjectI3D = 10022");
}
private ReceiptBaseDTO CreateNewReceipt(CentronObjectKindNumeric receiptKind)
{
using (var session = new BLSession())
{
var user = session.GetBL<AppUserBL>().GetAppUser(f => f.I3D == 11);
var result = session.GetBL<ReceiptWebServiceBL>().CreateNewReceipt(receiptKind, new LoggedInUser(user), 10022, new CreateReceiptData(), null, null, true, false, true);
return result.Data.Receipt;
}
}
private ReceiptItemBaseDTO CreateReceiptItem(ReceiptBaseDTO receipt)
{
using (var session = new BLSession())
{
var user = session.GetBL<AppUserBL>().GetAppUser(f => f.I3D == 11);
var receiptItemsResult = session.GetBL<ReceiptItemWebServiceBL>().CreateArticleReceiptItems(
receipt,
false,
ArticleI3D,
null,
null,
-1,
new LoggedInUser(user));
return receiptItemsResult.Data.ReceiptItems.Single(f => f.ArticleI3D == ArticleI3D);
}
}
private Result<SaveReceiptResultDTO> SaveReceipt(ReceiptBaseDTO originReceipt)
{
using (var session = new BLSession())
{
var user = session.GetBL<AppUserBL>().GetAppUser(f => f.I3D == 11);
var saveReceiptResult = session.GetBL<ReceiptWebServiceBL>().SaveReceipt(
originReceipt,
user,
new SaveReceiptData { IgnoreCallbacks = true },
autoLockIfNewReceipt: false,
CreatedThroughApplication.WebServices,
receiptTemplateFolderI3D: null);
return saveReceiptResult;
}
}
private ReceiptBaseDTO ForwardReceipt(CentronObjectKindNumeric targetReceiptKind, ReceiptBaseDTO originReceipt)
{
using (var session = new BLSession())
{
var user = session.GetBL<AppUserBL>().GetAppUser(f => f.I3D == 11);
var forwardResult = session.GetBL<ReceiptWebServiceBL>().ForwardReceipt(
targetReceiptKind,
user,
new ForwardReceiptData
{
CreateReceiptData = new CreateReceiptData
{
IgnoreCallbacks = true,
},
CreateReceiptItemsFromExistingItemsData = new List<CreateReceiptItemsFromExistingItemsData>
{
new()
{
IgnoreCallbacks = true,
},
},
IgnoreCallbacks = true
},
new List<ReceiptToForward>
{
new ReceiptToForward
{
ReceiptKind = originReceipt.ReceiptKind,
ReceiptI3D = originReceipt.I3D
}
},
null,
InsertReceiptTakeoverOptions.Reference,
true,
false);
return forwardResult.Data.Receipt;
}
}
private ReceiptBaseDTO CreateNewVersion(CentronObjectKindNumeric receiptKind, int receiptI3D)
{
using (var session = new BLSession())
{
var user = session.GetBL<AppUserBL>().GetAppUser(f => f.I3D == 11);
var createNewVersionResult = session.GetBL<ReceiptWebServiceBL>().CreateNewVersion(
receiptKind,
receiptI3D,
null,
null,
user,
new CreateNewVersionData());
return createNewVersionResult.Data.Receipt;
}
}
}
}