public string WriteFailure(ExampleBase example) { var failure = "\n" + example.FullName().Replace("_", " ") + "\n"; failure += example.Exception.CleanMessage() + "\n"; var stackTrace = FailureLines(example.Exception); stackTrace.AddRange(FailureLines(example.Exception.InnerException)); var flattenedStackTrace = stackTrace.Flatten("\n").TrimEnd() + "\n"; failure += example.Context.GetInstance().StackTraceToPrint(flattenedStackTrace); return failure; }
public string WriteFailure(ExampleBase example) { var failure = "\n" + example.FullName().Replace("_", " ") + "\n"; failure += example.Exception.CleanMessage() + "\n"; var stackTrace = FailureLines(example.Exception); stackTrace.AddRange(FailureLines(example.Exception.InnerException)); var flattenedStackTrace = stackTrace.Flatten("\n").TrimEnd() + "\n"; failure += example.Context.GetInstance().StackTraceToPrint(flattenedStackTrace); return(failure); }
public ExecutedExample FromExample(ExampleBase example) { var executed = new ExecutedExample() { FullName = example.FullName(), Pending = example.Pending, Failed = example.Failed(), }; if (example.Exception != null) { executed.ExceptionMessage = example.Exception.Message; executed.ExceptionStackTrace = example.Exception.StackTrace; } return(executed); }
private ExampleBase.RunResult runExample(ExampleBase example, Execute mode, double sizeFactor) { example.ExecuteOn = mode; System.Threading.Thread.Sleep(100); try { return(example.Run(sizeFactor, sizeFactor, sizeFactor, print, rounds, warmup_rounds)); } catch (Exception exception) { logWriteLine(exception.ToString()); return(null); } }
public void CanMergeSubItems() { var repository = ExampleRepository.InstantiateForMemory(); // Create Basic Sample var o = new ExampleBase { Description = "Test Base" }; o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub A" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub B" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub C" }); var result = repository.Create(o); var existing = repository.Find(o.bvin); Assert.AreEqual(o.SubObjects.Count, existing.SubObjects.Count, "Sub object count should be equal"); Assert.AreEqual(o.SubObjects[0].Name, existing.SubObjects[0].Name, "First item name should be equal"); existing.SubObjects.Add(new ExampleSubObject { Name = "New Sub A" }); // index 3, then 2 existing.SubObjects.Add(new ExampleSubObject { Name = "New Sub B" }); // index 4, then 3 existing.SubObjects[0].Name = "Updated Sub A"; existing.SubObjects.RemoveAt(2); Assert.IsTrue(repository.Update(existing), "update should be true"); var target = repository.Find(o.bvin); Assert.IsNotNull(target, "target should not be null"); Assert.AreEqual(4, target.SubObjects.Count, "Sub object count should be four after merge"); Assert.AreEqual("Updated Sub A", target.SubObjects[0].Name, "First sub name didn't match"); Assert.AreEqual("Test Sub B", target.SubObjects[1].Name, "Second name didn't match"); Assert.AreEqual("New Sub A", target.SubObjects[2].Name, "Third name didn't match"); Assert.AreEqual("New Sub B", target.SubObjects[3].Name, "Fourth Name didn't match"); }
private static ExampleBase GetExample() { var examples = new ExampleBase[] { new SessionExample(), new OperationsCallSequenceExample(), new ConnectionsExample(), new ReliableSessionExceptionExample(), new FaultExceptionExample(), new ErrorHandlerExample(), new ConcurrencyModeExample(), new ConcurrencyModeNotWorkingExample(), new BasicHttpCallbackExample() }; return(QuestionManager.Choose(examples, e => e.Name, "List of samples:")); }
static ExecutedExample MapToExecuted(ExampleBase example) { var executedExample = new ExecutedExample() { FullName = example.FullName(), Pending = example.Pending, Failed = example.Failed(), Duration = example.Duration, }; if (example.Exception != null) { executedExample.ExceptionMessage = example.Exception.Message; executedExample.ExceptionStackTrace = example.Exception.StackTrace; } return(executedExample); }
public ExampleEventArgs(ExampleBase ex) { string name = string.Empty; Utilities.GenerateUniqueExampleName(ex.Context, ref name, ex.Spec); Example = new SerializableExampleBase { Spec = ex.Spec, Exception = ex.Exception != null ? new SerializableExampleFailureException { ExampleException = ex.Exception.GetBaseException() } : null, Context = new SerializableContext { Name = ex.Context.Name, Tags = ex.Context.Tags }, Tags = ex.Tags, UniqueName = name }; }
static MethodInfo GetFunctionBodyInfo(ExampleBase example) { string exampleTypeName = example.GetType().Name; BaseExampleBodyGetter getFunctionBodyInfo; bool hasGetterForType = typeNameToBodyGetterMap.TryGetValue(exampleTypeName, out getFunctionBodyInfo); if (hasGetterForType) { var info = getFunctionBodyInfo(example); return(info); } else { throw new ArgumentOutOfRangeException("example", String.Format("Unexpected example type: {0}", exampleTypeName)); } }
/// <summary> /// Executes the specified Bing Ads code example. /// </summary> /// <param name="example">The Bing Ads code example to execute.</param> public async void ExecuteExample(ExampleBase example) { try { OutputStatusMessage(string.Format("Running example: {0}\n", example.ExampleName)); OutputStatusMessage(string.Format("Description: {0}\n", example.Description)); await example.RunAsync(_authorizationData); OutputStatusMessage(string.Format("\nExample finished running: {0}\n", example.ExampleName)); } // The example's RunAsync method should catch exceptions specific to the corresponding Bing Ads services. // Catch application exceptions that were not caught within the specified example. catch (Exception ex) { OutputStatusMessage(ex.Message); } }
private async Task LaunchExample(Bitmap bmp, ExampleBase example) { try { TimeSpan initializationTime = TimeSpan.Zero; await Task.Run(() => { initializationTime = ExecTime.Run(() => example.ApplyExample(bmp)); }); view.SetResultImages(example.Images); view.SelectedResultImage = example.OriginalImage; view.SetSummary(example.GetType().Name, initializationTime.TotalMilliseconds); } catch (Exception exc) { view.ShowException(exc); } }
public DoublePair Get(ExampleBase exampleBase, double minSequentialExecutionTime) { foreach (DoublePair doublePair in AppropriateScales) { if (doublePair.Key == minSequentialExecutionTime) { return(doublePair); } } DoublePair result = new DoublePair(); result.Key = minSequentialExecutionTime; result.Value = findGoodSize(exampleBase, minSequentialExecutionTime); AppropriateScales.Add(result); return(result); }
public void Write(ExampleBase e, int level) { string name = string.Empty; Utilities.GenerateUniqueExampleName(e.Context, ref name, e.Spec); if (ExamplesToProcess.Count == 0 || ExamplesToProcess.Contains(GetSpecName(e))) { var noFailure = e.Exception == null; var failureMessage = noFailure ? "" : " - FAILED - {0}".With(e.Exception.CleanMessage()); var whiteSpace = indent.Times(level); var result = e.Pending ? whiteSpace + e.Spec + " - PENDING" : whiteSpace + e.Spec + failureMessage; WriteLineDelegate(result); if (ExampleProcessed != null) { ExampleProcessed(new ExampleEventArgs(e)); } } }
void BuildSpec(StringBuilder sb, ExampleBase example) { sb.AppendFormat("<li>{0}", example.Spec); if (example.Exception != null) { sb.AppendLine("<span class=\"spec-failed\">⇐ Failed</span>"); sb.Append("<div class=\"spec-exception\"><code>"); sb.Append(HttpUtility.HtmlEncode(example.Exception.ToString())); sb.AppendLine("</code></div>"); } else if (example.Pending) { sb.Append("<span class=\"spec-pending\">⇐ Pending</span>"); } else { sb.Append("<span class=\"spec-passed\">⇐ Passed</span>"); } sb.AppendLine("</li>"); }
public DiscoveredExample FromExample(ExampleBase example) { var methodInfo = GetFunctionBodyInfo(example); string specClassName = methodInfo.DeclaringType.FullName; string exampleMethodName = methodInfo.Name; var navigationData = debugInfoProvider.GetNavigationData(specClassName, exampleMethodName); var discoveredExample = new DiscoveredExample() { FullName = example.FullName(), SourceAssembly = binaryPath, SourceFilePath = navigationData.FileName, SourceLineNumber = navigationData.MinLineNumber, Tags = example.Tags.Select(tag => tag.Replace("_", " ")).ToArray(), }; return(discoveredExample); }
void BuildSpec(StringBuilder sb, ExampleBase example) { sb.AppendFormat("<li>{0}", example.Spec); if (example.Exception != null) { sb.AppendLine("<span class=\"spec-failed\">⇐ Failed</span>"); sb.Append("<div class=\"spec-exception\"><code>"); sb.Append(HtmlUtils.Encode(example.Exception.ToString())); sb.AppendLine("</code></div>"); } else if (example.Pending) { sb.Append("<span class=\"spec-pending\">⇐ Pending</span>"); } else { sb.Append("<span class=\"spec-passed\">⇐ Passed</span>"); } sb.AppendLine("</li>"); }
string BuildSpec(ExampleBase e, int level) { string output = ""; if (e.Exception != null) { output = String.Format("{0}<<markSpecAsFailed '{1}'>> <<showException 'error_{2}' '{3}''>>", "*".Times(level), e.Spec, Guid.NewGuid(), HtmlUtils.Encode(e.Exception.ToString())); } else if (e.Pending) { output = String.Format("{0}<<markSpecAsPending '{1}'>>", "*".Times(level), e.Spec); } else { output = String.Format("{0}{1}", "*".Times(level), e.Spec); } return(output + Environment.NewLine); }
public void Write(ExampleBase e, int level) { var noFailure = e.Exception == null; var failureMessage = noFailure ? "" : " - FAILED - {0}".With(e.Exception.CleanMessage()); var whiteSpace = indent.Times(level); var result = e.Pending ? whiteSpace + e.Spec + " - PENDING" : whiteSpace + e.Spec + failureMessage; Console.ForegroundColor = ConsoleColor.Green; if (!noFailure) Console.ForegroundColor = ConsoleColor.Red; if (e.Pending) Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(result); Console.ForegroundColor = ConsoleColor.White; }
public static void DoTest() { One2ManyExample example = new One2ManyExample(); ITransaction tx = ExampleBase.SetupDb(); example.Patch(tx); One2ManyParentEntity entity = example.CreateEntity(); example.Persist(tx, entity); entity = example.Retrieve(tx); Console.WriteLine("Entity Name = " + entity.Name); foreach (One2ManyChildEntity childEntity in entity.ChildEntities) { Console.WriteLine("Entity Child Name = " + childEntity.Name); } entity.Name = "Updated Entity A"; foreach (One2ManyChildEntity childEntity in entity.ChildEntities) { childEntity.Name += " Updated"; } example.Persist(tx, entity); entity = example.Retrieve(tx); Console.WriteLine("Entity Name = " + entity.Name); foreach (One2ManyChildEntity childEntity in entity.ChildEntities) { Console.WriteLine("Entity Child Name = " + childEntity.Name); } entity.Status = EntityStatus.Deleted; example.Persist(tx, entity); entity = example.Retrieve(tx); Console.WriteLine("Entity = " + entity); ExampleBase.CloseDb(); }
void BuildSpec(XmlTextWriter xml, ExampleBase example) { xml.WriteStartElement("testcase"); string testName = example.Spec; StringBuilder className = new StringBuilder(); ComposePartialName(example.Context, className); xml.WriteAttributeString("classname", className.ToString()); xml.WriteAttributeString("name", testName); if (example.Exception != null) { xml.WriteStartElement("failure"); xml.WriteAttributeString("type", example.Exception.GetType().Name); xml.WriteAttributeString("message", example.Exception.Message); xml.WriteString(example.Exception.ToString()); xml.WriteEndElement(); } xml.WriteEndElement(); }
private async void ExampleRun() { if (view.SelectedExample == null || view.SelectedSourceImage == null) { return; } if (view.SelectedExample == currentExample && view.SelectedSourceImage == currentImage) { return; } view.SelectedResultImage = null; currentExample?.CleanUp(); currentExample = view.SelectedExample; currentImage = view.SelectedSourceImage; view.Busy = true; await LaunchExample(currentImage, currentExample); view.Busy = false; }
private static void Main(string[] args) { var examples = new ExampleBase[] { new IfElseExample(), new StringFormatExample(), new CurrentExample(), new XPathIteratorMergeExample(), }; while (true) { var choosenExample = QuestionManager.Choose( examples, example => example.Name, "Please choose an example"); Console.WriteLine(); choosenExample.Execute(); Console.ReadKey(); Console.WriteLine(); } }
void BuildSpec(XmlTextWriter xml, ExampleBase example) { xml.WriteStartElement("Spec"); xml.WriteAttributeString("Name", example.Spec); if (example.Exception != null) { xml.WriteAttributeString("Status", "Failed"); xml.WriteStartElement("Exception"); xml.WriteCData(example.Exception.ToString()); xml.WriteEndElement(); } else if (example.Pending) { xml.WriteAttributeString("Status", "Pending"); } else { xml.WriteAttributeString("Status", "Passed"); } xml.WriteEndElement(); }
private void runExampleGpuAndAutomaticOnly(ExampleBase example, double sizeFactor) { ExampleBase.RunResult runResultSerial = new ExampleBase.RunResult(); { runResultSerial.Valid = true; runResultSerial.ElapsedTotalSeconds = 1; runResultSerial.SizeX = sizeFactor; runResultSerial.SizeY = sizeFactor; runResultSerial.SizeZ = sizeFactor; runResultSerial.Name = example.Name; }; //executeSerial(example, sizeFactor); ExampleBase.RunResult runResultParallel = executeParallel(example, sizeFactor); ExampleBase.RunResult runResultGPU = executeGpu(example, sizeFactor); ExampleBase.RunResult runResultAutomatic = new ExampleBase.RunResult(); { runResultAutomatic.Valid = false; runResultAutomatic.ElapsedTotalSeconds = -1; }; //executeAutomatic(example, sizeFactor); logWriteLine(); writeOutputs(example, runResultSerial, runResultParallel, runResultGPU, runResultAutomatic); }
public void CanFindObjectInRepositoryAfterCreate() { var repository = ExampleRepository.InstantiateForMemory(); var o = new ExampleBase { LastUpdatedUtc = new DateTime(2001, 1, 1), Description = "This is an example base", IsActive = true }; repository.Create(o); var targetId = o.bvin; var found = repository.Find(targetId); Assert.IsNotNull(found, "Found item should not be null"); Assert.AreEqual(o.bvin, found.bvin, "Bvin should match"); Assert.AreEqual(o.Description, found.Description, "Bvin should match"); Assert.AreEqual(o.IsActive, found.IsActive, "IsActive should match"); Assert.AreEqual(o.LastUpdatedUtc.Ticks, found.LastUpdatedUtc.Ticks, "Last Updated should match"); Assert.AreEqual(o.SubObjects.Count, found.SubObjects.Count, "Sub object count should match"); }
public void CanDeleteSubsOnDelete() { var repository = ExampleRepository.InstantiateForMemory(); // Create Basic Sample var o = new ExampleBase { Description = "Test Base" }; o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub A" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub B" }); o.SubObjects.Add(new ExampleSubObject { Name = "Test Sub C" }); var result = repository.Create(o); var existing = repository.Find(o.bvin); Assert.AreEqual(o.SubObjects.Count, existing.SubObjects.Count, "Sub object count should be equal"); Assert.AreEqual(o.SubObjects[0].Name, existing.SubObjects[0].Name, "First item name should be equal"); Assert.IsTrue(repository.Delete(o.bvin)); var target = repository.Find(o.bvin); Assert.IsNull(target, "target should not null after delete"); var subs = repository.PeakIntoSubObjects(o.bvin); Assert.IsNotNull(subs, "Sub list should NOT be null but should be empty."); Assert.AreEqual(0, subs.Count, "Sub list should be empty."); }
string BuildSpec(ExampleBase e, int level) { string output = ""; if (e.Exception != null) { output = String.Format("{0}<<markSpecAsFailed '{1}'>> <<showException 'error_{2}' '{3}''>>", "*".Times(level), e.Spec, Guid.NewGuid(), HttpUtility.HtmlEncode(e.Exception.ToString())); } else if (e.Pending) { output = String.Format("{0}<<markSpecAsPending '{1}'>>", "*".Times(level), e.Spec); } else { output = String.Format("{0}{1}", "*".Times(level), e.Spec); } return output + Environment.NewLine; }
public static void should <T>(this T o, Expression <Predicate <T> > predicate) { Assert.IsTrue(predicate.Compile()(o), ExampleBase.Parse(predicate.Body)); }
public void Write(ExampleBase example, int level) { }
public static void should_have_failed(this ExampleBase example) { (example.HasRun && example.Exception == null).is_false(); }
public static void should_have_passed(this ExampleBase example) { (example.HasRun && example.Exception == null).is_true(); }
protected abstract void testExample(ExampleBase example);
public static void ShouldHavePassed(this ExampleBase example) { (example.HasRun && example.Exception == null).Should().BeTrue(); }
public static void ShouldHaveFailed(this ExampleBase example) { (example.HasRun && example.Exception == null).Should().BeFalse(); }