예제 #1
0
        public void GivenSalesRepRelationship_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var customer = new OrganisationBuilder(this.Session).WithName("customer").WithLocale(new Locales(this.Session).EnglishGreatBritain).Build();

            this.Session.Derive();
            this.Session.Commit();

            var builder      = new SalesRepRelationshipBuilder(this.Session);
            var relationship = builder.Build();

            this.Session.Derive();
            Assert.True(relationship.Strategy.IsDeleted);

            this.Session.Rollback();

            builder.WithCustomer(customer);
            relationship = builder.Build();

            this.Session.Derive();
            Assert.True(relationship.Strategy.IsDeleted);

            this.Session.Rollback();

            builder.WithSalesRepresentative(new PersonBuilder(this.Session).WithLastName("salesrep.").Build());
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
예제 #2
0
        public void GivenParty_WhenSalesRepRelationshipIsUpdated_ThenCurrentSalesRepsAreUpdated()
        {
            var salesRep1    = new PersonBuilder(this.Session).WithLastName("salesRep1").Build();
            var salesRep2    = new PersonBuilder(this.Session).WithLastName("salesRep2").Build();
            var salesRep3    = new PersonBuilder(this.Session).WithLastName("salesRep3").Build();
            var organisation = new OrganisationBuilder(this.Session).WithName("customer").Build();

            var salesRepRelationship1 = new SalesRepRelationshipBuilder(this.Session)
                                        .WithCustomer(organisation)
                                        .WithSalesRepresentative(salesRep1)
                                        .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01))
                                        .Build();

            this.Session.Derive();

            Assert.Equal(1, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep1, organisation.CurrentSalesReps);

            new SalesRepRelationshipBuilder(this.Session)
            .WithCustomer(organisation)
            .WithSalesRepresentative(salesRep2)
            .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01))
            .Build();

            this.Session.Derive();

            Assert.Equal(2, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep1, organisation.CurrentSalesReps);
            Assert.Contains(salesRep2, organisation.CurrentSalesReps);

            salesRepRelationship1.ThroughDate = DateTimeFactory.CreateDate(2010, 12, 31);

            this.Session.Derive();

            Assert.Equal(1, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep2, organisation.CurrentSalesReps);

            new SalesRepRelationshipBuilder(this.Session)
            .WithCustomer(organisation)
            .WithSalesRepresentative(salesRep3)
            .WithProductCategory(new ProductCategoryBuilder(this.Session)
                                 .WithName("category")
                                 .Build())
            .Build();

            this.Session.Derive();

            Assert.Equal(2, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep2, organisation.CurrentSalesReps);
            Assert.Contains(salesRep3, organisation.CurrentSalesReps);
        }
예제 #3
0
        public void GivenWorkEffortPrintDocument_WhenPrinting_ThenMediaCreated()
        {
            // Arrange
            var frequencies = new TimeFrequencies(this.Session);
            var purposes    = new ContactMechanismPurposes(this.Session);

            //// Customer Contact and Address Data
            var customer         = new OrganisationBuilder(this.Session).WithName("Customer").Build();
            var customerContact  = new PersonBuilder(this.Session).WithFirstName("Customer").WithLastName("Contact").Build();
            var organisation     = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation);
            var customerRelation = new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build();

            var usa             = new Countries(this.Session).Extent().First(c => c.IsoCode.Equals("US"));
            var michigan        = new StateBuilder(this.Session).WithName("Michigan").WithCountry(usa).Build();
            var northville      = new CityBuilder(this.Session).WithName("Northville").WithState(michigan).Build();
            var postalCode      = new PostalCodeBuilder(this.Session).WithCode("48167").Build();
            var billingAddress  = this.CreatePostalAddress("Billing Address", "123 Street", "Suite S1", northville, postalCode);
            var shippingAddress = this.CreatePostalAddress("Shipping Address", "123 Street", "Dock D1", northville, postalCode);
            var phone           = new TelecommunicationsNumberBuilder(this.Session).WithCountryCode("1").WithAreaCode("616").WithContactNumber("774-2000").Build();

            customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.BillingAddress, billingAddress));
            customer.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.ShippingAddress, shippingAddress));
            customerContact.AddPartyContactMechanism(this.CreatePartyContactMechanism(purposes.GeneralPhoneNumber, phone));

            //// Work Effort Data
            var salesPerson      = new PersonBuilder(this.Session).WithFirstName("Sales").WithLastName("Person").Build();
            var salesRepRelation = new SalesRepRelationshipBuilder(this.Session).WithCustomer(customer).WithSalesRepresentative(salesPerson).Build();
            var salesOrder       = this.CreateSalesOrder(customer, organisation);
            var workOrder        = this.CreateWorkEffort(organisation, customer, customerContact, salesOrder.SalesOrderItems.First);
            var employee         = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build();
            var employment       = new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build();

            var salesOrderItem = salesOrder.SalesOrderItems.First;

            salesOrder.AddValidOrderItem(salesOrderItem);

            //// Work Effort Inventory Assignmets
            var part1 = this.CreatePart("P1");
            var part2 = this.CreatePart("P2");
            var part3 = this.CreatePart("P3");

            this.Session.Derive(true);

            var inventoryAssignment1 = this.CreateInventoryAssignment(workOrder, part1, 11);
            var inventoryAssignment2 = this.CreateInventoryAssignment(workOrder, part2, 12);
            var inventoryAssignment3 = this.CreateInventoryAssignment(workOrder, part3, 13);

            //// Work Effort Time Entries
            var yesterday      = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1));
            var laterYesterday = DateTimeFactory.CreateDateTime(yesterday.AddHours(3));

            var today      = DateTimeFactory.CreateDateTime(this.Session.Now());
            var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4));

            var tomorrow      = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1));
            var laterTomorrow = DateTimeFactory.CreateDateTime(tomorrow.AddHours(6));

            var timeEntryYesterday = this.CreateTimeEntry(yesterday, laterYesterday, frequencies.Day, workOrder);
            var timeEntryToday     = this.CreateTimeEntry(today, laterToday, frequencies.Hour, workOrder);
            var timeEntryTomorrow  = this.CreateTimeEntry(tomorrow, laterTomorrow, frequencies.Minute, workOrder);

            employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryYesterday);
            employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday);
            employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryTomorrow);

            this.Session.Derive(true);

            // Act
            workOrder.Print();

            this.Session.Derive();
            this.Session.Commit();

            // Assert
            Assert.True(workOrder.PrintDocument.ExistMedia);

            var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var outputFile = System.IO.File.Create(System.IO.Path.Combine(desktopDir, "workTask.odt"));
            var stream     = new System.IO.MemoryStream(workOrder.PrintDocument.Media.MediaContent.Data);

            stream.CopyTo(outputFile);
            stream.Close();
        }
예제 #4
0
        public void GivenSalesRepRelationship_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain).Build();
            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var builder = new SalesRepRelationshipBuilder(this.DatabaseSession);
            var relationship = builder.Build();

            this.DatabaseSession.Derive();
            Assert.IsTrue(relationship.Strategy.IsDeleted);

            this.DatabaseSession.Rollback();

            builder.WithCustomer(customer);
            relationship = builder.Build();

            this.DatabaseSession.Derive();
            Assert.IsTrue(relationship.Strategy.IsDeleted);

            this.DatabaseSession.Rollback();

            builder.WithSalesRepresentative(new PersonBuilder(this.DatabaseSession).WithLastName("salesrep.").Build());
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
예제 #5
0
파일: PartyTests.cs 프로젝트: Allors/apps
        public void GivenParty_WhenSalesRepRelationshipIsUpdated_ThenCurrentSalesRepsAreUpdated()
        {
            var salesRep1 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep1").Build();
            var salesRep2 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep2").Build();
            var salesRep3 = new PersonBuilder(this.DatabaseSession).WithLastName("salesRep3").Build();
            var organisation = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build();

            var salesRepRelationship1 = new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(organisation)
                .WithSalesRepresentative(salesRep1)
                .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01))
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep1, organisation.CurrentSalesReps);

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(organisation)
                .WithSalesRepresentative(salesRep2)
                .WithFromDate(DateTimeFactory.CreateDate(2010, 01, 01))
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep1, organisation.CurrentSalesReps);
            Assert.Contains(salesRep2, organisation.CurrentSalesReps);

            salesRepRelationship1.ThroughDate = DateTimeFactory.CreateDate(2010, 12, 31);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep2, organisation.CurrentSalesReps);

            new SalesRepRelationshipBuilder(this.DatabaseSession)
                .WithCustomer(organisation)
                .WithSalesRepresentative(salesRep3)
                .WithProductCategory(new ProductCategoryBuilder(this.DatabaseSession).WithDescription("category").Build())
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(2, organisation.CurrentSalesReps.Count);
            Assert.Contains(salesRep2, organisation.CurrentSalesReps);
            Assert.Contains(salesRep3, organisation.CurrentSalesReps);
        }