public void GivenOwnCreditCardForSingleton_WhenDeriving_ThenExpiredCardIsBlocked()
        {
            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.Session)
                                .WithCreditCard(creditCard)
                                .Build();

            this.InternalOrganisation.AddPaymentMethod(paymentMethod);

            this.Session.Derive();
            Assert.True(paymentMethod.IsActive);

            creditCard.ExpirationYear  = this.Session.Now().Year;
            creditCard.ExpirationMonth = this.Session.Now().Month;

            this.Session.Derive();
            Assert.False(paymentMethod.IsActive);
        }
Exemplo n.º 2
0
        public void GivenOwnCreditCardForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenCreditorIsRequired()
        {
            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession)
                .WithCreditCard(creditCard)
                .Build();

            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;

            internalOrganisation.RemovePaymentMethods();
            internalOrganisation.AddPaymentMethod(paymentMethod);
            internalOrganisation.DoAccounting = false;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            internalOrganisation.DoAccounting = true;

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);
        }
        public void GivenOwnCreditCard_WhenDeriving_ThenCreditCardRelationMustExist()
        {
            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            this.Session.Commit();

            var builder = new OwnCreditCardBuilder(this.Session);

            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithCreditCard(creditCard);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnCreditCard_WhenDeriving_ThenGeneralLedgerAccountAndJournalAtMostOne()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var collectionMethod = new OwnCreditCardBuilder(this.Session)
                                   .WithCreditCard(creditCard)
                                   .WithGeneralLedgerAccount(internalOrganisationGlAccount)
                                   .Build();

            ((OrganisationDerivedRoles)this.InternalOrganisation).AddActiveCollectionMethod(collectionMethod);

            this.Session.Commit();

            var internalOrganisation = this.InternalOrganisation;

            internalOrganisation.DoAccounting            = true;
            internalOrganisation.DefaultCollectionMethod = collectionMethod;

            Assert.False(this.Session.Derive(false).HasErrors);

            collectionMethod.Journal = journal;

            Assert.True(this.Session.Derive(false).HasErrors);

            collectionMethod.RemoveGeneralLedgerAccount();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Exemplo n.º 5
0
        public void TestAbstaractFactoryAndBuilder()
        {
            Owner   owner   = new Owner("Vlad", "Demyanov", "Ruslanovich", DateTime.Now, "GH92OL88II99PP");
            Account account = new Account("7k", "валютный счёт", 2000, DateTime.Now, true, false, owner);

            CardDesigner cardDesigner = new CardDesigner();
            CardBuilder  cardBuilder  = new CreditCardBuilder(new CreditCardFactory(account, owner));

            Card creditCard = cardDesigner.ReleaseCard(cardBuilder);

            Console.WriteLine(creditCard.ToString());
            creditCard.ToPerformOperation();

            Assert.Pass();
        }
        public void GivenOwnCreditCardForSingletonThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            this.InternalOrganisation.DoAccounting = true;

            this.Session.Derive();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.Session)
                                       .WithAccountNumber("0001")
                                       .WithName("GeneralLedgerAccount")
                                       .WithBalanceSheetAccount(true)
                                       .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.Session)
                                                .WithGeneralLedgerAccount(generalLedgerAccount)
                                                .Build();

            var journal = new JournalBuilder(this.Session).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.Session)
                                .WithCreditCard(creditCard)
                                .Build();

            this.InternalOrganisation.AddPaymentMethod(paymentMethod);

            Assert.True(this.Session.Derive(false).HasErrors);

            paymentMethod.Journal = journal;

            Assert.False(this.Session.Derive(false).HasErrors);

            paymentMethod.RemoveJournal();
            paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.False(this.Session.Derive(false).HasErrors);
        }
        public void GivenOwnCreditCard_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var creditCard = new CreditCardBuilder(this.Session)
                             .WithCardNumber("4012888888881881")
                             .WithExpirationYear(this.Session.Now().Year + 1)
                             .WithExpirationMonth(03)
                             .WithNameOnCard("M.E. van Knippenberg")
                             .WithCreditCardCompany(new CreditCardCompanyBuilder(this.Session).WithName("Visa").Build())
                             .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.Session)
                                .WithCreditCard(creditCard)
                                .Build();

            this.InternalOrganisation.AddPaymentMethod(paymentMethod);

            this.Session.Derive();

            Assert.True(paymentMethod.IsActive);
        }
Exemplo n.º 8
0
        public void withSpecifiedValues()
        {
            AccountBuilder accountBuilder = AccountBuilder.NewAccount()
                                            .WithName(ACC_NAME)
                                            .WithId(ACC_ID)
                                            .WithOwner(ACC_OWNER)
                                            .WithLogoUrl(ACC_LOGOURL)
                                            .WithData(ACC_DATA)
                                            .WithCompany(CompanyBuilder.NewCompany(ACC_CO_NAME)
                                                         .WithAddress(AddressBuilder.NewAddress()
                                                                      .WithAddress1(ACC_CO_ADDR_ADDR1)
                                                                      .WithAddress2(ACC_CO_ADDR_ADDR2)
                                                                      .WithCity(ACC_CO_ADDR_CITY)
                                                                      .WithCountry(ACC_CO_ADDR_COUNTRY)
                                                                      .WithState(ACC_CO_ADDR_STATE)
                                                                      .WithZipCode(ACC_CO_ADDR_ZIP).Build())
                                                         .WithId(ACC_CO_ID)
                                                         .WithData(ACC_CO_DATA)
                                                         .Build())
                                            .WithCustomField(CustomFieldBuilder.CustomFieldWithId(ACC_FIELD_ID)
                                                             .WithDefaultValue(ACC_FIELD_DEF_VLE)
                                                             .IsRequired(ACC_FIELD_IS_REQUIRED)
                                                             .WithTranslation(TranslationBuilder.NewTranslation(ACC_FIELD_TRANSL_LANG).Build())
                                                             .Build())
                                            .WithLicense(LicenseBuilder.NewLicense()
                                                         .CreatedOn(ACC_LIC_CREATED)
                                                         .WithPaidUntil(ACC_LIC_PAIDUNTIL)
                                                         .WithStatus(ACC_LIC_STATUS)
                                                         .WithTransaction(ACC_LIC_TRANS_CREATED,
                                                                          CreditCardBuilder.NewCreditCard()
                                                                          .WithCvv(ACC_LIC_TRANS_CC_CVV)
                                                                          .WithName(ACC_LIC_TRANS_CC_NAME)
                                                                          .WithNumber(ACC_LIC_TRANS_CC_NUM)
                                                                          .WithType(ACC_LIC_TRANS_CC_TYPE)
                                                                          .WithExpiration(ACC_LIC_TRANS_CC_EXP_MONTH, ACC_LIC_TRANS_CC_EXP_YEAR)
                                                                          .Build(),
                                                                          PriceBuilder.NewPrice()
                                                                          .WithAmount(ACC_LIC_TRANS_PRICE_AMOUNT)
                                                                          .WithCurrency(ACC_LIC_TRANS_PRICE_CURR_ID, ACC_LIC_TRANS_PRICE_CURR_NAME,
                                                                                        ACC_LIC_TRANS_PRICE_CURR_DATA)
                                                                          .Build())
                                                         .WithPlan(PlanBuilder.NewPlan(ACC_LIC_PLAN_ID)
                                                                   .WithId(ACC_LIC_PLAN_NAME)
                                                                   .WithContract(ACC_LIC_PLAN_CONTRACT)
                                                                   .WithDescription(ACC_LIC_PLAN_DES)
                                                                   .WithGroup(ACC_LIC_PLAN_GRP)
                                                                   .WithCycle(ACC_LIC_PLAN_CYC)
                                                                   .WithOriginal(ACC_LIC_PLAN_ORI)
                                                                   .WithData(ACC_LIC_PLAN_DATA)
                                                                   .WithFreeCycles(ACC_LIC_PLAN_CYC_COUNT, ACC_LIC_PLAN_CYC_CYCLE)
                                                                   .WithQuota(ACC_LIC_PLAN_QUOTA_CYCLE, ACC_LIC_PLAN_QUOTA_LIMIT, ACC_LIC_PLAN_QUOTA_SCOPE,
                                                                              ACC_LIC_PLAN_QUOTA_TARGET)
                                                                   .WithFeatures(ACC_LIC_PLAN_FEAT)
                                                                   .WithPrice(PriceBuilder.NewPrice()
                                                                              .WithAmount(ACC_LIC_PLAN_PRICE_AMOUNT)
                                                                              .WithCurrency(ACC_LIC_PLAN_PRICE_CURR_ID, ACC_LIC_PLAN_PRICE_CURR_NAME,
                                                                                            ACC_LIC_PLAN_PRICE_CURR_DATA)
                                                                              .Build())
                                                                   .Build())
                                                         .Build())
                                            .WithAccountProviders(new List <Provider>()
            {
                ProviderBuilder.NewProvider(ACC_PROV_DOC_NAME)
                .WithData(ACC_PROV_DOC_DATA)
                .WithId(ACC_PROV_DOC_ID)
                .WithProvides(ACC_PROV_DOC_NAME)
                .Build()
            }, new List <Provider>()
            {
                ProviderBuilder.NewProvider(ACC_PROV_USR_NAME)
                .WithData(ACC_PROV_USR_DATA)
                .WithId(ACC_PROV_USR_ID)
                .WithProvides(ACC_PROV_USR_PROVIDES)
                .Build()
            });

            Account account = accountBuilder.Build();

            Assert.AreEqual(ACC_NAME, account.Name);
            Assert.AreEqual(ACC_CO_ID, account.Company.Id);
            Assert.AreEqual(ACC_CO_ADDR_ADDR1, account.Company.Address.Address1);

            Assert.AreEqual(1, account.CustomFields.Count);
            Assert.AreEqual(ACC_FIELD_DEF_VLE, account.CustomFields[0].Value);
            Assert.AreEqual(1, account.CustomFields[0].Translations.Count);
            Assert.AreEqual(ACC_FIELD_TRANSL_LANG, account.CustomFields[0].Translations[0].Language);

            Assert.AreEqual(1, account.Licenses.Count);
            Assert.AreEqual(ACC_LIC_STATUS, account.Licenses[0].Status);
            Assert.AreEqual(1, account.Licenses[0].Transactions.Count);
            Assert.AreEqual(ACC_LIC_TRANS_CC_NUM, account.Licenses[0].Transactions[0].CreditCard.Number);
            Assert.AreEqual(ACC_LIC_TRANS_PRICE_AMOUNT, account.Licenses[0].Transactions[0].Price.Amount);
            Assert.AreEqual(ACC_LIC_PLAN_CONTRACT, account.Licenses[0].Plan.Contract);
            Assert.AreEqual(ACC_LIC_PLAN_PRICE_AMOUNT, account.Licenses[0].Plan.Price.Amount);

            Assert.AreEqual(1, account.Providers.Documents.Count);
            Assert.AreEqual(ACC_PROV_DOC_NAME, account.Providers.Documents[0].Name);
            Assert.AreEqual(1, account.Providers.Users.Count);
            Assert.AreEqual(ACC_PROV_USR_NAME, account.Providers.Users[0].Name);
        }
Exemplo n.º 9
0
        public void GivenOwnCreditCardForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenEitherGeneralLedgerAccountOrJournalMustExist()
        {
            var supplier = new OrganisationBuilder(this.DatabaseSession)
                .WithName("supplier")
                .WithLocale(new Locales(this.DatabaseSession).EnglishGreatBritain)
                .Build();

            var internalOrganisation = new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation");

            var supplierRelationship = new SupplierRelationshipBuilder(this.DatabaseSession)
                .WithSupplier(supplier)
                .WithInternalOrganisation(internalOrganisation)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            var generalLedgerAccount = new GeneralLedgerAccountBuilder(this.DatabaseSession)
                .WithAccountNumber("0001")
                .WithName("GeneralLedgerAccount")
                .WithBalanceSheetAccount(true)
                .Build();

            var internalOrganisationGlAccount = new OrganisationGlAccountBuilder(this.DatabaseSession)
                .WithInternalOrganisation(internalOrganisation)
                .WithGeneralLedgerAccount(generalLedgerAccount)
                .Build();

            var journal = new JournalBuilder(this.DatabaseSession).WithDescription("journal").Build();

            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession)
                .WithCreditCard(creditCard)
                .WithCreditor(supplierRelationship)
                .Build();

            this.DatabaseSession.Commit();

            internalOrganisation.RemovePaymentMethods();
            internalOrganisation.AddPaymentMethod(paymentMethod);
            internalOrganisation.DoAccounting = true;

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            paymentMethod.Journal = journal;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);

            paymentMethod.RemoveJournal();
            paymentMethod.GeneralLedgerAccount = internalOrganisationGlAccount;

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemplo n.º 10
0
        public void GivenOwnCreditCard_WhenDeriving_ThenCreditCardRelationMustExist()
        {
            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            this.DatabaseSession.Commit();

            var builder = new OwnCreditCardBuilder(this.DatabaseSession);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithCreditCard(creditCard);
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }
Exemplo n.º 11
0
        public void GivenOwnCreditCard_WhenBuild_ThenPostBuildRelationsMustExist()
        {
            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession)
                .WithCreditCard(creditCard)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.IsTrue(paymentMethod.IsActive);
        }
Exemplo n.º 12
0
        public void GivenOwnCreditCardForInternalOrganisationThatDoesAccounting_WhenDeriving_ThenExpiredCardIsBlocked()
        {
            var creditCard = new CreditCardBuilder(this.DatabaseSession)
                .WithCardNumber("4012888888881881")
                .WithExpirationYear(2016)
                .WithExpirationMonth(03)
                .WithNameOnCard("M.E. van Knippenberg")
                .WithCreditCardCompany(new CreditCardCompanyBuilder(this.DatabaseSession).WithName("Visa").Build())
                .Build();

            var paymentMethod = new OwnCreditCardBuilder(this.DatabaseSession)
                .WithCreditCard(creditCard)
                .Build();

            var internalOrganisation = Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation;
            internalOrganisation.AddPaymentMethod(paymentMethod);

            this.DatabaseSession.Derive(true);
            Assert.IsTrue(paymentMethod.IsActive);

            creditCard.ExpirationYear = DateTime.UtcNow.Year;
            creditCard.ExpirationMonth = DateTime.UtcNow.Month;

            this.DatabaseSession.Derive(true);
            Assert.IsFalse(paymentMethod.IsActive);
        }