Exemple #1
0
        public void Ctor_WithElements_ElementsAddedInOrder()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));

            Assert.That(series.First().Period, Is.EqualTo(new YearPeriod(2014)));
            Assert.That(series.Last().Period, Is.EqualTo(new YearPeriod(2015)));
        }
Exemple #2
0
        public void ProvideValue_RhsHasNoDataForPeriod_ItemSkippedInJoin()
        {
            myLhsSeries = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 5), FigureFactory.New(2014, 7), FigureFactory.New(2013, 87));
            myRhsSeries = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 23), FigureFactory.New(2014, 37));

            var result = ( IFigureSeries )myProvider.ProvideValue(myContext.Object);

            Assert.That(result.Count, Is.EqualTo(2));
        }
Exemple #3
0
        public void ProvideValue_InconsistentCurrencies_Throws()
        {
            myLhsSeries = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));
            myRhsSeries = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 23, Dollar), FigureFactory.New(2014, 37, Dollar));

            var ex = Assert.Throws <ArgumentException>(() => myProvider.ProvideValue(myContext.Object));

            Assert.That(ex.Message, Does.Contain("Currency inconsistencies"));
        }
Exemple #4
0
        public void Add_CurrencyUnexpected_Throws()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure));

            series.Add(FigureFactory.New(2015, 5, null));
            var ex = Assert.Throws <ArgumentException>(() => series.Add(FigureFactory.New(2014, 7, Dollar)));

            Assert.That(ex.Message, Does.Contain("Currency inconsistencies"));
        }
Exemple #5
0
        public void ProvideValue_WithPreserveCurrency_CurrencyTakenOverForResult()
        {
            myLhsSeries = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));
            myRhsSeries = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 23, Euro), FigureFactory.New(2014, 37, Euro));

            var result = ( IFigureSeries )myProvider.ProvideValue(myContext.Object);

            Assert.That(result.Currency, Is.EqualTo(Euro));
        }
Exemple #6
0
        public void Add_WithICurrencyFigure_CurrencyIsTakenOver()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure));

            series.Add(FigureFactory.New(2015, 5, Euro));
            series.Add(FigureFactory.New(2014, 7, Euro));

            Assert.That(series.Currency, Is.EqualTo(Euro));
        }
        public void ProvideValue_WhenCalled_InputsReferenced()
        {
            myCurrentPrice = FigureFactory.NewPrice("2015-01-01", 17.21, Euro);
            myRhsSeries    = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 23, Euro), FigureFactory.New(2014, 37, Euro));

            var result = ( DerivedFigure )myProvider.ProvideValue(myContext.Object);

            Assert.That(result.Inputs, Is.EquivalentTo(new[] { myCurrentPrice, myRhsSeries.ElementAt(1) }));
        }
Exemple #8
0
        public void Add_FigureTypeMismatch_Throws()
        {
            var series = new FigureSeries(typeof(FakeFigure));

            series.Add(FigureFactory.New(2015, 5));
            var ex = Assert.Throws <ArgumentException>(() => series.Add(FigureFactory.NewPrice("2013-11-11", 7, Dollar)));

            Assert.That(ex.Message, Does.Contain("FigureType mismatch"));
        }
        public void ProvideValue_PriceWithoutCurrency_Throws()
        {
            myCurrentPrice = FigureFactory.NewPrice("2015-01-01", 17.21, null);
            myRhsSeries    = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 1));

            var ex = Assert.Throws <ArgumentException>(() => myProvider.ProvideValue(myContext.Object));

            Assert.That(ex.Message, Does.Contain("Currency missing"));
        }
        public void ProvideValue_SeriesWithoutCurrency_CurrencyOfPriceTaken()
        {
            myCurrentPrice = FigureFactory.NewPrice("2015-01-01", 17.21, Euro);
            myRhsSeries    = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 23), FigureFactory.New(2014, 37));

            var result = ( DerivedFigure )myProvider.ProvideValue(myContext.Object);

            Assert.That(result.Currency, Is.EqualTo(myCurrentPrice.Currency));
            Assert.That(result.Value, Is.EqualTo(17.21 + 23));
        }
Exemple #11
0
        public void ProvideValue_RhsSeriesEmpty_ReturnsMissingData()
        {
            myLhsSeries = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 1));
            myRhsSeries = FigureSeries.Empty;

            var result = myProvider.ProvideValue(myContext.Object);

            Assert.That(result, Is.InstanceOf <MissingData>());
            Assert.That((( MissingData )result).Figure, Is.EqualTo(RhsSeriesName));
        }
        public void ProvideValue_RhsHasNoDataForPeriod_MissingDataForPeriodReturned()
        {
            myCurrentPrice = FigureFactory.NewPrice("2015-01-01", 17.21, Euro);
            myRhsSeries    = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2001, 1, Euro));

            var result = myProvider.ProvideValue(myContext.Object);

            Assert.That(result, Is.InstanceOf <MissingDataForPeriod>());
            Assert.That((( MissingDataForPeriod )result).Figure, Is.EqualTo(RhsSeriesName));
        }
        public void ProvideValue_PriceMissing_ReturnsMissingData()
        {
            myCurrentPrice = null;
            myRhsSeries    = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 1));

            var result = myProvider.ProvideValue(myContext.Object);

            Assert.That(result, Is.InstanceOf <MissingData>());
            Assert.That((( MissingData )result).Figure, Is.EqualTo("Price"));
        }
Exemple #14
0
        public void ProvideValue_WhenCalled_InputsReferenced()
        {
            myLhsSeries = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));
            myRhsSeries = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 23, Euro), FigureFactory.New(2014, 37, Euro));

            var result = ( IFigureSeries )myProvider.ProvideValue(myContext.Object);

            Assert.That((( DerivedFigure )result.ElementAt(0)).Inputs, Is.EquivalentTo(new[] { myLhsSeries.ElementAt(0), myRhsSeries.ElementAt(0) }));
            Assert.That((( DerivedFigure )result.ElementAt(1)).Inputs, Is.EquivalentTo(new[] { myLhsSeries.ElementAt(1), myRhsSeries.ElementAt(1) }));
        }
        public void ProvideValue_WithValidInputData_RatioReturned()
        {
            myCurrentPrice = FigureFactory.NewPrice("2015-01-01", 17.21, Euro);
            myRhsSeries    = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 23, Euro), FigureFactory.New(2014, 37, Euro));

            var result = ( ICurrencyFigure )myProvider.ProvideValue(myContext.Object);

            Assert.That(result.Period, Is.EqualTo(myCurrentPrice.Period));
            Assert.That(result.Value, Is.EqualTo(17.21 + 23));
            Assert.That(result.Currency, Is.EqualTo(myCurrentPrice.Currency));
        }
        public void ProvideValue_InconsistentCurrencies_PriceCurrencyTranslated()
        {
            myCurrentPrice = FigureFactory.NewPrice("2015-01-01", 17.21, Euro);
            myRhsSeries    = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 23, Dollar), FigureFactory.New(2014, 37, Dollar));
            myContext.Setup(x => x.TranslateCurrency(It.IsAny <double>(), It.IsAny <Currency>(), It.IsAny <Currency>()))
            .Returns <double, Currency, Currency>((value, source, target) => value * 2);

            var result = ( DerivedFigure )myProvider.ProvideValue(myContext.Object);

            Assert.That(result.Currency, Is.EqualTo(myRhsSeries.Currency));
            Assert.That(result.Value, Is.EqualTo(17.21 * 2 + 23));
        }
Exemple #17
0
        public void ProvideValue_WithValidInputData_JoinReturned()
        {
            myLhsSeries = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 5), FigureFactory.New(2014, 7));
            myRhsSeries = new FigureSeries(typeof(FakeFigure), FigureFactory.New(2015, 23), FigureFactory.New(2014, 37));

            var result = ( IFigureSeries )myProvider.ProvideValue(myContext.Object);

            var r2015 = result.Single(i => i.Period.Equals(new YearPeriod(2015)));

            Assert.That(r2015.Value, Is.EqualTo(28));

            var r2014 = result.Single(i => i.Period.Equals(new YearPeriod(2014)));

            Assert.That(r2014.Value, Is.EqualTo(44));
        }
Exemple #18
0
        public void Ctor_WithElements_CurrencyIsTakenOver()
        {
            var series = new FigureSeries(typeof(FakeCurrencyFigure), FigureFactory.New(2015, 5, Euro), FigureFactory.New(2014, 7, Euro));

            Assert.That(series.Currency, Is.EqualTo(Euro));
        }