using System; using System.Collections.Generic; using System.Linq; using Centron.Tests.EndToEnd.Infrastructure; using Xunit.Abstractions; using Centron.BusinessLogic.Warehousing.InventoryManagement; using Centron.Data.WebServices.Sales.Receipts.Offers; using Centron.Data.WebServices.Sales.Receipts.Orders; using Centron.Interfaces; using Centron.Interfaces.BL; using Centron.Interfaces.Sales.Receipts.ReceiptSearch; using Centron.BusinessLogic; using Centron.BusinessLogic.WebServices.Sales.Receipts.ReceiptSearch; using Centron.BusinessLogic.EmployeeArea; using Centron.Data.Entities.Administration.Logins; using Centron.BusinessLogic.WebServices.Warehousing.ArticleManagement; using Centron.BusinessLogic.WebServices.Warehousing.InventoryManagement; using Centron.BusinessLogic.WebServices.Sales.Receipts; using Centron.BusinessLogic.WebServices.Warehousing; namespace Centron.Tests.EndToEnd.Tests.ArticleConvert { public class ArticleConvertTest : EndToEndTest { private const int ARTICLEI3D_EXTERNAL = 1; private const int ARTICLEI3D_NEW = 2; public ArticleConvertTest(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { this.ConvertArticleOffer(ARTICLEI3D_EXTERNAL, 20833, true); this.ConvertArticleOffer(ARTICLEI3D_NEW, 18887, false); this.ConvertArticleOrder(ARTICLEI3D_EXTERNAL, 5824,true); this.ConvertArticleOrder(ARTICLEI3D_NEW, 6939,false); } #region Offer private void ConvertArticleOffer(int articleI3D, int articleHistoryI3D, bool isExternal) { var articleHistoryListExternal = this.WithSession(f => f.GetBL().GetArticleOfferHistory(articleI3D)); var articelHistory = articleHistoryListExternal.FirstOrDefault(f => f.I3D == articleHistoryI3D); if (articelHistory == null) { throw new Exception("articleHistory (Offer) is null"); } var user = this.WithSession(d => d.GetBL().GetAppUser(f => f.I3D == 11)); var receipt = this.WithSession(f => f.GetBL().SearchReceipts(new LoggedInUser(user), new ReceiptSearchFilter {ReceiptNumber = articelHistory?.Number}, 1, int.MaxValue)); if (receipt.Status == ResultStatus.Error || receipt.Data == null) { throw new Exception("receipt (Offer) is null"); } var materialFilter = new MaterialGroupFilter() { State = 1, MaterialMarkupsState = 1, SecondaryMaterialGroupsState = 1, SecondaryMaterialMarkupsState = 1 }; var materialGroupList = this.WithSession(f => f.GetBL().GetMaterialGroups(materialFilter)); var selectedMaterialGroup = materialGroupList.FirstOrDefault(f => f.I3D == 1); if (selectedMaterialGroup == null) { throw new Exception("selectedMaterialGroup (Offer) is null"); } var selectedSecondaryMaterialGroup = selectedMaterialGroup.SecMaterialGroupList.FirstOrDefault(); if (selectedSecondaryMaterialGroup == null) { throw new Exception("selectedSecondaryMaterialGroup (Offer) is null"); } var article = this.WithSession(f => f.GetBL().GetNewArticle(new LoggedInUser(user).UserI3D)); article.MaterialGroupI3D = selectedMaterialGroup.I3D; article.SecondaryMaterialGroupI3D = selectedSecondaryMaterialGroup.I3D; article.ArticleCode = articelHistory.ManufacturerCode; article.Description = articelHistory.Text; article.ShortDescription = "Lorem ipsum"; article.ManufacturerCode = article.ManufacturerCode; var filter = new ReceiptSearchFilter() { ReceiptNumber = articleHistoryListExternal.OrderByDescending(f => f.I3D).First().Number, ReceiptKinds = new List() { CentronObjectKindNumeric.OfferClass}, IncludeClosedReceipts = true }; var savedArticle = this.WithSession(f => f.GetBL().SaveArticle(article, new LoggedInUser(user))).Data; if (isExternal) { this.Verifier.Verify("ConvertArticleOfferExternal", savedArticle); var offersBeforeArticleChangeExternal = this.WithSession(f => f.GetBL().SearchReceipts(new LoggedInUser(user), filter, 1, 1)); var receiptI3D = offersBeforeArticleChangeExternal.Data.Result.First().I3D; var offerBeforeChangeExternal = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OfferClass)); this.Verifier.Verify("01_OfferBeforeChangeExternal", offerBeforeChangeExternal); this.WithSession(f => f.GetBL().UpdateArticlePositionFromArticleChange( user, savedArticle.I3D, savedArticle.ArticleCode, savedArticle.ManufacturerCode, 0, //offer & external -> 0 article.ManufacturerCode )); var offerAfterChangeExternal = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OfferClass)); this.Verifier.Verify("02_OfferAfterChangeExternal", offerAfterChangeExternal); } else { this.Verifier.Verify("ConvertArticleOfferNew", savedArticle); var offersBeforeArticleChangeNew = this.WithSession(f => f.GetBL().SearchReceipts(new LoggedInUser(user), filter, 1, int.MaxValue)); var receiptI3D = offersBeforeArticleChangeNew.Data.Result.First().I3D; var offerBeforeChangeNew = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OfferClass)); this.Verifier.Verify("03_OfferBeforeChangeNew", offerBeforeChangeNew); this.WithSession(f => f.GetBL().UpdateArticlePositionFromArticleChange( user, savedArticle.I3D, savedArticle.ArticleCode, savedArticle.ManufacturerCode, 2, //offer & new -> 2 article.ManufacturerCode )); var offerAfterChangeNew = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OfferClass)); this.Verifier.Verify("04_OfferAfterChangeNew", offerAfterChangeNew); } } #endregion #region Order private void ConvertArticleOrder(int articleI3D, int articleHistoryI3D, bool isExternal) { var articleHistoryList = this.WithSession(f => f.GetBL().GetArticleOrderHistory(articleI3D)); var articelHistory = articleHistoryList.FirstOrDefault(f => f.I3D == articleHistoryI3D); if (articelHistory == null) { throw new Exception("no articleHistory (Order) found"); } var user = this.WithSession(d => d.GetBL().GetAppUser(f => f.I3D == 11)); var receipt = this.WithSession(f => f.GetBL().SearchReceipts(new LoggedInUser(user), new ReceiptSearchFilter {ReceiptNumber = articelHistory?.Number}, 1, int.MaxValue)); if (receipt.Status == ResultStatus.Error || receipt.Data == null) { throw new Exception("no receipt (Order) found"); } var materialFilter = new MaterialGroupFilter() { State = 1, MaterialMarkupsState = 1, SecondaryMaterialGroupsState = 1, SecondaryMaterialMarkupsState = 1 }; var materialGroupList = this.WithSession(f => f.GetBL().GetMaterialGroups(materialFilter)); var selectedMaterialGroup = materialGroupList.FirstOrDefault(f => f.I3D == 1); if (selectedMaterialGroup == null) { throw new Exception("selectedMaterialGroup (Order) is null"); } var selectedSecondaryMaterialGroup = selectedMaterialGroup.SecMaterialGroupList.FirstOrDefault(); if (selectedSecondaryMaterialGroup == null) { throw new Exception("selectedSecondaryMaterialGroup (Order) is null"); } var article = this.WithSession(f => f.GetBL().GetNewArticle(new LoggedInUser(user).UserI3D)); article.MaterialGroupI3D = selectedMaterialGroup.I3D; article.SecondaryMaterialGroupI3D = selectedSecondaryMaterialGroup.I3D; article.ArticleCode = articelHistory.ManufacturerCode; article.Description = articelHistory.Text; article.ShortDescription = "Lorem ipsum"; article.ManufacturerCode = article.ManufacturerCode; var savedArticle = this.WithSession(f => f.GetBL().SaveArticle(article, new LoggedInUser(user))).Data; var filter = new ReceiptSearchFilter() { ReceiptNumber = articleHistoryList.OrderByDescending(f => f.I3D).First().Number, ReceiptKinds = new List() { CentronObjectKindNumeric.OrderClass}, IncludeClosedReceipts = true }; if (isExternal) { this.Verifier.Verify("ConvertArticleOrderExternal", savedArticle); var ordersBeforeArticleChangeExternal = this.WithSession(f => f.GetBL().SearchReceipts(new LoggedInUser(user), filter, 1, 1)); var receiptI3D = ordersBeforeArticleChangeExternal.Data.Result.First().I3D; var orderBeforeChangeExternal = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OrderClass)); this.Verifier.Verify("05_OrderBeforeChangeExternal", orderBeforeChangeExternal); this.WithSession(f => f.GetBL().UpdateArticlePositionFromArticleChange( user, savedArticle.I3D, savedArticle.ArticleCode, savedArticle.ManufacturerCode, 1, //order & external -> 1 article.ManufacturerCode )); var orderAfterChangeExternal = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OrderClass)); this.Verifier.Verify("06_OrderAfterChangeExternal", orderAfterChangeExternal); } else { this.Verifier.Verify("ConvertArticleOrderNew", savedArticle); var ordersBeforeArticleChangeNew = this.WithSession(f => f.GetBL().SearchReceipts(new LoggedInUser(user), filter, 1, 1)); var receiptI3D = ordersBeforeArticleChangeNew.Data.Result.First().I3D; var orderBeforeChangeExternal = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OrderClass)); this.Verifier.Verify("07_OrderBeforeChangeExternal", orderBeforeChangeExternal); this.WithSession(f => f.GetBL().UpdateArticlePositionFromArticleChange( user, savedArticle.I3D, savedArticle.ArticleCode, savedArticle.ManufacturerCode, 3, //order & new -> 3 article.ManufacturerCode )); var orderBeforeChangeNew = this.WithSession(f => f.GetBL().GetReceiptByI3D(receiptI3D, CentronObjectKindNumeric.OrderClass)); this.Verifier.Verify("08_OrderBeforeChangeExternal", orderBeforeChangeNew); } } #endregion } }