Represents a physical file on the filesystem
        public RunnerResult Execute(object callingFixture, Resource resource, string href)
        {
            var runnerFixture = GetFixture(resource, href, callingFixture);

            var concordion = new ConcordionBuilder()
                                        .WithSource(Source)
                                        .WithTarget(Target)
                                        .Build();

            var results = concordion.Process(runnerFixture);

            Result result;
            if (results.HasFailures)
            {
                result = Result.Failure;
            }
            else if (results.HasExceptions)
            {
                result = Result.Exception;
            }
            else
            {
                result = Result.Success;
            }

		    return new RunnerResult(result);
        }
        public void Test_If_Paths_Are_Not_Identical_Can_Calculate_Relative_Path()
        {
            var from = new Resource(@"\spec\");
            var to = new Resource(@"\spec\blah");

            Assert.Equal<string>(@"blah", from.GetRelativePath(to));
        }
        public void Test_If_Paths_Are_Weird_And_End_In_Slashes_Can_Calculate_Relative_Path()
        {
            var from = new Resource(@"\x\b\c\");
            var to = new Resource(@"\a\b\x\");

            Assert.Equal<string>(@"..\..\..\a\b\x\", from.GetRelativePath(to));
        }
Example #4
0
        public ProcessingResult Process(Resource resource)
        {
            var eventRecorder = new EventRecorder();
            this.Target = new StubTarget();

            var concordionBuilder = new ConcordionBuilder()
                .WithEvaluatorFactory(this.EvaluatorFactory)
                .WithSource(this.Source)
                .WithTarget(this.Target)
                .WithAssertEqualsListener(eventRecorder)
                .WithExceptionListener(eventRecorder);

            if (this.Fixture != null)
            {
                new ExtensionLoader(this.Configuration).AddExtensions(this.Fixture, concordionBuilder);
            }

            if (this.Extension != null)
            {
                this.Extension.AddTo(concordionBuilder);
            }

            var concordion = concordionBuilder.Build();

            try
            {
                IResultSummary resultSummary = concordion.Process(resource, this.Fixture);
                string xml = this.Target.GetWrittenString(resource);
                return new ProcessingResult(resultSummary, eventRecorder, xml);
            }
            catch (Exception e)
            {
                throw new Exception("Test rig failed to process specification", e);
            }
        }
        public void Test_If_Paths_Point_To_File_And_Are_Identical_Can_Calculate_Relative_Path()
        {
            var from = new Resource(@"\spec\x.html");
            var to = new Resource(@"\spec\x.html");

            Assert.Equal<string>("x.html", from.GetRelativePath(to));
        }
        private void GenerateCommandCallTree(XElement element, CommandCall parentCommandCall, Resource resource)
        {
            bool isCommandAssigned = false;

            foreach (XAttribute attribute in element.Attributes())
            {
                string namespaceURI = attribute.Name.Namespace.NamespaceName;

                if (!attribute.IsNamespaceDeclaration && !String.IsNullOrEmpty(namespaceURI))
                {
                    string commandName = attribute.Name.LocalName;
                    ICommand command = CreateCommand(namespaceURI, commandName);
                    if (command != null)
                    {
                        Check.IsFalse(isCommandAssigned, "Multiple commands per element is currently not supported.");
                        isCommandAssigned = true;
                        String expression = attribute.Value;
                        CommandCall commandCall = new CommandCall(command, new Element(element), expression, resource);
                        parentCommandCall.AddChild(commandCall);
                        parentCommandCall = commandCall;
                    }
                }
            }

            foreach (XElement child in element.Elements())
            {
                GenerateCommandCallTree(child, parentCommandCall, resource);
            }
        }
 public IResultSummary Process(Resource resource, object fixture) 
 {
     var specification = SpecificationReader.ReadSpecification(resource);
     var resultRecorder = new SummarizingResultRecorder();
     specification.Process(EvaluatorFactory.CreateEvaluator(fixture), resultRecorder);
     return resultRecorder;
 }
 private void AnnounceBeforeProcessingEvent(Resource resource, Element element)
 {
     foreach (var listener in m_Listeners)
     {
         listener.BeforeProcessingSpecification(new SpecificationProcessingEvent(resource, element));
     }
 }
 private void OnSpecificationCommandProcessed(Resource resource, Element element)
 {
     if (SpecificationCommandProcessed != null)
     {
         SpecificationCommandProcessed(this, new SpecificationEventArgs { Element = element, Resource = resource });
     }
 }
        private void AddFooterToDocument(Element rootElement, Resource resource, long timeTaken)
        {
            Element body = rootElement.GetFirstChildElement("body");

            if (body != null)
            {

                Element footer = new Element("div");
                footer.AddStyleClass("footer");
                footer.AppendText("Results generated by ");

                Element link = new Element("a");
                link.AddAttribute("href", CONCORDION_WEBSITE_URL);
                footer.AppendChild(link);

                Element img = new Element("img");
                img.AddAttribute("src", resource.GetRelativePath(TARGET_LOGO_RESOURCE));
                img.AddAttribute("alt", "Concordion");
                img.AddAttribute("border", "0");
                link.AppendChild(img);

                Element dateDiv = new Element("div");
                dateDiv.AddStyleClass("testTime");
                dateDiv.AppendText("in " + (timeTaken + 1) + " ms ");
                dateDiv.AppendText(DateTime.Now.ToString());
                footer.AppendChild(dateDiv);

                body.AppendChild(footer);
            }
        }
 public CommandCall(ICommand command, Element element, string expression, Resource resource)
 {
     Children = new CommandCallList();
     Command = command;
     Element = element;
     Expression = expression;
     Resource = resource;
 } 
 public ISpecification Parse(XDocument document, Resource resource)
 {
     OnDocumentParsing(document);
     XElement rootElement = document.Root;
     CommandCall rootCommandCall = new CommandCall(CreateSpecificationCommand(), new Element(rootElement), "", resource);
     GenerateCommandCallTree(rootElement, rootCommandCall, resource);
     return new XmlSpecification(rootCommandCall);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ConcordionTest"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="codeElement">The code element.</param>
        /// <param name="typeInfo">The type info.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="fixtureType">The fixture type.</param>
        public ConcordionTest(string name, ICodeElementInfo codeElement, ConcordionTypeInfoAdapter typeInfo, Resource resource, Type fixtureType)
            : base(name, codeElement)
        {
            if (typeInfo == null)
                throw new ArgumentNullException(@"typeInfo");

            this.TypeInfo = typeInfo;
            this.Resource = resource;
            this.FixtureType = fixtureType;
        }
        public ISpecification ReadSpecification(Resource resource)
        {
            XDocument document;

            using (var inputStream = Source.CreateReader(resource))
            {
                document = XDocument.Load(inputStream);
            }

            return DocumentParser.Parse(document, resource);
        }
        public TextReader CreateReader(Resource resource)
        {
            var fullyQualifiedTypeName = ConvertPathToNamespace(resource.Path);

            if (CanFind(resource))
            {
                return new StreamReader(FixtureAssembly.GetManifestResourceStream(fullyQualifiedTypeName));
            }

            throw new InvalidOperationException(String.Format("Cannot open the resource {0}", fullyQualifiedTypeName));
        }
Example #16
0
        public void CopyTo(Resource resource, string destination)
        {
            Check.NotNull(resource, "resource is null");
            MakeDirectories(resource);
            string source = BaseDirectory + resource.Path;

            if (File.Exists(source) && IsFreshEnough(source))
            {
                return;
            }
            File.Copy(source, destination);
        }
Example #17
0
 public void CopyTo(Resource resource, TextReader inputReader)
 {
     Check.NotNull(resource, "resource is null");
     MakeDirectories(resource);
     var outputFile = GetTargetPath(resource);
     // Do not overwrite if a recent copy already exists
     if (File.Exists(outputFile) && IsFreshEnough(outputFile))
     {
         return;
     }
     IOUtil.Copy(inputReader, new StreamWriter(outputFile));
 }
Example #18
0
 public void AddResource(Resource resource, string content)
 {
     if (!this.resources.ContainsKey(resource))
     {
         this.resources.Add(resource, content);
     }
     else
     {
         this.resources.Remove(resource);
         this.resources.Add(resource, content);
     }
 }
Example #19
0
 private string ExistingFilePath(Resource resource)
 {
     var filePath = Path.Combine(BaseDirectory, resource.Path);
     if (File.Exists(filePath))
     {
         return filePath;
     }
     filePath = Path.Combine(BaseDirectory, resource.ReducedPath);
     if (File.Exists(filePath))
     {
         return filePath;
     }
     return null;
 }
        private void AppendBreadcrumbsTo(Element breadcrumbSpan, Resource documentResource)
        {
            Resource packageResource = documentResource.Parent;

            while (packageResource != null)
            {
                Resource indexPageResource = packageResource.GetRelativeResource(GetIndexPageName(packageResource));
                if (!indexPageResource.Equals(documentResource) && Source.CanFind(indexPageResource))
                {
                    try
                    {
                        PrependBreadcrumb(breadcrumbSpan, CreateBreadcrumbElement(documentResource, indexPageResource));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Trouble appending a breadcrumb", e);
                    }
                }
                packageResource = packageResource.Parent;
            }

        }
Example #21
0
        public ProcessingResult Process(Resource resource)
        {
            var eventRecorder = new EventRecorder();
            var stubTarget = new StubTarget();

            var concordion = new ConcordionBuilder()
                .WithAssertEqualsListener(eventRecorder)
                .WithExceptionListener(eventRecorder)
                .WithSource(Source)
                .WithEvaluatorFactory(EvaluatorFactory)
                .WithTarget(stubTarget)
                .Build();

            try
            {
                IResultSummary resultSummary = concordion.Process(resource, Fixture);
                string xml = stubTarget.GetWrittenString(resource);
                return new ProcessingResult(resultSummary, eventRecorder, xml);
            }
            catch (Exception e)
            {
                throw new Exception("Test rig failed to process specification", e);
            }
        }
        private void AddFooterToDocument(Element rootElement, Resource resource, long timeTaken)
        {
            Element body = rootElement.GetFirstChildElement("body");

            if (body != null)
            {

                Element footer = new Element("div");
                footer.AddStyleClass("footer");
                footer.AppendText("Powered by ");

                Element link = new Element("a");
                link.AddAttribute("href", CONCORDION_WEBSITE_URL);
                footer.AppendChild(link);

                Element img = new Element("img");
                img.AddAttribute("src", resource.GetRelativePath(TARGET_LOGO_RESOURCE));
                img.AddAttribute("alt", "Concordion");
                img.AddAttribute("border", "0");
                link.AppendChild(img);

                body.AppendChild(footer);
            }
        }
 public bool CanFind(Resource resource)
 {
     var fullyQualifiedTypeName = ConvertPathToNamespace(resource.Path);
     return FixtureAssembly.GetManifestResourceInfo(fullyQualifiedTypeName) != null;
 }
Example #24
0
        /// <summary>
        /// Gets the relative path.
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <returns></returns>
        public string GetRelativePath(Resource resource)
        {
            if (resource.Path == Path)
            {
                return Name;
            }

            // Find common stem and ignore it
            // Use ../ to move up the path from here to common stem
            // Append the rest of the path from resource

            string[] therePieces = resource.Package.Path.Split(new string[] {PATH_SEPARATOR.ToString()}, StringSplitOptions.RemoveEmptyEntries);
            string[] herePieces = Package.Path.Split(new string[] {PATH_SEPARATOR.ToString()}, StringSplitOptions.RemoveEmptyEntries);

            int sharedPiecesCount = 0;
            for (int i = 0; i < herePieces.Length; i++)
            {
                if (therePieces.Length <= i)
                {
                    break;
                }
                if (therePieces[i].Equals(herePieces[i]))
                {
                    sharedPiecesCount++;
                }
                else
                {
                    break;
                }
            }

            StringBuilder r = new StringBuilder();

            for (int i = sharedPiecesCount; i < herePieces.Length; i++)
            {
                r.Append(RELATIVE_PATH_INDICATOR);
            }

            for (int i = sharedPiecesCount; i < therePieces.Length; i++)
            {
                r.Append(therePieces[i]);
                r.Append(PATH_SEPARATOR);
            }

            if (resource.IsPackage)
            {
                return r.ToString();
            }
            return r.ToString() + resource.Name;
        }
Example #25
0
 public void Delete(Resource resource)
 {
     Check.NotNull(resource, "resource is null");
     File.Delete(BaseDirectory + resource.Path);
 }
Example #26
0
 private void MakeDirectories(Resource resource)
 {
     string path = Path.Combine(BaseDirectory, StripLeadingBackslash(resource.Parent.Path));
     Directory.CreateDirectory(path);
 }
Example #27
0
 private StreamWriter CreateWriter(Resource resource)
 {
     string path = this.GetTargetPath(resource);
     return new StreamWriter(path, false, Encoding.UTF8);
 }
Example #28
0
 public void Write(Resource resource, Bitmap image)
 {
     Check.NotNull(resource, "resource is null");
     MakeDirectories(resource);
     image.Save(Path.Combine(BaseDirectory, resource.Path), ImageFormat.Png);
 }
Example #29
0
 public void Write(Resource resource, string s)
 {
     Check.NotNull(resource, "resource is null");
     MakeDirectories(resource);
     using (StreamWriter writer = CreateWriter(resource))
     {
         try
         {
             writer.Write(s);
         }
         finally { }
     }
 }
Example #30
0
 public string ResolvedPathFor(Resource resource)
 {
     return GetTargetPath(resource);
 }