public void BothHaveSegsAndScenariosCheckScenarios()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment( "key1", "key1", "key1", "key1" );
            cp1.AddScenario( "key1", "key1", "key1", "key1" );
            cp1.PeriodType = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime( 2000,1,1);
            cp1.PeriodEndDate = new DateTime( 2000, 1, 2);

            cp2.AddSegment( "key1", "key1", "key1", "key1" );
            cp2.AddScenario( "key2", "key2", "key2", "key2" );
            cp2.PeriodType = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime( 2000,1,1);
            cp2.PeriodEndDate = new DateTime( 2000, 1, 2);

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            Assert.AreEqual( 0, CompareSegments( cuw1.contextRef.Segments, cuw2.contextRef.Segments ), "segments are not equal" );
            Assert.AreEqual( 0, CompareDates( cuw1, cuw2 ), "dates are not equal" );
            Assert.AreEqual( 1, CompareScenarios( cuw2.contextRef.Scenarios, cuw1.contextRef.Scenarios ), "scenario 1 sort wrong" );

            Assert.AreEqual( 1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( -1, Compare( cuw1, cuw2 ), "2 sort wrong" );
        }
Example #2
0
        public static string GetCurrencyCodeFromMCU(MergedContextUnitsWrapper mcu)
        {
            if (mcu == null)
            {
                return(string.Empty);
            }

            foreach (UnitProperty up in mcu.UPS)
            {
                string code = GetCurrencyCodeFromUnit(up);
                if (!string.IsNullOrEmpty(code))
                {
                    return(code);
                }
            }

            return(string.Empty);
        }
        public void BothHaveSegsAndScenariosCheckDates()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment( "key1", "key1", "key1", "key1" );
            cp1.AddScenario( "key9", "key9", "key9", "key9" );
            cp1.PeriodType = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime( 2000,1,1);
            cp1.PeriodEndDate = new DateTime( 2000, 1, 2);

            cp2.AddSegment( "key1", "key1", "key1", "key1" );
            cp2.AddScenario( "key2", "key2", "key2", "key2" );
            cp2.PeriodType = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime( 2000,1,1);
            cp2.PeriodEndDate = new DateTime( 2000, 1, 3);

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            // and compare them - no scen should be first
            Assert.AreEqual( -1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( 1, Compare( cuw1, cuw2 ), "2 sort wrong" );
        }
        public void BothHaveSegsOneWithScenario()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment( "key1", "key1", "key1", "key1" );
            cp1.PeriodType = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime( 2000,1,1);
            cp1.PeriodEndDate = new DateTime( 2000, 1, 2);

            cp1.AddScenario( "key1", "key1", "key1", "key1" );

            cp2.AddSegment( "key1", "key1", "key1", "key1" );
            cp2.PeriodType = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime( 2000,1,1);
            cp2.PeriodEndDate = new DateTime( 2000,1,2);

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            Assert.AreEqual( -1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( 1, Compare( cuw1, cuw2 ), "2 sort wrong" );
        }
        public void TwoSegsBeforeOneSeg()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment( "key1", "key1", "key1", "key1" );
            cp1.AddSegment( "key3", "key3", "key3", "key3" );

            cp2.AddSegment( "key2", "key2", "key2", "key2" );

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            // and compare them
            Assert.AreEqual( 1, CompareSegments( cp2.Segments, cp1.Segments ), "segment sort 1 wrong" );
            Assert.AreEqual( -1, CompareSegments( cp1.Segments, cp2.Segments ), "segment sort 2 wrong" );

            Assert.AreEqual( 1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( -1, Compare( cuw1, cuw2 ), "2 sort wrong" );
        }
        public void SimpleSegmentTest()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddSegment( "key1", "key1", "key1", "key1" );
            cp2.AddSegment( "key2", "key2", "key2", "key2" );

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            // and compare them
            Assert.AreEqual( 1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( -1, Compare( cuw1, cuw2 ), "2 sort wrong" );
            Assert.AreEqual( 0, Compare( cuw1, cuw1 ), "3 sort wrong" );
        }
        public void SimpleCompareTestWithSegment()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.PeriodType = Element.PeriodType.duration;
            cp1.AddSegment( "key1", "key1", "key1", "key1" );

            cp2.PeriodType = Element.PeriodType.instant;

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            Assert.AreEqual( -1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( 1, Compare( cuw1, cuw2 ), "2 sort wrong" );

            ArrayList test = new ArrayList();
            test.Add( cuw1 );
            test.Add( cuw2 );

            test.Sort( new SortByDurationFirst() );

            Assert.AreEqual( cuw2.KeyName, ((MergedContextUnitsWrapper)test[0]).KeyName );
        }
        public void SimpleCompareTest()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.PeriodType = Element.PeriodType.duration;
            cp2.PeriodType = Element.PeriodType.instant;

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            Assert.AreEqual( 1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( -1, Compare( cuw1, cuw2 ), "2 sort wrong" );
        }
        public void OneSegBeforeTwoScenarios()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.AddScenario( "key11", "key11", "key11", "key11" );
            cp1.AddScenario( "key3", "key3", "key3", "key3" );

            cp2.AddSegment( "key1", "key1", "key1", "key1" );

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            // and compare them
            Assert.AreEqual( -1, Compare( cuw2, cuw1 ), "1 sort wrong" );
            Assert.AreEqual( 1, Compare( cuw1, cuw2 ), "2 sort wrong" );
        }
        public void DateTest()
        {
            ContextProperty cp1 = new ContextProperty();
            ContextProperty cp2 = new ContextProperty();

            cp1.PeriodType = Element.PeriodType.duration;
            cp1.PeriodStartDate = new DateTime( 2006, 1, 1 );
            cp1.PeriodEndDate = new DateTime( 2006, 3, 31 );

            cp2.PeriodType = Element.PeriodType.duration;
            cp2.PeriodStartDate = new DateTime( 2006, 4, 1 );
            cp2.PeriodEndDate = new DateTime( 2006, 6, 30 );

            MergedContextUnitsWrapper cuw1 = new MergedContextUnitsWrapper( "key1", cp1 );
            MergedContextUnitsWrapper cuw2 = new MergedContextUnitsWrapper( "key2", cp2 );

            /// x == y -> 0
            /// x > y -> 1
            /// x < y -> -1

            ArrayList arrg = new ArrayList();
            arrg.Add( cuw2 );
            arrg.Add( cuw1 );
            arrg.Sort( new SortByDurationFirst() );

            Assert.AreEqual( cp2.PeriodEndDate, ((MergedContextUnitsWrapper)arrg[0]).contextRef.PeriodEndDate, "index 0 wrong" );
            Assert.AreEqual( cp1.PeriodEndDate, ((MergedContextUnitsWrapper)arrg[1]).contextRef.PeriodEndDate, "index 1 wrong" );
        }
Example #11
0
        public static string GetCurrencyCodeFromMCU( MergedContextUnitsWrapper mcu )
        {
            if( mcu == null )
                return string.Empty;

            foreach( UnitProperty up in mcu.UPS )
            {
                string code = GetCurrencyCodeFromUnit( up );
                if( !string.IsNullOrEmpty( code ) )
                    return code;
            }

            return string.Empty;
        }
Example #12
0
        public object Clone()
        {
            //Clones all base type properties and shallow clones any complex types
            //Complex types will be recloned further down in the code.
            MergedContextUnitsWrapper mcu = this.MemberwiseClone() as MergedContextUnitsWrapper;

            mcu.contextRef = new ContextProperty(this.contextRef.ContextID);
            mcu.contextRef.EntitySchema      = this.contextRef.EntitySchema;
            mcu.contextRef.EntityValue       = this.contextRef.EntityValue;
            mcu.contextRef.PeriodDisplayName = this.contextRef.PeriodDisplayName;
            mcu.contextRef.PeriodEndDate     = this.contextRef.PeriodEndDate;
            mcu.contextRef.PeriodStartDate   = this.contextRef.PeriodStartDate;
            mcu.contextRef.PeriodType        = this.contextRef.PeriodType;

            mcu.contextRef.Segments = new ArrayList();

            #region clone segments

            foreach (Segment seg in this.contextRef.Segments)
            {
                Segment segClone = new Segment();

                //Setting DimensionInfo sets some of the other properties on the Segment, so to ensure that
                //the object is truely cloned set DimensionInfo first then set the other properties
                if (seg.DimensionInfo != null)
                {
                    segClone.DimensionInfo = seg.DimensionInfo.Clone() as ContextDimensionInfo;
                }

                segClone.Name      = seg.Name;
                segClone.ValueName = seg.ValueName;
                segClone.ValueType = seg.ValueType;
                segClone.Namespace = seg.Namespace;
                segClone.Schema    = seg.Schema;

                mcu.contextRef.AddSegment(segClone);
            }

            #endregion

            #region clone scenarios

            foreach (Scenario scen in this.contextRef.Scenarios)
            {
                Segment scenClone = new Segment();

                //Setting DimensionInfo sets some of the other properties on the scenario, so to ensure that
                //the object is truely cloned set DimensionInfo first then set the other properties
                if (scen.DimensionInfo != null)
                {
                    scenClone.DimensionInfo = scen.DimensionInfo.Clone() as ContextDimensionInfo;
                }

                scenClone.Name      = scen.Name;
                scenClone.ValueName = scen.ValueName;
                scenClone.ValueType = scen.ValueType;
                scenClone.Namespace = scen.Namespace;
                scenClone.Schema    = scen.Schema;

                mcu.contextRef.AddScenario(scen);
            }

            #endregion

            #region clone unit properties

            mcu.UPS = new List <UnitProperty>();
            foreach (UnitProperty up in this.UPS)
            {
                UnitProperty upClone = new UnitProperty(up.UnitID, up.UnitType);
                upClone.Scale = up.Scale;

                if (up.StandardMeasure != null)
                {
                    upClone.StandardMeasure = new Aucent.MAX.AXE.XBRLParser.Measure();
                    upClone.StandardMeasure.MeasureNamespace = up.StandardMeasure.MeasureNamespace;
                    upClone.StandardMeasure.MeasureSchema    = up.StandardMeasure.MeasureSchema;
                    upClone.StandardMeasure.MeasureValue     = up.StandardMeasure.MeasureValue;
                }

                if (up.MultiplyMeasures != null)
                {
                    upClone.MultiplyMeasures = new Aucent.MAX.AXE.XBRLParser.Measure[up.MultiplyMeasures.Length];
                    for (int i = 0; i < up.MultiplyMeasures.Length; i++)
                    {
                        upClone.MultiplyMeasures[i] = new Aucent.MAX.AXE.XBRLParser.Measure();
                        upClone.MultiplyMeasures[i].MeasureNamespace = up.MultiplyMeasures[i].MeasureNamespace;
                        upClone.MultiplyMeasures[i].MeasureSchema    = up.MultiplyMeasures[i].MeasureSchema;
                        upClone.MultiplyMeasures[i].MeasureValue     = up.MultiplyMeasures[i].MeasureValue;
                    }
                }

                if (up.NumeratorMeasure != null)
                {
                    upClone.NumeratorMeasure = new Aucent.MAX.AXE.XBRLParser.Measure();
                    upClone.NumeratorMeasure.MeasureNamespace = up.NumeratorMeasure.MeasureNamespace;
                    upClone.NumeratorMeasure.MeasureSchema    = up.NumeratorMeasure.MeasureSchema;
                    upClone.NumeratorMeasure.MeasureValue     = up.NumeratorMeasure.MeasureValue;
                }

                if (up.DenominatorMeasure != null)
                {
                    upClone.DenominatorMeasure = new Aucent.MAX.AXE.XBRLParser.Measure();
                    upClone.DenominatorMeasure.MeasureNamespace = up.DenominatorMeasure.MeasureNamespace;
                    upClone.DenominatorMeasure.MeasureSchema    = up.DenominatorMeasure.MeasureSchema;
                    upClone.DenominatorMeasure.MeasureValue     = up.DenominatorMeasure.MeasureValue;
                }

                mcu.UPS.Add(upClone);
            }

            #endregion

            mcu.CurrencySymbol = this.CurrencySymbol;
            mcu.CurrencyCode   = this.CurrencyCode;

            return(mcu);
        }