Пример #1
0
 public Context(string name, int level)
 {
     Name = name.Replace("_", " ");
     Level = level;
     Examples = new List<Example>();
     Contexts = new ContextCollection();
 }
Пример #2
0
 public void Write(ContextCollection contexts)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine(FailureSummary(contexts));
     Console.ForegroundColor = ConsoleColor.White;
     Console.WriteLine(Summary(contexts));
 }
Пример #3
0
        public LinkInfo SetUpContext(PanelPreferences preferences, string skinFolderPath)
        {
            // Offline and Advanced mode Changes

            var linkInfo = new LinkInfo {FolderName = Res.FolderName};
            if (!preferences.OfflineMode)
            {
                CookieJar = Login(preferences);

                CookieJar = Home.HomeViewPostToPanelSettingsManager(CookieJar, preferences);  //Source code here contains the Panel Settings Form

                var collection = new ContextCollection(CookieJar.SourceCode);

                ContextInfo contextInfo = collection.FindAvailableContext();
                Environment = contextInfo.Environment;

                collection.UpdateFormValue(contextInfo.ContextIndex, -1, "OpenPortalSkinFolder", contextInfo.SubDomain);
                collection.UpdateFormValue(contextInfo.ContextIndex, -1, "PortalSkinPath", Res.PortalSkinPathParent + "/" + contextInfo.SubDomain + "/");
                collection.UpdateFormValue(contextInfo.ContextIndex, -1, "IsHidden", "False");
                collection.UpdateFormValue(contextInfo.ContextIndex, -1, "Name", preferences.CompanyName + " Portal");
                // Added for Language selection
                collection.UpdateFormValue(contextInfo.ContextIndex, -1, "Culture", preferences.Language);

                PanelSettingsManagement.PanelSettingsUpdatePost(CookieJar, collection, preferences);
                linkInfo.FolderName = contextInfo.SubDomain;
                linkInfo.PortalLink = contextInfo.OpenPortalTestBaseUrl; //TODO CHANGE TO LIVE LINK
            }
            return linkInfo;
        }
Пример #4
0
        protected when_running_specs Run(params Type[] types)
        {
            //if (types.Count() == 1) tags = types.First().Name;

            this.types = types;

            builder = new ContextBuilder(new SpecFinder(types), new Tags().Parse(tags), new DefaultConventions());

            runner = new ContextRunner(builder, formatter, failFast);

            contextCollection = builder.Contexts();

            contextCollection.Build();

            classContext = contextCollection
                .AllContexts()
                .Where(c => c is ClassContext)
                .Cast<ClassContext>()
                .FirstOrDefault(c => types.Contains(c.type));

            methodContext = contextCollection.AllContexts().FirstOrDefault(c => c is MethodContext);

            runner.Run(contextCollection);

            return this;
        }
Пример #5
0
        public ContextCollection GetContextCollection(PanelPreferences preferences)
        {
            CookieJar = preferences.CookieJar;
            ContextCollection collection;
            try
            {
                if (CookieJar.SourceCode.IndexOf("Settings are locked by VcAdmin") > 0)
                {
                    throw new Exception("Settings are currently locked, navigate away from settings, recycle or wait");
                }
                collection = new ContextCollection(CookieJar.SourceCode);
            }
            catch (Exception e)
            {
                // attempt to Navigate away to attempt not to lock panel settings
                try
                {
                    PanelSettingsManagement.PanelSettingsPostToAssetManager(CookieJar, preferences);
                }
                catch (Exception) { }
                throw e;
            }

            return collection;
        }
Пример #6
0
        public void Write( ContextCollection contexts )
        {
            contexts.Do( c => Console.WriteLine( Write( c ) ) );

            Console.WriteLine( FailureSummary( contexts ) );

            Console.WriteLine( Summary( contexts ) );
        }
Пример #7
0
        public ContextBuilder(ISpecFinder finder, Conventions conventions)
        {
            this.finder = finder;

            contexts = new ContextCollection();

            this.conventions = conventions;
        }
Пример #8
0
 public Context(string name = "", int level = 0, bool isPending = false)
 {
     Name = name.Replace("_", " ");
     Level = level;
     Examples = new List<Example>();
     Contexts = new ContextCollection();
     this.isPending = isPending;
 }
Пример #9
0
 public Context(string name = "", string tags = null, bool isPending = false)
 {
     Name = name.Replace("_", " ");
     Examples = new List<Example>();
     Contexts = new ContextCollection();
     Tags = Domain.Tags.ParseTags(tags);
     this.isPending = isPending;
 }
Пример #10
0
 public string Summary( ContextCollection contexts )
 {
     return "{0} Examples, {1} Failed, {2} Pending".With(
         contexts.Examples().Count(),
         contexts.Failures().Count(),
         contexts.Pendings().Count()
     );
 }
Пример #11
0
        public string FailureSummary( ContextCollection contexts )
        {
            if( contexts.Failures().Count() == 0 ) return "";

            var summary = Environment.NewLine + "**** FAILURES ****" + Environment.NewLine;

            contexts.Failures().Do( f => summary += WriteFailure( f ) );

            return summary;
        }
Пример #12
0
        public string FailureSummary(ContextCollection contexts)
        {
            if (contexts.Failures().Count() == 0) return "";

            var summary = "\n" + "**** FAILURES ****" + "\n";

            contexts.Failures().Do(f => summary += WriteFailure(f));

            return summary;
        }
Пример #13
0
        public ContextBuilder(ISpecFinder finder, Tags tagsFilter, Conventions conventions)
        {
            contexts = new ContextCollection();

            this.finder = finder;

            this.conventions = conventions;

            this.tagsFilter = tagsFilter;
        }
Пример #14
0
        public void setup()
        {
            contexts = new ContextCollection();

            var context = new Context();

            context.AddExample(new Example());

            context.AddExample(new Example(pending:true));

            context.AddExample(new Example{Exception = new Exception()});

            contexts.Add(context);
        }
Пример #15
0
        public string Summary(ContextCollection contexts)
        {
            var summary = "{0} Examples, {1} Failed, {2} Pending".With(
                contexts.Examples().Count(),
                contexts.Failures().Count(),
                contexts.Pendings().Count()
                );

            if (contexts.AnyTaggedWithFocus())
            {
                summary += Environment.NewLine + Environment.NewLine + @"NSpec found context/examples tagged with ""focus"" and only ran those.";
            }

            return summary;
        }
        public void setup()
        {
            contexts = new ContextCollection();

            var context = new Context();

            context.AddExample(new ExampleBaseWrap());

            context.AddExample(new ExampleBaseWrap { Pending = true });

            context.AddExample(new ExampleBaseWrap { Exception = new Exception() });

            context.Tags.Add(Tags.Focus);

            contexts.Add(context);
        }
Пример #17
0
            void IFormatter.Write(ContextCollection contexts)
            {
                //Not calling base here lets us get rid of its noisy stack trace output so it does not obscure our thrown exceptions stacktrace.
                Console.WriteLine();
                if (contexts.Failures().Any())
                {
                    WriteNoticably("SUMMARY");
                    Console.WriteLine(base.Summary(contexts));

                    int currentFailure = 0;
                    foreach (var failure in contexts.Failures())
                    {
                        Console.WriteLine();
                        Console.Write("#################################  FAILURE {0} #################################", ++currentFailure);

                        var current         = failure.Context;
                        var relatedContexts = new List <Context>()
                        {
                            current
                        };
                        while (null != (current = current.Parent))
                        {
                            relatedContexts.Add(current);
                        }

                        var levels = relatedContexts.Select(me => me.Name)
                                     .Reverse()
                                     .Skip(1)
                                     .Concat(new string[] { failure.Spec + " - " + failure.Exception.Message });

                        var message = levels
                                      .Select((name, level) => "\t".Times(level) + name)
                                      .Aggregate(Environment.NewLine + "at: ", (agg, curr) => agg + curr + Environment.NewLine);

                        Console.WriteLine(message);

                        Console.WriteLine(base.WriteFailure(failure));
                    }
                }



                Console.WriteLine();
                WriteNoticably("END OF NSPEC RESULTS");
                Console.WriteLine();
            }
Пример #18
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            XmlTextWriter xml = new XmlTextWriter(sw);

            xml.WriteStartElement("testsuites");
            xml.WriteAttributeString("tests", contexts.Examples().Count().ToString());
            xml.WriteAttributeString("errors", "0");
            xml.WriteAttributeString("failures", contexts.Failures().Count().ToString());
            xml.WriteAttributeString("skip", contexts.Pendings().Count().ToString());

            contexts.Do(c => this.BuildContext(xml, c));
            xml.WriteEndElement();

            Console.WriteLine(sb.ToString());
        }
        public override void before_each()
        {
            base.before_each();

            var firstLevelContext = new Context("first-level context");

            foreach (var ctx in someContexts)
            {
                ctx.Parent = firstLevelContext;
            }

            firstLevelContext.Contexts = someContextCollection;

            var firstLevelContextCollection = new ContextCollection(new[] { firstLevelContext });

            contextFinder.BuildContextCollection(somePath).Returns(firstLevelContextCollection);
        }
        public NSpecResultModel Run(string specName)
        {
            var reflector     = new Reflector(this._dllFile);
            var nspecInstance = new nspec();
            var conventions   = new DefaultConventions();
            var finder        = new SpecFinder(reflector);

            var builder  = new ContextBuilder(finder, new Tags().Parse(_tags), new DefaultConventions());
            var contexts = builder.Contexts().Build();

            var context            = contexts.AllContexts().FirstOrDefault(t => t.Name == specName);
            var parentTypeInstance = contexts.AllContexts().FirstOrDefault(t => t is ClassContext);

            if (context != null && !context.HasAnyExecutedExample() && parentTypeInstance != null)
            {
                ILiveFormatter liveFormatter = new SilentLiveFormatter();

                if (_formatter is ILiveFormatter)
                {
                    liveFormatter = _formatter as ILiveFormatter;
                }

                var instance = (parentTypeInstance as ClassContext).type.Instance <nspec>();
                context.Contexts.Where(t => t is MethodContext).Do(t => (t as MethodContext).Build(instance));

                context.Run(_formatter as ILiveFormatter, false, instance);
                context.AssignExceptions();

                if (builder.tagsFilter.HasTagFilters())
                {
                    context.TrimSkippedDescendants();
                }
            }

            var contextCollection = new ContextCollection {
                context
            };

            _formatter.Write(contextCollection);
            var serializableContextCollection = new SerializableContextCollection();

            BuildResponse(serializableContextCollection, contextCollection);
            return(new NSpecResultModel {
                ContextCollection = serializableContextCollection, Output = _formatter.GetFormattedString
            });
        }
Пример #21
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            XmlTextWriter xml = new XmlTextWriter(sw);

            xml.WriteStartElement("Contexts");
            xml.WriteAttributeString("TotalSpecs", contexts.Examples().Count().ToString());
            xml.WriteAttributeString("TotalFailed", contexts.Failures().Count().ToString());
            xml.WriteAttributeString("TotalPending", contexts.Pendings().Count().ToString());

            xml.WriteAttributeString("RunDate", DateTime.Now.ToString());
            contexts.Do(c => this.BuildContext(xml, c));
            xml.WriteEndElement();

            Console.WriteLine(sb.ToString());
        }
Пример #22
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder   sb         = new StringBuilder();
            StringWriter    sw         = new StringWriter(sb);
            XmlWriteWrapper xmlWrapper = new XmlWriteWrapper(sw);

            var xml = xmlWrapper.Xml;

            xml.WriteStartElement("testsuites");
            xml.WriteAttributeString("tests", contexts.Examples().Count().ToString());
            xml.WriteAttributeString("errors", "0");
            xml.WriteAttributeString("failures", contexts.Failures().Count().ToString());
            xml.WriteAttributeString("skip", contexts.Pendings().Count().ToString());

            contexts.Do(c => this.BuildContext(xmlWrapper, c));

            xml.WriteEndElement();
            xml.Flush();

            var  results        = sb.ToString();
            bool didWriteToFile = false;

            if (Options.ContainsKey("file"))
            {
                var filePath = Path.Combine(Directory.GetCurrentDirectory(), Options["file"]);

                using (var stream = new FileStream(filePath, FileMode.Create))
                    using (var writer = new StreamWriter(stream, Encoding.Unicode))
                    {
                        writer.WriteLine(results);
                        Console.WriteLine("Test results published to: {0}".With(filePath));
                    }

                didWriteToFile = true;
            }
            if (didWriteToFile && Options.ContainsKey("console"))
            {
                Console.WriteLine(results);
            }

            if (!didWriteToFile)
            {
                Console.WriteLine(results);
            }
        }
        public void setup()
        {
            contexts = new ContextCollection();

            var context = new Context();

            context.AddExample(new ExampleBaseWrap());

            context.AddExample(new ExampleBaseWrap(pending: true));

            context.AddExample(new ExampleBaseWrap {
                Exception = new KnownException()
            });

            context.Tags.Add(Tags.Focus);

            contexts.Add(context);
        }
Пример #24
0
        public static void ParseContexts(XDocument report, Instance instance)
        {
            // parse contexts and add to instance
            // ix:header/ix:resources/xbrli:context
            var contextNs         = report.Root.GetNamespaceOfPrefix("xbrli");
            var contextElements   = report.Root.Descendants(contextNs + "context");
            var contextSerializer = new XmlSerializer(typeof(Context));

            var contexts = new ContextCollection(instance);

            foreach (var contextElement in contextElements)
            {
                var contextReader = contextElement.CreateReader();
                var context       = (Context)contextSerializer.Deserialize(contextReader);
                contexts.Add(context);
            }
            instance.Contexts = contexts;
        }
Пример #25
0
        public void setup()
        {
            contexts = new ContextCollection();

            var context = new Context();

            context.AddExample(new Example());

            context.AddExample(new Example {
                Pending = true
            });

            context.AddExample(new Example {
                Exception = new Exception()
            });

            contexts.Add(context);
        }
Пример #26
0
        private async Task CoreAction(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData, CompilationAsync action)
        {
            var index = 0;

            while (ContinueBuilding(outputStream, scopeData))
            {
                var collectionContext = new ContextCollection(index++, false, context.Key,
                                                              context.Parent, context.Value);

                //TODO get a way how to execute this on the caller
                await action(outputStream, collectionContext, scopeData);

                if (!(await MorestachioExpression.GetValue(collectionContext, scopeData)).Exists())
                {
                    break;
                }
            }
        }
Пример #27
0
        public void UpdateChannelsList()
        {
            eChannelsList.Items.Clear();
            eChannelsList.Items.Add(((IIrcContext)ContextCollection.Server).Name);
            //eChannelsList.Items.AddRange(ContextCollection.GetContextNames().ToArray());

            foreach (string name in ContextCollection.GetContextNames())
            {
                if (ContextCollection.ActiveContexts.Contains(name))
                {
                    eChannelsList.Items.Add("* " + name);
                }
                else
                {
                    eChannelsList.Items.Add(name);
                }
            }
        }
Пример #28
0
        public void Run()
        {
            var contexts = new ContextCollection();

            try
            {
                contexts = builder.Contexts();

                contexts.Build();

                contexts.Run();

                formatter.Write(contexts);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #29
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder   sb         = new StringBuilder();
            StringWriter    sw         = new StringWriter(sb);
            XmlWriteWrapper xmlWrapper = new XmlWriteWrapper(sw);

            var xml = xmlWrapper.Xml;

            xml.WriteStartElement("Contexts");
            xml.WriteAttributeString("TotalSpecs", contexts.Examples().Count().ToString());
            xml.WriteAttributeString("TotalFailed", contexts.Failures().Count().ToString());
            xml.WriteAttributeString("TotalPending", contexts.Pendings().Count().ToString());

            xml.WriteAttributeString("RunDate", DateTime.Now.ToString());
            contexts.Do(c => this.BuildContext(xmlWrapper, c));
            xml.WriteEndElement();

            Console.WriteLine(sb.ToString());
        }
Пример #30
0
        /// <inheritdoc />
        public override async ItemExecutionPromise Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData)
        {
            var index = 0;

            while (ContinueBuilding(outputStream, context))
            {
                var collectionContext = new ContextCollection(index++, false, context.Options, context.Key,
                                                              context.Parent, context.Value);

                //TODO get a way how to execute this on the caller
                await MorestachioDocument.ProcessItemsAndChildren(Children, outputStream, collectionContext, scopeData);

                if (!(await MorestachioExpression.GetValue(collectionContext, scopeData)).Exists())
                {
                    break;
                }
            }
            return(new DocumentItemExecution[0]);
        }
Пример #31
0
            void IFormatter.Write(ContextCollection contexts)
            {
                //Not calling base here lets us get rid of its noisy stack trace output so it does not obscure our thrown exceptions stacktrace.
                Console.WriteLine();
                if(contexts.Failures().Any())
                {
                    WriteNoticably("SUMMARY");                    
                    Console.WriteLine(base.Summary(contexts));

                    int currentFailure = 0;
                    foreach (var failure in contexts.Failures())
                    {
                        Console.WriteLine();
                        Console.Write("#################################  FAILURE {0} #################################", ++currentFailure);

                        var current = failure.Context;
                        var relatedContexts = new List<Context>() { current };
                        while (null != (current = current.Parent))
                        {
                            relatedContexts.Add(current);
                        }

                        var levels = relatedContexts.Select(me => me.Name)
                                                    .Reverse()
                                                    .Skip(1)
                                                    .Concat(new string[] { failure.Spec + " - " + failure.Exception.Message });

                        var message = levels
                            .Select((name, level) => "\t".Times(level) + name)
                            .Aggregate(Environment.NewLine + "at: ", (agg, curr) => agg + curr + Environment.NewLine);

                        Console.WriteLine(message);

                        Console.WriteLine(base.WriteFailure(failure));                        
                    }
                }

                

                Console.WriteLine();
                WriteNoticably("END OF NSPEC RESULTS");                
                Console.WriteLine();
            }
Пример #32
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<html>");
            sb.AppendLine("<head>");
            sb.AppendLine("<style type=\"text/css\">");
            sb.AppendLine("body {font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:12px;}");
            sb.AppendLine("  span {padding: 0.5em}");
            sb.AppendLine("  ul {margin-top: 0px}");
            sb.AppendLine("  .results {background-color: #FFFFCC; border:1px solid #d8d8d8; font-weight:bold; white-space: pre-wrap; text-align: center; padding: 0.5em}");
            sb.AppendLine("  .context-parent {border:1px solid #d8d8d8; margin-bottom: 1em;}");
            sb.AppendLine("  .context-parent-title {border:1px solid #d8d8d8;font-weight:bold; padding: 0.5em;background-color:#d8d8d8}");
            sb.AppendLine("  .context-parent-body {padding: 1em 2em 1em 0;}");
            sb.AppendLine("  .context-parent-name {font-weight:bold;}");
            sb.AppendLine("  .spec-passed {font-weight:bold; color:green;}");
            sb.AppendLine("  .spec-failed {font-weight:bold; color:#FF0000;}");
            sb.AppendLine("  .spec-pending {font-weight:bold; color:#0000FF;}");
            sb.AppendLine("  .spec-exception {background-color: #FFD2CF; border:1px solid #FF828D;padding: 1em; font-size:11px; white-space: pre-wrap; padding: 0.5em}");
            sb.AppendLine("  .run-date {color:grey; font-size:x-small;}");
            sb.AppendLine("</style>");
            sb.AppendLine("</head>");
            sb.AppendLine("<body>");

            sb.AppendLine();
            sb.Append("<div class=\"results\">");
            sb.AppendFormat("<div>Assembly: {0}</div>", ((((NSpec.Domain.ClassContext)(contexts.FirstOrDefault())).type).Assembly).FullName);
            sb.AppendFormat("Specs:<span>{0}</span>", contexts.Examples().Count());
            sb.AppendFormat("Failed:<span class=\"spec-failed\">{0}</span>", contexts.Failures().Count());
            sb.AppendFormat("Pending:<span class=\"spec-pending\">{0}</span>", contexts.Pendings().Count());
            sb.AppendFormat("<div class=\"run-date\">Run Date: {0}</div>", DateTime.Now);
            sb.Append("</div>");
            sb.AppendLine();
            sb.AppendLine("<br />");

            contexts.Do(c => this.BuildParentContext(sb, c));

            sb.AppendLine("</html>");
            sb.AppendLine("</body>");

            Console.WriteLine(sb.ToString());
        }
Пример #33
0
        public void Write(ContextCollection contexts)
        {
            contexts.Do(c => this.tiddlers.Add(c.Name, this.BuildTiddlerFrom(c)));

            StringBuilder menuItemsOutput = new StringBuilder();
            StringBuilder tiddlersOutput = new StringBuilder();
            foreach (var context in this.tiddlers.Keys)
            {
                menuItemsOutput.AppendFormat("[[{0}]]", context);
                menuItemsOutput.AppendLine();

                tiddlersOutput.Append(this.tiddlers[context]);
            }
            int examplesCount = contexts.Examples().Count();
            int failuresCount = contexts.Failures().Count();
            int pendingsCount = contexts.Pendings().Count();

            this.WriteTiddlyWiki(menuItemsOutput.ToString(), tiddlersOutput.ToString(),
                                 examplesCount, failuresCount, pendingsCount);
        }
Пример #34
0
        /// <param name="compiler"></param>
        /// <inheritdoc />
        public CompilationAsync Compile(IDocumentCompiler compiler)
        {
            var children   = compiler.Compile(Children);
            var expression = MorestachioExpression.Compile();

            return(async(stream, context, scopeData) =>
            {
                var c = await expression(context, scopeData);

                if (!c.Exists())
                {
                    return;
                }

                if (!(Number.IsIntegralNumber(c.Value)))
                {
                    var path = new Stack <string>();
                    var parent = context.Parent;
                    while (parent != null)
                    {
                        path.Push(parent.Key);
                        parent = parent.Parent;
                    }

                    throw new IndexedParseException(CharacterLocationExtended.Empty,
                                                    string.Format(
                                                        "{1}'{0}' is expected to return a integral number but did not." +
                                                        " Complete Expression until Error:{2}",
                                                        MorestachioExpression, base.ExpressionStart,
                                                        (path.Count == 0 ? "Empty" : path.Aggregate((e, f) => e + "\r\n" + f))));
                }

                var nr = new Number(c.Value as IConvertible);
                for (int i = 0; i < nr; i++)
                {
                    var contextCollection = new ContextCollection(i, i + 1 == nr, $"[{i}]", context,
                                                                  context.Value);
                    await children(stream, contextCollection, scopeData);
                }
            });
        }
Пример #35
0
        /// <inheritdoc />
        public override async Task <IEnumerable <DocumentItemExecution> > Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData)
        {
            var index = 0;

            var collectionContext = new ContextCollection(index, false, context.Options, context.Key, context.Parent)
            {
                Value = context.Value
            };

            while (ContinueBuilding(outputStream, context) && await(await MorestachioExpression.GetValue(collectionContext, scopeData)).Exists())
            {
                //TODO get a way how to execute this on the caller
                await MorestachioDocument.ProcessItemsAndChildren(Children, outputStream, collectionContext, scopeData);

                collectionContext = new ContextCollection(++index, false, context.Options, context.Key, context.Parent)
                {
                    Value = context.Value
                };
            }
            return(new DocumentItemExecution[0]);
        }
Пример #36
0
        public void Write(ContextCollection contexts)
        {
            contexts.Do(c => this.tiddlers.Add(c.Name, this.BuildTiddlerFrom(c)));

            StringBuilder menuItemsOutput = new StringBuilder();
            StringBuilder tiddlersOutput  = new StringBuilder();

            foreach (var context in this.tiddlers.Keys)
            {
                menuItemsOutput.AppendFormat("[[{0}]]", context);
                menuItemsOutput.AppendLine();

                tiddlersOutput.Append(this.tiddlers[context]);
            }
            int examplesCount = contexts.Examples().Count();
            int failuresCount = contexts.Failures().Count();
            int pendingsCount = contexts.Pendings().Count();

            this.WriteTiddlyWiki(menuItemsOutput.ToString(), tiddlersOutput.ToString(),
                                 examplesCount, failuresCount, pendingsCount);
        }
Пример #37
0
        public ContextCollection Run(ContextCollection contexts)
        {
            try
            {
                ILiveFormatter liveFormatter = new SilentLiveFormatter();

                if (formatter is ILiveFormatter) liveFormatter = formatter as ILiveFormatter;

                contexts.Run(liveFormatter, failFast);

                if (builder.tagsFilter.HasTagFilters()) contexts.TrimSkippedContexts();

                formatter.Write(contexts);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return contexts;
        }
Пример #38
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<html>");
            sb.AppendLine("<head>");
            sb.AppendLine("<style type=\"text/css\">");
            sb.AppendLine("  span {padding: 0.5em}");
            sb.AppendLine("  ul {margin-top: 0px}");
            sb.AppendLine("  .results {background-color: #FFFFCC; border-color: #000000; border-style: dashed; border-width: thin; font-weight:bold; white-space: pre-wrap; text-align: center; padding: 0.5em}");
            sb.AppendLine("  .context-parent {border-color: #000000; border-style: dashed; border-width: thin; margin-bottom: 1em;}");
            sb.AppendLine("  .context-parent-title {background-color: #6699FF; border-color: #000000; border-bottom-style: dashed; border-width: thin; font-weight:bold; padding: 0.5em}");
            sb.AppendLine("  .context-parent-body {padding: 1em 2em 1em 0;}");
            sb.AppendLine("  .context-parent-name {font-weight:bold;}");
            sb.AppendLine("  .spec-passed {font-weight:bold; color:green;}");
            sb.AppendLine("  .spec-failed {font-weight:bold; color:#FF0000;}");
            sb.AppendLine("  .spec-pending {font-weight:bold; color:#0000FF;}");
            sb.AppendLine("  .spec-exception {background-color: #FFD2CF; border-color: #FF828D; border-style: dashed; border-width: thin; padding: 1em; font-size:small; white-space: pre-wrap; padding: 0.5em}");
            sb.AppendLine("  .run-date {color:grey; font-size:x-small;}");
            sb.AppendLine("</style>");
            sb.AppendLine("</head>");
            sb.AppendLine("<body>");

            sb.AppendLine();
            sb.Append("<div class=\"results\">");
            sb.AppendFormat("Specs:<span>{0}</span>", contexts.Examples().Count());
            sb.AppendFormat("Failed:<span class=\"spec-failed\">{0}</span>", contexts.Failures().Count());
            sb.AppendFormat("Pending:<span class=\"spec-pending\">{0}</span>", contexts.Pendings().Count());
            sb.AppendFormat("<div class=\"run-date\">Run Date: {0}</div>", DateTime.Now);
            sb.Append("</div>");
            sb.AppendLine();
            sb.AppendLine("<br />");

            contexts.Do(c => this.BuildParentContext(sb, c));

            sb.AppendLine("</html>");
            sb.AppendLine("</body>");

            Console.WriteLine(sb.ToString());
        }
        private void BuildResponse(SerializableContextCollection contextCollection, ContextCollection collection)
        {
            foreach (var rootContext in collection)
            {
                // create a context
                var context = (rootContext as ClassContext) != null ? new SerializableClassContext() : new SerializableContext();
                context.Name   = rootContext.Name;
                context.Parent = new SerializableContext {
                    Name = rootContext.Parent.Name
                };
                context.Exception = rootContext.Failures().Count() > 0 ? new SerializableExampleFailureException {
                    ExampleException = rootContext.Failures().Select(t => t.Exception as Exception).FirstOrDefault().GetBaseException()
                } : null;
                context.Tags       = rootContext.Tags;
                context.Level      = rootContext.Level;
                context.UniqueName = GetExampleName(rootContext, string.Empty);
                _tagsCollection.AddRange(rootContext.Tags);

                context.Examples = rootContext.Examples != null?rootContext.Examples.Select(t => new SerializableExampleBase
                {
                    Spec      = t.Spec,
                    Exception = t.Exception != null ? new SerializableExampleFailureException {
                        ExampleException = t.Exception.GetBaseException()
                    } : null,
                    Tags       = t.Tags,
                    UniqueName = GetExampleName(t.Context, t.Spec),
                    Context    = new SerializableContext {
                        Name = rootContext.Parent.Name
                    }
                }).ToList() : null;

                _tagsCollection.AddRange(rootContext.AllExamples().SelectMany(t => t.Tags));
                if (rootContext.Contexts.Count > 0)
                {
                    context.Contexts = new SerializableContextCollection();
                    BuildResponse(context.Contexts, rootContext.Contexts);
                }
                contextCollection.Add(context);
            }
        }
Пример #40
0
        public void Write(ContextCollection contexts)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<html>");
            sb.AppendLine("<head>");
            sb.AppendLine("<style type=\"text/css\">");
            sb.AppendLine("  span {padding: 0.5em}");
            sb.AppendLine("  ul {margin-top: 0px}");
            sb.AppendLine("  .results {background-color: #FFFFCC; border-color: #000000; border-style: dashed; border-width: thin; font-weight:bold; white-space: pre-wrap; text-align: center; padding: 0.5em}");
            sb.AppendLine("  .context-parent {border-color: #000000; border-style: dashed; border-width: thin; margin-bottom: 1em;}");
            sb.AppendLine("  .context-parent-title {background-color: #6699FF; border-color: #000000; border-bottom-style: dashed; border-width: thin; font-weight:bold; padding: 0.5em}");
            sb.AppendLine("  .context-parent-body {padding: 1em 2em 1em 0;}");
            sb.AppendLine("  .context-parent-name {font-weight:bold;}");
            sb.AppendLine("  .spec-passed {font-weight:bold; color:green;}");
            sb.AppendLine("  .spec-failed {font-weight:bold; color:#FF0000;}");
            sb.AppendLine("  .spec-pending {font-weight:bold; color:#0000FF;}");
            sb.AppendLine("  .spec-exception {background-color: #FFD2CF; border-color: #FF828D; border-style: dashed; border-width: thin; padding: 1em; font-size:small; white-space: pre-wrap; padding: 0.5em}");
            sb.AppendLine("  .run-date {color:grey; font-size:x-small;}");
            sb.AppendLine("</style>");
            sb.AppendLine("</head>");
            sb.AppendLine("<body>");

            sb.AppendLine();
            sb.Append("<div class=\"results\">");
            sb.AppendFormat("Specs:<span>{0}</span>", contexts.Examples().Count());
            sb.AppendFormat("Failed:<span class=\"spec-failed\">{0}</span>", contexts.Failures().Count());
            sb.AppendFormat("Pending:<span class=\"spec-pending\">{0}</span>", contexts.Pendings().Count());
            sb.AppendFormat("<div class=\"run-date\">Run Date: {0}</div>", DateTime.Now);
            sb.Append("</div>");
            sb.AppendLine();
            sb.AppendLine("<br />");

            contexts.Do(c => this.BuildParentContext(sb, c));

            sb.AppendLine("</html>");
            sb.AppendLine("</body>");

            Console.WriteLine(sb.ToString());
        }
Пример #41
0
        private static async Promise LoopCollection(IByteCounterStream outputStream, ContextObject c, ScopeData scopeData,
                                                    Func <ContextObject, Promise> onItem, ICollection value)
        {
            var index        = 0;
            var innerContext =
                new ContextCollection(index, false, $"[{index}]", c, null)
                .MakeNatural() as ContextCollection;

            foreach (var item in value)
            {
                if (!ContinueBuilding(outputStream, scopeData))
                {
                    return;
                }
                innerContext.Index = index;
                innerContext.Last  = index + 1 == value.Count;
                innerContext.Value = item;
                await onItem(innerContext);

                index++;
            }
        }
        public static void PanelSettingsUpdatePost(ContextCollection collection, PanelPreferences preferences)
        {
            var panelSettingsViewUrl = new Uri(preferences.PanelAdminUrl + "PanelSettingsManagementView.aspx");
            string panelSettingsViewFormParams = GetPanelSettingsViewFormParams(collection.GetFormString());
            var bytes = Encoding.ASCII.GetBytes(panelSettingsViewFormParams);

            var panelSettingsRequest = AutomationHelper.CreatePost(panelSettingsViewUrl, preferences.CookieJar);
            panelSettingsRequest.Referer = preferences.PanelAdminUrl + "PanelSettingsManagementView.aspx";
            panelSettingsRequest.ContentLength = bytes.Length;

            using (Stream os = panelSettingsRequest.GetRequestStream())
            {
                os.Write(bytes, 0, bytes.Length);
            }

            var response = (HttpWebResponse)panelSettingsRequest.GetResponse();
            string cookies = response.Headers["Set-Cookie"];
            preferences.CookieJar.VcAuthentication = AutomationHelper.GetVcAuthentication(cookies);
            preferences.CookieJar.UniqueRequestId = AutomationHelper.GetReqId(cookies);

            response.Close();
        }
Пример #43
0
        protected when_running_specs Init(Type[] types, string tags = null, bool failFast = false)
        {
            this.types = types;

            builder = new ContextBuilder(new SpecFinder(types), new Tags().Parse(tags), new DefaultConventions());

            runner = new ContextRunner(builder, formatter, failFast);

            contextCollection = builder.Contexts();

            contextCollection.Build();

            classContext = contextCollection
                .AllContexts()
                .Where(c => c is ClassContext)
                .Cast<ClassContext>()
                .FirstOrDefault(c => types.Contains(c.type));

            methodContext = contextCollection.AllContexts().FirstOrDefault(c => c is MethodContext);

            return this;
        }
        public RunnableContextFinder_desc_base()
        {
            var context1 = new Context("context 1");

            context1.AddExample(new Example("example 1A"));
            context1.AddExample(new Example("example 1B"));

            var context2 = new Context("context 2");

            context2.AddExample(new Example("example 2A"));

            var context3 = new Context("context 3");

            context3.AddExample(new Example("example 3A"));
            context3.AddExample(new Example("example 3B"));
            context3.AddExample(new Example("example 3C"));

            var context4 = new Context("context 4");

            context4.AddExample(new Example("example 4A"));

            someContexts = new Context[]
            {
                context1,
                context2,
                context3,
                context4,
            };

            someContextCollection = new ContextCollection(someContexts);

            var dummyInstance = new nspec();

            foreach (var ctx in someContextCollection)
            {
                ctx.Build(dummyInstance);
            }
        }
Пример #45
0
        /// <param name="compiler"></param>
        /// <inheritdoc />
        public CompilationAsync Compile(IDocumentCompiler compiler)
        {
            var children   = compiler.Compile(Children);
            var expression = MorestachioExpression.Compile();

            return(async(outputStream, context, scopeData) =>
            {
                var index = 0;

                var collectionContext = new ContextCollection(index, false, context.Key,
                                                              context.Parent,
                                                              context.Value);

                while (ContinueBuilding(outputStream, scopeData) &&
                       (await expression(collectionContext, scopeData)).Exists())
                {
                    await children(outputStream, collectionContext, scopeData);

                    collectionContext = new ContextCollection(++index, false, context.Key,
                                                              context.Parent, context.Value);
                }
            });
        }
Пример #46
0
        public void Run()
        {
            var contexts = new ContextCollection();

            try
            {
                contexts = builder.Contexts();

                contexts.Build();

                contexts.Run();

                // remove any contexts that ended with no executed examples (which is likely due to presence of tag filters)
                if( builder.tagsFilter != null && builder.tagsFilter.HasTagFilters() )
                    contexts.TrimSkippedContexts();

                formatter.Write(contexts);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #47
0
 public void Write(ContextCollection contexts)
 {
     this.Contexts = contexts;
 }
Пример #48
0
 public void Write( ContextCollection contexts )
 {
     this.Contexts = contexts;
 }
Пример #49
0
        public LinkInfo SetUpContext(PanelPreferences preferences, string skinFolderPath)
        {
            // Offline and Advanced mode Changes by Optimus

            var linkInfo = new LinkInfo { FolderName = Res.FolderName };
            if (!preferences.OfflineMode)
            {
                Login(preferences);

                try
                {
                    OpenPanelSettings(preferences);

                    var collection = new ContextCollection(CookieJar.SourceCode);

                    ContextInfo contextInfo = collection.FindAvailableContext();
                    Environment = contextInfo.Environment;

                    collection.UpdateFormValue(contextInfo.ContextIndex, -1, "OpenPortalSkinFolder", contextInfo.FolderName());
                    collection.UpdateFormValue(contextInfo.ContextIndex, -1, "PortalSkinPath", Res.PortalSkinPathParent + "/" + contextInfo.FolderName() + "/");
                    collection.UpdateFormValue(contextInfo.ContextIndex, -1, "IsHidden", "False");
                    collection.UpdateFormValue(contextInfo.ContextIndex, -1, "Name", preferences.CompanyName + " Portal");

                    // Added for Language selection by Optimus
                    collection.UpdateFormValue(contextInfo.ContextIndex, -1, "Culture", preferences.Language);

                    PanelSettingsManagement.PanelSettingsUpdatePost(collection, preferences);
                    linkInfo.FolderName = contextInfo.FolderName();
                    linkInfo.PortalLink = contextInfo.OpenPortalTestBaseUrl; //TODO CHANGE TO LIVE LINK
                }
                catch (Exception e)
                {
                    // attempt to Navigate away to attempt not to lock panel settings
                    try
                    {
                        PanelSettingsManagement.PanelSettingsPostToHome(preferences);
                    }
                    catch (Exception) { }
                    throw e;
                }
            }
            return linkInfo;
        }
Пример #50
0
        public void Write(ContextCollection contexts)
        {
            Console.WriteLine(FailureSummary(contexts));

            Console.WriteLine(Summary(contexts));
        }
Пример #51
0
 public void Write(ContextCollection contexts) { }
 public ContextValueFunction(ContextCollection <string> context)
 {
     this.instanceContext = context;
 }
Пример #53
0
 public static ExampleBase FindExample(this ContextCollection contextCollection, string name)
 {
     return(contextCollection.Examples().SingleOrDefault(e => e.Spec == name));
 }
Пример #54
0
 public static Context Find(this ContextCollection contextCollection, string name)
 {
     return(contextCollection.AllContexts().SingleOrDefault(c => c.Name == name));
 }
Пример #55
0
 public void Write(ContextCollection contexts)
 {
     WriteLineDelegate(FailureSummary(contexts));
     WriteLineDelegate(Summary(contexts));
 }
Пример #56
0
 public string FocusNotification(ContextCollection contexts)
 {
     return("");
 }
Пример #57
0
 public TestHub(ContextCollection <string> users)
 {
     _users = users;
 }
Пример #58
0
        /// <exception cref="IndexedParseException"></exception>
        /// <inheritdoc />
        public override async ItemExecutionPromise Render(IByteCounterStream outputStream, ContextObject context, ScopeData scopeData)
        {
            var c = await MorestachioExpression.GetValue(context, scopeData);

            if (!c.Exists())
            {
                return(new DocumentItemExecution[0]);
            }

            if (!(c.Value is IEnumerable value) || value is string || value is IDictionary <string, object> )
            {
                var path   = new Stack <string>();
                var parent = context.Parent;
                while (parent != null)
                {
                    path.Push(parent.Key);
                    parent = parent.Parent;
                }

                throw new IndexedParseException(CharacterLocationExtended.Empty,
                                                string.Format("{1}'{0}' is used like an array by the template, but is a scalar value or object in your model." + " Complete Expression until Error:{2}",
                                                              MorestachioExpression.ToString(), base.ExpressionStart, (path.Count == 0 ? "Empty" : path.Aggregate((e, f) => e + "\r\n" + f))));
            }

            var scopes = new List <DocumentItemExecution>();

            //var items = value.OfType<object>().ToArray();
            //var result = new WrapperCounterStream[items.Length];

            //Parallel.ForEach(items, async (item, state, index) =>
            //{
            //	var innerContext =
            //		new ContextCollection(index, items.Length == index, context.Options, $"[{index}]", c, item)
            //			.MakeNatural();
            //	var stream = new WrapperCounterStream(outputStream, context.Options);
            //	await MorestachioDocument.ProcessItemsAndChildren(Children, stream, innerContext, scopeData);
            //	result[index] = stream;
            //});

            //foreach (var byteCounterStream in result)
            //{
            //	byteCounterStream.Write(byteCounterStream.Read());
            //}

            //return Enumerable.Empty<DocumentItemExecution>();
            //Use this "lookahead" enumeration to allow the $last keyword
            var index      = 0;
            var enumerator = value.GetEnumerator();

            if (!enumerator.MoveNext())
            {
                return(Enumerable.Empty <DocumentItemExecution>());
            }

            var current = enumerator.Current;

            do
            {
                var next = enumerator.MoveNext() ? enumerator.Current : null;

                var innerContext =
                    new ContextCollection(index, next == null, context.Options, $"[{index}]", c, current)
                    .MakeNatural();
                scopes.AddRange(Children.WithScope(innerContext));
                index++;
                current = next;
            } while (current != null && ContinueBuilding(outputStream, context));

            return(scopes);
        }
 public void Write(ContextCollection contexts)
 {
 }
Пример #60
0
 public ExampleContext(Tags tagsFilter, ContextCollection testSuite, ExampleBase example)
 {
     TagsFilter = tagsFilter;
     TestSuite  = testSuite;
     Example    = example;
 }