コード例 #1
0
        /**
         *
         * All invloved parties (Buyer and Seller) must be an Organisation to use
         * WithOrganisationInternalDefaults method
         *
         **/
        public static SalesOrderBuilder WithOrganisationInternalDefaults(this SalesOrderBuilder @this, Organisation sellerOrganisation)
        {
            var faker = @this.Session.Faker();

            var internalOrganisations = @this.Session.Extent <Organisation>();

            // Organisation of type Internal Organisation
            internalOrganisations.Filter.AddEquals(M.Organisation.IsInternalOrganisation.RoleType, true);

            // Filter out the sellerOrganisation
            var shipToCustomer = internalOrganisations.Except(new List <Organisation> {
                sellerOrganisation
            }).FirstOrDefault();

            var billToCustomer = shipToCustomer;

            var endCustomer = faker.Random.ListItem(shipToCustomer.ActiveCustomers.Where(v => v.GetType().Name == "Organisation").ToList());

            var endContact    = endCustomer is Person endContactPerson ? endContactPerson : endCustomer.CurrentContacts.FirstOrDefault();
            var shipToContact = shipToCustomer.CurrentContacts.FirstOrDefault();

            var salesOrderItem_Default = new SalesOrderItemBuilder(@this.Session).WithDefaults().Build();
            var salesOrderItem_Product = new SalesOrderItemBuilder(@this.Session).WithProductItemDefaults().Build();
            var salesOrderItem_Part    = new SalesOrderItemBuilder(@this.Session).WithPartItemDefaults().Build();

            var paymentMethod = faker.Random.ListItem(@this.Session.Extent <PaymentMethod>());

            @this.WithCustomerReference(faker.Random.Words(10));
            @this.WithTakenBy(sellerOrganisation);
            @this.WithTakenByContactMechanism(sellerOrganisation.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithTakenByContactPerson(sellerOrganisation.CurrentContacts.FirstOrDefault());
            @this.WithDescription(faker.Lorem.Sentence());
            @this.WithComment(faker.Lorem.Sentence());
            @this.WithInternalComment(faker.Lorem.Sentence());
            @this.WithBillToCustomer(billToCustomer);
            @this.WithBillToContactMechanism(billToCustomer.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithBillToContactPerson(billToCustomer.CurrentContacts.FirstOrDefault());
            @this.WithBillToEndCustomer(endCustomer);
            @this.WithBillToEndCustomerContactMechanism(endCustomer.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault());
            @this.WithBillToEndCustomerContactPerson(endContact);
            @this.WithShipToEndCustomer(endCustomer);
            @this.WithShipToEndCustomerAddress(endCustomer.ShippingAddress);
            @this.WithShipToEndCustomerContactPerson(endContact);
            @this.WithShipToCustomer(shipToCustomer);
            @this.WithShipToAddress(shipToCustomer.ShippingAddress);
            @this.WithShipFromAddress(sellerOrganisation.ShippingAddress);
            @this.WithShipToContactPerson(shipToContact);
            @this.WithPaymentMethod(paymentMethod);
            @this.WithSalesOrderItem(salesOrderItem_Default);
            @this.WithSalesOrderItem(salesOrderItem_Product);
            @this.WithSalesOrderItem(salesOrderItem_Part);
            @this.WithSalesTerm(new IncoTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaults().Build());
            @this.WithSalesTerm(new OrderTermBuilder(@this.Session).WithDefaults().Build());

            return(@this);
        }