Esempio n. 1
0
        public void GivenDiscount_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build();
            var good      = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            var colorFeature = new ColourBuilder(this.Session)
                               .WithVatRate(vatRate21)
                               .WithName("black")
                               .Build();

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

            var builder = new DiscountComponentBuilder(this.Session);

            builder.Build();

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

            this.Session.Rollback();

            builder.WithPrice(1);
            builder.Build();

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

            this.Session.Rollback();

            builder.WithFromDate(DateTime.UtcNow);
            builder.Build();

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

            this.Session.Rollback();

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

            builder.WithProduct(good);
            builder.Build();

            this.Session.Rollback();

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

            builder.WithProductFeature(colorFeature);
            builder.Build();

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

            this.Session.Rollback();

            builder.WithPercentage(10);
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);
        }
Esempio n. 2
0
        public void GivenDiscount_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("gizmo")
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var colorFeature = new ColourBuilder(this.DatabaseSession)
             .WithName("golden")
             .WithVatRate(vatRate21)
             .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession)
                                         .WithText("black")
                                         .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                                         .Build())
             .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

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

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

            this.DatabaseSession.Rollback();

            builder.WithPrice(1);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithFromDate(DateTime.UtcNow);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithDescription("description");
            builder.Build();

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

            builder.WithProduct(good);
            builder.Build();

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

            builder.WithProductFeature(colorFeature);
            builder.Build();

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

            this.DatabaseSession.Rollback();

            builder.WithPercentage(10);
            builder.Build();

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