Ejemplo n.º 1
0
        public void ShouldBeFullyClonable()
        {
            var apples = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlResourceString);
            var clone  = apples.Clone();

            apples.ShouldBe(clone);
        }
Ejemplo n.º 2
0
        public void ShouldAllowInitializingFromCollectionOfResources()
        {
            var list    = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlResourceString);
            var newList = new ResourceList(list.Resources.Select(x => x));

            newList.Count.ShouldBe(list.Count, "Unable to initialize new ResourceList from a collection of Resources");
        }
        public void ShouldTransformFiles()
        {
            var path = SampleData.GenerateRandomTempPath("TransformFilesTests");

            SampleData.CreateSampleFileHierarchy(this.FileSystem, path);

            var apples = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlFruitResourceString("Apple"));

            var appleResourceOne     = apples.First(x => x.Key == "Resfit_Tests_Apple_Resource_One");
            var replacementOrangeOne = new Resource(
                "Resfit_Tests_Orange_Resource_One",
                "My orange is taking over the world");

            appleResourceOne.Transforms.Add(new ResourceReplacementTransform(replacementOrangeOne));
            new FileTransformer(this.FileSystem, apples).TransformDirectory(path, FileFilter.Typical);

            // -- Verify the files were changed as expected
            var changedAppleSourceFile = this.FileSystem.LoadFile(Path.Combine(path, "Apples.cs"));

            changedAppleSourceFile.ShouldNotContain("Resfit_Tests_Apple_Resource_One");
            changedAppleSourceFile.ShouldContain("Resfit_Tests_Orange_Resource_One");

            // -- Verify the resources where changd as expected
            var changedAppleResourcesFile = this.FileSystem.LoadFile(Path.Combine(path, "Apples.resx"));
            var changedAppleResources     = XmlResourceParser.ParseAsResourceList(changedAppleResourcesFile);

            changedAppleResources.ShouldNotContain(x => x.Key == "Resfit_Tests_Apple_Resource_One");
            var oranges = changedAppleResources.Where(x => x.Key == "Resfit_Tests_Orange_Resource_One").ToArray();

            oranges.Count().ShouldBe(1);
            var orange = oranges.First();

            orange.Key.ShouldBe("Resfit_Tests_Orange_Resource_One");
            orange.Value.ShouldBe("My orange is taking over the world");
        }
Ejemplo n.º 4
0
        private void LoadResourcesFromResxFile()
        {
            var xml = this.FileSystem.LoadXmlFile(this.ResxFile);

            var resourceList = XmlResourceParser.ParseAsResourceList(xml);

            this.WriteObject(resourceList);
        }
        public void ThenAllOfTheExistingResourcesFromTheResourceListWillBeReplacedWithTheirMatches()
        {
            var modifiedResources = XmlResourceParser.ParseAllResourceFiles(this.FileSystem, this.Context.DirectoryPath);

            var expectedResources = this.Context.ResourceList.TransformSelfIntoNewList();

            modifiedResources.Count.ShouldBe(expectedResources.Count);
            modifiedResources.ShouldBeSubsetOf(expectedResources);
        }
Ejemplo n.º 6
0
        public void ShouldAllowFilteringResourcesOnClone()
        {
            var list = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlResourceString);

            var newList = list.Clone(new ResourceFilter {
                KeyRegex = new Regex(@"Kiwi")
            });

            newList.ShouldAllBe(x => x.Key.Contains("Kiwi"));
        }
        public void ShouldParseXmlAsAResourceList()
        {
            var xmlDoc = XElement.Parse(SampleData.SampleXmlResourceString);

            var resourceList = XmlResourceParser.ParseAsResourceList(xmlDoc);

            resourceList.Count.ShouldBe(5);
            resourceList.Last().Key.ShouldBe("Resfit_Tests_Kiwi_Resource_Two");
            resourceList.Last().Value.ShouldBe("This is the second Kiwi resource in the file");
        }
        public void ThenItIsLoadedAsAListOfResources()
        {
            this.Context.ResourceList = XmlResourceParser.ParseAsResourceList(this.Context.Xml);

            this.Context.ResourceList.Count.ShouldBe(5);
            this.Context.ResourceList.First().Key.ShouldBe("Resfit_Tests_Banana_Resource_One");
            this.Context.ResourceList.First().Value.ShouldBe("This is the first Banana resource in the file");
            this.Context.ResourceList.Last().Key.ShouldBe("Resfit_Tests_Kiwi_Resource_Two");
            this.Context.ResourceList.Last().Value.ShouldBe("This is the second Kiwi resource in the file");
        }
        public void GivenAListOfResourcesWithMatches()
        {
            this.Context.DirectoryPath = SampleData.GenerateRandomTempPath("MatchAndReplaceTests");
            this.GenerateSampleSourceFiles(this.Context.DirectoryPath);

            this.Context.ResourceList = XmlResourceParser.ParseAllResourceFiles(this.FileSystem, this.Context.DirectoryPath);

            this.Context.ResourceList.First().Transforms.Add(new ResourceReplacementTransform(new Resource("Resfit_Tests_Banana_Resource_OneReplacement", "One replaced")));
            this.Context.ResourceList.Last().Transforms.Add(new ResourceReplacementTransform(new Resource("Resfit_Tests_Banana_Resource_ThreeReplacement", "Three replaced")));
        }
Ejemplo n.º 10
0
        private void LoadAllResourcesFromPath()
        {
            var directoryPath = Path.GetFullPath(this.Directory);

            this.WriteVerbose(string.Format("Loading all resources from path \"{0}\"", directoryPath));

            var resourceList = XmlResourceParser.ParseAllResourceFiles(this.FileSystem, directoryPath);

            this.WriteObject(resourceList);
        }
Ejemplo n.º 11
0
        public void MergesTwoResourceLists()
        {
            var apples  = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlFruitResourceString("apples"));
            var oranges = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlFruitResourceString("oranges"));

            var applesAndOranges = apples.Clone();

            applesAndOranges.Merge(oranges);

            apples.ShouldBeSubsetOf(applesAndOranges);
            oranges.ShouldBeSubsetOf(applesAndOranges, "The Oranges resource list was not merged in.");
        }
        public void ParsesAllResourcesInPath()
        {
            var path = SampleData.GenerateRandomTempPath("TransformFilesTests");

            SampleData.CreateSampleFileHierarchy(this.FileSystem, path);

            var resources = XmlResourceParser.ParseAllResourceFiles(this.FileSystem, path);

            resources.Count.ShouldBe(8);
            var appleTwoResource = resources.First(x => x.Key == "Resfit_Tests_Apple_Resource_Two");

            appleTwoResource.Value.ShouldBe("This is the second Apple resource in the file");
        }
Ejemplo n.º 13
0
        public void ShouldPerformAutoTransformIntoNewResourceList()
        {
            var apples  = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlFruitResourceString("apples"));
            var oranges = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlFruitResourceString("oranges")).ToArray();

            var orangeIndex = 0;

            foreach (var appleResource in apples)
            {
                appleResource.Transforms.Add(new ResourceReplacementTransform(oranges[orangeIndex++]));
            }

            var applesTransformedToOranges = apples.TransformSelfIntoNewList();

            applesTransformedToOranges.ShouldBeSubsetOf(oranges);
        }
Ejemplo n.º 14
0
        public View inflate(int resource, ViewGroup root, bool attachToRoot)
        {
            Resources res = getContext().getResources();

            if (DEBUG)
            {
                //Debug.WriteLine("INFLATING from resource: \"" + res.getResourceName(resource) + "\" (" + resource.ToString("X") + ")");
            }

            XmlResourceParser parser = res.getLayout(resource);

            try
            {
                return(inflate(parser, root, attachToRoot));
            }

            finally
            {
                parser.close();
            }
        }
 public void GivenAListOfResources()
 {
     this.Context.ResourceList = XmlResourceParser.ParseAsResourceList(SampleData.SampleXmlResourceString);
 }
 public void WhenILoadTheResourcesFromTheFileIntoANewResourceList()
 {
     this.Context.ResourceList = XmlResourceParser.ParseAsResourceList(this.Context.Xelement, this.Context.ResourceFilter);
 }
Ejemplo n.º 17
0
        private void parseInclude(XmlPullParser parser, View parent, AttributeSet attrs, bool inheritContext)
        {
            int type;

            //if (parent.GetType().Equals(typeof(ViewGroup)))
            if (parent is ViewGroup)
            {
                int layout = attrs.getAttributeResourceValue(null, "layout", 0); //This should return resource value, not name
                if (layout == 0)
                {
                    string value = attrs.getAttributeValue(null, "layout");
                    if (value == null)
                    {
                        throw new Exception("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
                    }
                    else
                    {
                        throw new Exception("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid.");
                    }
                }

                else
                {
                    XmlResourceParser childParser = getContext().getResources().getLayout(layout);

                    try
                    {
                        AttributeSet childAttrs = Xml.asAttributeSet(childParser, mContext);

                        while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT)
                        {
                            // Empty.
                        }

                        if (type != XmlPullParser.START_TAG)
                        {
                            throw new Exception(childParser.getPositionDescription() + ": No start tag found!");
                        }

                        string childName = childParser.getName();

                        if (TAG_MERGE.Equals(childName))
                        {
                            // Inflate all children.
                            rInflate(childParser, parent, childAttrs, false, inheritContext);
                        }
                        else
                        {
                            View      view  = createViewFromTag(parent, childName, childAttrs, inheritContext);
                            ViewGroup group = (ViewGroup)parent;

                            // We try to load the layout params set in the <include /> tag. If
                            // they don't exist, we will rely on the layout params set in the
                            // included XML file.
                            // During a layoutparams generation, a runtime exception is thrown
                            // if either layout_width or layout_height is missing. We catch
                            // this exception and set localParams accordingly: true means we
                            // successfully loaded layout params from the <include /> tag,
                            // false means we need to rely on the included layout params.
                            ViewGroup.LayoutParams lparams = null;
                            try
                            {
                                lparams = group.generateLayoutParams(attrs);
                            }
                            catch
                            {
                                lparams = group.generateLayoutParams(childAttrs);
                            }
                            finally
                            {
                                if (lparams != null)
                                {
                                    view.setLayoutParams(lparams);
                                }
                            }

                            // Inflate all children.
                            rInflate(childParser, view, childAttrs, true, true);

                            /*
                             * // Attempt to override the included layout's android:id with the
                             * // one set on the <include /> tag itself.
                             * TypedArray a = mContext.obtainStyledAttributes(attrs, com.android.inner.R.styleable.View, 0, 0);
                             * int id = a.getResourceId(com.android.inner.R.styleable.View_id, View.NO_ID);
                             * // While we're at it, let's try to override android:visibility.
                             * int visibility = a.getInt(com.android.inner.R.styleable.View_visibility, -1);
                             * a.recycle();
                             *
                             * if (id != View.NO_ID)
                             * {
                             *  view.setId(id);
                             * }
                             *
                             * switch (visibility)
                             * {
                             *  case 0:
                             *      view.setVisibility(View.VISIBLE);
                             *      break;
                             *  case 1:
                             *      view.setVisibility(View.INVISIBLE);
                             *      break;
                             *  case 2:
                             *      view.setVisibility(View.GONE);
                             *      break;
                             * }
                             */

                            group.addView(view);
                        }
                    }

                    finally { }
                }
            }
            else
            {
                throw new Exception("<include /> can only be used inside of a ViewGroup");
            }

            int currentDepth = parser.getDepth();

            while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT)
            {
                // Empty
            }
        }