using Centron.BusinessLogic; using Centron.BusinessLogic.WebServices.Administration.FileManagement; using Centron.Data.WebServices.Administration.FileManagement; using Centron.Interfaces; using Centron.Interfaces.Administration.Documents; using Centron.Tests.EndToEnd.Infrastructure; using System.Collections.Generic; using System.Linq; using Xunit; using Xunit.Abstractions; using Centron.Core.Extensions; namespace Centron.Tests.EndToEnd.Tests.Documents { public class DocumentsTests : EndToEndTest { private int _referenceDirectoryI3D => 2093; private int _referenceReceiptI3D => 242; private int _referenceDocumentI3D; private int _referenceDocument2I3D; public DocumentsTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { // need to be ignored so we don't get an actual version from the assembly which is always different this.Verifier.Settings.IgnoreProperty(f => f.ChangedVersion); this.Verifier.Settings.IgnoreProperty(f => f.CreatedVersion); } public override void Execute() { // there are no documents in the testDB at all, so we first have to create them // so we have to be careful with our order of operations: create->work with it->delete this.AddDocumentToDirectory(); this.AddDocumentWithInvalidName(); this.AddDocumentToSpecialDirectory(); this.GetDocumentsByDirectory(1); this.GetDocumentMetaInformations(); this.GetDocument(); this.UpdateFlags(); this.RenameDocument(); this.NewDocumentVersion(); this.CheckOutDocument(); this.CheckInDocument(); this.UndoCheckOutDocument(); this.DeleteDocument(); // rerun documentsbydirectory to ensure that we have the correct documents after everything we did this.GetDocumentsByDirectory(2); } private void AddDocumentToDirectory() { using (var session = new BLSession()) { var result = session.GetBL().AddDocumentToDirectory(this.GetLoggedInUser(), this._referenceDirectoryI3D, new byte[] { 1,2,3,4,5,6,7,8,10,11,12,13,14,15 }, "ibims1bildchen", new List { new DocumentMetaInformationDTO { Type = DocumentMetaInformationType.ReceiptNumber, TypeName = "ibims1receiptnumber", Value = "123" }, new DocumentMetaInformationDTO { Type = DocumentMetaInformationType.SupplierI3D, TypeName = "ibims1supplieri3d", Value = "123" } }, fileObjectKind:CentronObjectKindNumeric.Chat); this._referenceDocumentI3D = result.I3D; } } private void AddDocumentWithInvalidName() { // this is specifically to test handling of Centron.Core.StringExtensions.ConvertToAscii() var asciiConvertedStrings = new List() { "üöua", "?.!bkalsdfjÄÖÜ", "japaneseこんにちはsentence" // this is wild }.Select(f => f.ConvertToAscii()).ToList(); this.Verifier.Verify("AsciiConvertedStrings", asciiConvertedStrings); int documentI3D; using (var session = new BLSession()) { documentI3D = session.GetBL().AddDocumentToDirectory(this.GetLoggedInUser(), this._referenceDirectoryI3D, new byte[] { 1,2,3,4,5,6,7,8,10,11,12,13,14,15 }, "yeshälloümööf").I3D; } using (var session = new BLSession()) { var resultDocument = session.GetBL().GetDocument(this.GetLoggedInUser(), documentI3D).Data; this.Verifier.Verify("DocumentWithAdjustedName", resultDocument); } } private void AddDocumentToSpecialDirectory() { using (var session = new BLSession()) { // this writes the document into the same directory as the AddDocumentToDirectory() does, just via a different method var result = session.GetBL().AddDocumentToSpecialDirectory(this.GetLoggedInUser(), "ibims2bildchen", new byte[] { 1,2,3,4,5,6,7,8,10,11,12,13,14,15 }, this._referenceReceiptI3D, CentronObjectKindNumeric.OrderClass, new List { new DocumentMetaInformationDTO { Type = DocumentMetaInformationType.ReceiptNumber, TypeName = "ibims2receiptnumber", Value = "456" }, new DocumentMetaInformationDTO { Type = DocumentMetaInformationType.SupplierI3D, TypeName = "ibims2supplieri3d", Value = "456" } }); this._referenceDocument2I3D = result.I3D; } } private void GetDocumentsByDirectory(int version) { using (var session = new BLSession()) { var documents = session.GetBL().GetDocumentsFromDirectory(this.GetLoggedInUser(), this._referenceDirectoryI3D); this.Verifier.Verify("DocumentsFromDirectory" + version, documents); } using (var session = new BLSession()) { var documents = session.GetBL().GetDocumentsByDirectory(this._referenceDirectoryI3D); this.Verifier.Verify("DocumentsByDirectory" + version, documents); } } private void GetDocumentMetaInformations() { using (var session = new BLSession()) { var metaInformations = session.GetBL().GetDocumentMetaInformations(this.GetLoggedInUser(), new List() { this._referenceDocumentI3D, this._referenceDocument2I3D }); this.Verifier.Verify("MetaInformations", metaInformations); } } private void GetDocument() { var document = this.GetReferenceDocument(); this.Verifier.Verify("Document", document); } private void UpdateFlags() { using (var session = new BLSession()) { session.GetBL().UpdateDocumentFlags(this.GetLoggedInUser(), this._referenceDocumentI3D, DocumentFlags.IsPrinted | DocumentFlags.Checked); } var document = this.GetReferenceDocument(); this.Verifier.Verify("NewDocumentFlags", document.Flags); } private void RenameDocument() { using (var session = new BLSession()) { session.GetBL().RenameDocument(this.GetLoggedInUser(), this._referenceDocumentI3D, "ibims1document"); } var document = this.GetReferenceDocument(); this.Verifier.Verify("NewDocumentName", document.Name); } private void NewDocumentVersion() { using (var session = new BLSession()) { session.GetBL().AddNewDocumentVersion(this._referenceDocumentI3D, new byte[] { 1,2,3,4,5,6,7,8,10 }, this.GetLoggedInUser()); } var document = this.GetReferenceDocument(); this.Verifier.Verify("NewDocumentVersion", document); // we override this here as CheckInDocument creates a new version of the document, and we want to work with the newest version this._referenceDocumentI3D = document.I3D; } private void CheckOutDocument() { using (var session = new BLSession()) { session.GetBL().CheckOutDocument(this._referenceDocumentI3D, "ibims1workstation", "ibims1dateipfad", this.GetLoggedInUser()); } var document = this.GetReferenceDocument(); this.Verifier.Verify("DocumentCheckedOut", document); } private void CheckInDocument() { using (var session = new BLSession()) { session.GetBL().CheckInDocument(this._referenceDocumentI3D, new byte[20], this.GetLoggedInUser()); } var document = this.GetReferenceDocument(); this.Verifier.Verify("DocumentCheckedIn", document); // we override this here as CheckInDocument creates a new version of the document, and we want to work with the newest version this._referenceDocumentI3D = document.I3D; } private void UndoCheckOutDocument() { using (var session = new BLSession()) { session.GetBL().CheckOutDocument(this._referenceDocumentI3D, "ibims1workstation", "ibims1dateipfad", this.GetLoggedInUser()); } using (var session = new BLSession()) { session.GetBL().UndoCheckOut(this._referenceDocumentI3D); } var document = this.GetReferenceDocument(); this.Verifier.Verify("DocumentUndoCheckedOut", document); } private void DeleteDocument() { using (var session = new BLSession()) { session.GetBL().DeleteDocument(this.GetLoggedInUser(), this._referenceDocumentI3D); } var document = this.GetReferenceDocument(); Assert.Null(document); } private DocumentDTO GetReferenceDocument() { using (var session = new BLSession()) { var document = session.GetBL().GetNewestDocumentVersion(this.GetLoggedInUser(), this._referenceDocumentI3D); return document.Data; } } } }