Пример #1
0
        public void Pattern_Set_ValueIsSet()
        {
            var locator = new StringContainsLocator();

            locator.Pattern = "EPS";

            Assert.That(locator.Pattern.ToString(), Is.EqualTo("EPS"));
        }
Пример #2
0
        public void Validate_IsValid_DoesNotThrows()
        {
            var locator = new StringContainsLocator {
                HeaderSeriesPosition = 4, Pattern = "Sales"
            };

            RecursiveValidator.Validate(locator);
        }
Пример #3
0
        public void HeaderSeriesPosition_Set_ValueIsSet()
        {
            var locator = new StringContainsLocator();

            locator.HeaderSeriesPosition = 6;

            Assert.That(locator.HeaderSeriesPosition, Is.EqualTo(6));
        }
Пример #4
0
        public void Pattern_Set_ChangeIsNotified()
        {
            var locator = new StringContainsLocator();
            var counter = new PropertyChangedCounter(locator);

            locator.Pattern = "EPS";

            Assert.That(counter.GetCount(nameof(locator.Pattern)), Is.EqualTo(1));
        }
Пример #5
0
        public void HeaderSeriesPosition_Set_ChangeIsNotified()
        {
            var locator = new StringContainsLocator();
            var counter = new PropertyChangedCounter(locator);

            locator.HeaderSeriesPosition = 6;

            Assert.That(counter.GetCount(nameof(locator.HeaderSeriesPosition)), Is.EqualTo(1));
        }
Пример #6
0
        public void Validate_PatternNull_Throws()
        {
            var locator = new StringContainsLocator {
                HeaderSeriesPosition = 0, Pattern = null
            };

            var ex = Assert.Throws <ValidationException>(() => RecursiveValidator.Validate(locator));

            Assert.That(ex.Message, Does.Contain("Pattern field is required"));
        }
Пример #7
0
        public void Validate_HeaderSeriesPositionOutOfRange_Throws()
        {
            var locator = new StringContainsLocator {
                HeaderSeriesPosition = -1, Pattern = "Sales"
            };

            var ex = Assert.Throws <ValidationException>(() => RecursiveValidator.Validate(locator));

            Assert.That(ex.Message, Does.Contain("HeaderSeriesPosition must be between 0 and " + int.MaxValue));
        }
Пример #8
0
        public void FindIndex_ListContainsNull_DoesNotThrow()
        {
            var locator = new StringContainsLocator {
                HeaderSeriesPosition = 0, Pattern = "abc"
            };

            var idx = locator.FindIndex(new[] { null, "x", "y", "abcdefg", null, "^7" });

            Assert.That(idx, Is.EqualTo(3));
        }
Пример #9
0
        public void Clone_WhenCalled_AllMembersAreCloned()
        {
            var locator = new StringContainsLocator {
                HeaderSeriesPosition = 4, Pattern = "Sales"
            };

            var clone = FigureDescriptorFactory.Clone(locator);

            Assert.That(clone.HeaderSeriesPosition, Is.EqualTo(4));
            Assert.That(clone.Pattern, Is.EqualTo("Sales"));
        }
Пример #10
0
        public IFormat GetFormat(Site site)
        {
            var newFormat = site.Format.Clone();

            // XXX: find a better way!!
            //      go for transformation rules
            foreach (var pi in newFormat.GetType().GetProperties())
            {
                if (!pi.CanWrite)
                {
                    continue;
                }

                if (pi.PropertyType == typeof(string))
                {
                    pi.SetValue(newFormat, LookupInternal((string)pi.GetValue(newFormat, null)), null);
                }
                else if (pi.PropertyType == typeof(Anchor))
                {
                    // xxx: hack to get string replacement in anchors running
                    var anchor = (Anchor)pi.GetValue(newFormat, null);
                    if (anchor != null)
                    {
                        var colLocator = anchor.Column;
                        var rowLocator = anchor.Row;
                        var locator    = colLocator as StringContainsLocator;
                        if (locator != null)
                        {
                            colLocator = new StringContainsLocator(locator.SeriesToScan, LookupInternal(locator.Pattern));
                        }
                        locator = rowLocator as StringContainsLocator;
                        if (locator != null)
                        {
                            rowLocator = new StringContainsLocator(locator.SeriesToScan, LookupInternal(locator.Pattern));
                        }
                        pi.SetValue(newFormat, Anchor.ForCell(rowLocator, colLocator), null);
                    }
                }
                else if (pi.PropertyType.HasInterface(typeof(IEnumerable)))
                {
                    var  list    = new List <object>();
                    bool changed = false;
                    foreach (var obj in (IEnumerable)pi.GetValue(newFormat, null))
                    {
                        if (obj.GetType() == typeof(string))
                        {
                            list.Add(LookupInternal((string)obj));
                            changed = true;
                        }
                        else
                        {
                            list.Add(obj);
                        }
                    }

                    if (changed)
                    {
                        if (pi.PropertyType.IsArray)
                        {
                            throw new NotSupportedException("Unable to handle properties of type System.Array");
                        }

                        // XXX: the trick is how to find the proper instance
                        //      or how to find the proper constructor
                        var newObj = Activator.CreateInstance(pi.PropertyType, list.ToArray());
                        pi.SetValue(newFormat, newObj, null);
                    }
                }
            }

            return(newFormat);
        }