public void Should_Add_Exchange_Rate_To_Cache()
        {
            // arrange
            var price = new SimplePrice
            {
                Price        = 5,
                CurrencyCode = "GBP"
            };

            var currencyToConvert = "EUR";

            var fixture = new Fixture();
            var sut     = fixture
                          .WithExchangeRate(15)
                          .Configure();

            // act
            sut.ConvertPrice(price, currencyToConvert);

            // assert
            fixture.ExchangeRatesInCache.Should().BeEquivalentTo(new Fixture.ExchangeRateInCache
            {
                CurrencyFrom = "GBP",
                CurrencyTo   = "EUR",
                ExchangeRate = 15
            });
        }
Exemplo n.º 2
0
        public void PercentageDiscountExncludingVat()
        {
            IOC.IntegrationTest();
            IOC.SettingsService.ExclVat();
            var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1, 10);
            var order       = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo);
            var discount    = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithPercentage(50);

            IOC.OrderDiscountRepository.SetupFake(discount);
            order.OrderDiscountsFactory = () => IO.Container.Resolve <IOrderDiscountService>().GetApplicableDiscountsForOrder(order, order.Localization).ToList();
            order.ResetDiscounts();

            Assert.AreEqual(1100, order.GetAmount(true, false, true));
            Assert.AreEqual(1000, order.GetAmount(false, false, true));
            Assert.AreEqual(550, order.GetAmount(true, true, true));
            Assert.AreEqual(500, order.GetAmount(false, true, true));

            var price = new SimplePrice(order, order.Localization);

            Assert.AreEqual(1100, price.BeforeDiscount.WithVat.ValueInCents);
            Assert.AreEqual(1000, price.BeforeDiscount.WithoutVat.ValueInCents);
            Assert.AreEqual(100, price.BeforeDiscount.Vat.ValueInCents);
            Assert.AreEqual(550, price.WithVat.ValueInCents);
            Assert.AreEqual(500, price.WithoutVat.ValueInCents);
            Assert.AreEqual(50, price.Vat.ValueInCents);

            Assert.AreEqual(550, price.Discount.WithVat.ValueInCents);
            Assert.AreEqual(500, price.Discount.WithoutVat.ValueInCents);
        }
Exemplo n.º 3
0
        private void AddSignal(Series series, TimedValue <DateTime, Signal> signal)
        {
            var price = GetPointForSignal(signal);

            if (price == null)
            {
                // actually this should result at least in a warning
                price = new SimplePrice(signal.Time, 0.0);
            }

            series.Points.AddXY(signal.Time, price.Value);

            var point = series.Points[series.Points.Count - 1];

            if (signal.Value.Type == SignalType.Buy)
            {
                point.MarkerStyle = MarkerStyle.Triangle;
                point.MarkerColor = Color.Green;
            }
            else if (signal.Value.Type == SignalType.Sell)
            {
                point.MarkerStyle = MarkerStyle.Cross;
                point.MarkerColor = Color.Red;
            }
        }
        public void Should_Valid_Convert_Price()
        {
            // arrange
            var price = new SimplePrice
            {
                Price        = 5,
                CurrencyCode = "GBP"
            };

            var currencyToConvert = "EUR";

            var sut = new Fixture()
                      .WithExchangeRate(10)
                      .Configure();

            // act
            var result = sut.ConvertPrice(price, currencyToConvert);

            // assert
            result.Should().BeEquivalentTo(new SimplePrice
            {
                Price        = 50,
                CurrencyCode = "EUR"
            });
        }
Exemplo n.º 5
0
        public void Apply_LessOrEqualPointsThanMax_SeriesRemainsUnchanged()
        {
            var op = new ReducePointsOperator( 2 );
            var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 12 );
            var thuesday = new SimplePrice( new DateTime( 2011, 1, 11 ), 23 );
            var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, thuesday } );

            var series = op.Apply( input );

            Assert.That( series, Is.EquivalentTo( input ) );
        }
Exemplo n.º 6
0
        public void Apply_DayMissing_DataFromDayBeforeIsTaken()
        {
            var op         = new InterpolateMissingDatesOperator();
            var monday     = new SimplePrice(new DateTime(2011, 1, 10), 123);
            var weddnesday = new SimplePrice(new DateTime(2011, 1, 12), 456);
            var input      = new PriceSeries(SeriesIdentifier.Null, new[] { monday, weddnesday });

            var series = op.Apply(input);

            Assert.That(series[1].Value, Is.EqualTo(123));
        }
        public void Apply_NoDataForWeekend_NoDataInterpolatedForWeekend()
        {
            var op = new InterpolateMissingDatesOperator();
            var friday = new SimplePrice( new DateTime( 2011, 1, 7 ), 0 );
            var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 0 );
            var input = new PriceSeries( SeriesIdentifier.Null, new[] { friday, monday } );

            var series = op.Apply( input );

            Assert.That( series, Is.EquivalentTo( input ) );
        }
Exemplo n.º 8
0
        public void Apply_LessOrEqualPointsThanMax_SeriesRemainsUnchanged()
        {
            var op       = new ReducePointsOperator(2);
            var monday   = new SimplePrice(new DateTime(2011, 1, 10), 12);
            var thuesday = new SimplePrice(new DateTime(2011, 1, 11), 23);
            var input    = new PriceSeries(SeriesIdentifier.Null, new[] { monday, thuesday });

            var series = op.Apply(input);

            Assert.That(series, Is.EquivalentTo(input));
        }
        public void Apply_DayMissing_DataFromDayBeforeIsTaken()
        {
            var op = new InterpolateMissingDatesOperator();
            var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 123 );
            var weddnesday = new SimplePrice( new DateTime( 2011, 1, 12 ), 456 );
            var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, weddnesday } );

            var series = op.Apply( input );

            Assert.That( series[ 1 ].Value, Is.EqualTo( 123 ) );
        }
Exemplo n.º 10
0
        public void Apply_NoDataForWeekend_NoDataInterpolatedForWeekend()
        {
            var op     = new InterpolateMissingDatesOperator();
            var friday = new SimplePrice(new DateTime(2011, 1, 7), 0);
            var monday = new SimplePrice(new DateTime(2011, 1, 10), 0);
            var input  = new PriceSeries(SeriesIdentifier.Null, new[] { friday, monday });

            var series = op.Apply(input);

            Assert.That(series, Is.EquivalentTo(input));
        }
        public void Apply_NoDatesMissing_SeriesRemainsUnchanged()
        {
            var op = new InterpolateMissingDatesOperator();
            var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 12 );
            var thuesday = new SimplePrice( new DateTime( 2011, 1, 11 ), 23 );
            var weddnesday = new SimplePrice( new DateTime( 2011, 1, 12 ), 34 );
            var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday } );

            var series = op.Apply( input );

            Assert.That( series, Is.EquivalentTo( input ) );
        }
Exemplo n.º 12
0
        public void Apply_NoDatesMissing_SeriesRemainsUnchanged()
        {
            var op         = new InterpolateMissingDatesOperator();
            var monday     = new SimplePrice(new DateTime(2011, 1, 10), 12);
            var thuesday   = new SimplePrice(new DateTime(2011, 1, 11), 23);
            var weddnesday = new SimplePrice(new DateTime(2011, 1, 12), 34);
            var input      = new PriceSeries(SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday });

            var series = op.Apply(input);

            Assert.That(series, Is.EquivalentTo(input));
        }
Exemplo n.º 13
0
        public void Apply_MorePointsThanMax_DataGroupedByAverage()
        {
            var op         = new ReducePointsOperator(2);
            var monday     = new SimplePrice(new DateTime(2011, 1, 10), 10);
            var thuesday   = new SimplePrice(new DateTime(2011, 1, 11), 20);
            var weddnesday = new SimplePrice(new DateTime(2011, 1, 12), 30);
            var input      = new PriceSeries(SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday });

            var series = op.Apply(input);

            Assert.That(series.Count, Is.EqualTo(2));
            Assert.That(series[0].Value, Is.EqualTo(15));
            Assert.That(series[1].Value, Is.EqualTo(30));
        }
Exemplo n.º 14
0
        public void Apply_MorePointsThanMax_DataGroupedByAverage()
        {
            var op = new ReducePointsOperator( 2 );
            var monday = new SimplePrice( new DateTime( 2011, 1, 10 ), 10 );
            var thuesday = new SimplePrice( new DateTime( 2011, 1, 11 ), 20 );
            var weddnesday = new SimplePrice( new DateTime( 2011, 1, 12 ), 30 );
            var input = new PriceSeries( SeriesIdentifier.Null, new[] { monday, thuesday, weddnesday } );

            var series = op.Apply( input );

            Assert.That( series.Count, Is.EqualTo( 2 ) );
            Assert.That( series[ 0 ].Value, Is.EqualTo( 15 ) );
            Assert.That( series[ 1 ].Value, Is.EqualTo( 30 ) );
        }
Exemplo n.º 15
0
        public IPriceSeries Calculate( IPriceSeries prices )
        {
            var points = new List<SimplePrice>();

            for ( int i = NumDays; i < prices.Count; ++i )
            {
                var pricesRange = new PriceSeriesRange( prices, ClosedInterval.FromOffsetLength( i - NumDays, NumDays ) );

                double value = pricesRange.Average( p => p.Value );

                var point = new SimplePrice( prices[ i ].Time, value );
                points.Add( point );
            }

            var descriptor = new ObjectDescriptor( "SMA", ObjectDescriptor.Param( "NumDays", NumDays ) );
            var seriesId = prices.Identifier.Derive( descriptor );
            return new PriceSeries( seriesId, points );
        }
Exemplo n.º 16
0
        public IPriceSeries Calculate(IPriceSeries prices)
        {
            var points = new List <SimplePrice>();

            for (int i = NumDays; i < prices.Count; ++i)
            {
                var pricesRange = new PriceSeriesRange(prices, ClosedInterval.FromOffsetLength(i - NumDays, NumDays));

                double value = pricesRange.Average(p => p.Value);

                var point = new SimplePrice(prices[i].Time, value);
                points.Add(point);
            }

            var descriptor = new ObjectDescriptor("SMA", ObjectDescriptor.Param("NumDays", NumDays));
            var seriesId   = prices.Identifier.Derive(descriptor);

            return(new PriceSeries(seriesId, points));
        }
Exemplo n.º 17
0
        public void AmountDiscountIncludingVat()
        {
            IOC.IntegrationTest();
            var productInfo = DefaultFactoriesAndSharedFunctionality.CreateProductInfo(1000, 1, 10);
            var order       = DefaultFactoriesAndSharedFunctionality.CreateIncompleteOrderInfo(productInfo);
            var discount    = DefaultFactoriesAndSharedFunctionality.CreateDefaultOrderDiscountWithAmount(500, DiscountOrderCondition.None, 0);

            IOC.OrderDiscountRepository.SetupFake(discount);
            order.OrderDiscountsFactory = () => IO.Container.Resolve <IOrderDiscountService>().GetApplicableDiscountsForOrder(order, order.Localization).ToList();
            order.ResetDiscounts();

            var absoluteDiscountAmount    = 500;
            var AverageOrderVatPercentage = 10m;
            var vatAmountFromWithVat      = VatCalculator.VatAmountFromWithVat(absoluteDiscountAmount, AverageOrderVatPercentage);

            //var vatAmountFromWithoutVat = VatCalculator.VatAmountFromWithoutVat(absoluteDiscountAmount, AverageOrderVatPercentage);
            Assert.AreEqual(45, vatAmountFromWithVat);

            // berekende discount vat = 45,45454545..
            // correct zou zijn 500 - 454 = 46 (zie hieronder)

            // full amount: 909
            // discounted amount: 455
            // discount: 909 - 455 = 454
            //  'discount vat': 500 - 454 = 46

            Assert.AreEqual(1000, order.GetAmount(true, false, true));
            Assert.AreEqual(909, order.GetAmount(false, false, true));
            Assert.AreEqual(500, order.GetAmount(true, true, true));
            Assert.AreEqual(455, order.GetAmount(false, true, true));

            var price = new SimplePrice(order, order.Localization);

            Assert.AreEqual(1000, price.BeforeDiscount.WithVat.ValueInCents);
            Assert.AreEqual(909, price.BeforeDiscount.WithoutVat.ValueInCents);
            Assert.AreEqual(91, price.BeforeDiscount.Vat.ValueInCents);
            Assert.AreEqual(500, price.WithVat.ValueInCents);
            Assert.AreEqual(455, price.WithoutVat.ValueInCents);
            Assert.AreEqual(45, price.Vat.ValueInCents);

            Assert.AreEqual(500, price.Discount.WithVat.ValueInCents);
            Assert.AreEqual(454, price.Discount.WithoutVat.ValueInCents);
        }