/// <summary> /// Initializes a new instance of the <see cref="ResultCentricAggregateQueryTestRunner"/> class. /// </summary> /// <param name="comparer">The comparer to use when comparing events.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception> public ResultCentricAggregateQueryTestRunner(IResultComparer comparer) { if (comparer == null) { throw new ArgumentNullException(nameof(comparer)); } _comparer = comparer; }
/// <summary> /// Asserts that the specification is met. /// </summary> /// <param name="builder">The specification builder.</param> /// <param name="comparer">The result comparer.</param> public static void Assert(this IResultCentricAggregateQueryTestSpecificationBuilder builder, IResultComparer comparer) { if (builder == null) throw new ArgumentNullException("builder"); if (comparer == null) throw new ArgumentNullException("comparer"); var specification = builder.Build(); var runner = new ResultCentricAggregateQueryTestRunner(comparer); var result = runner.Run(specification); if (result.Failed) { if (result.ButException.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0}", result.ButException.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } if (result.ButResult.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0}", result.ButResult.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } if (result.ButEvents.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0} event(s) ({1})", result.ButEvents.Value.Length, String.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray())); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.AssertException(writer.ToString()); #endif } } } }
public void Process(IEnumerable <AgentThreadResult> results) { foreach (var result in results) { Grade grade = null; if (result.Request.ExpectedResult != null) { string contentType; if (!result.Request.Metadata.Result.Payload.Headers.TryGetValue("Content-Type", out contentType)) { contentType = "text/plain"; } var header = MediaTypeHeaderValue.Parse(contentType); IResultComparer comparer = ComparerFactory.GetByContentType(header.MediaType); grade = comparer.Compare(result.Request.ExpectedResult, result.Request.Metadata.Result); } result.Request.Metadata.Grade = grade; if (grade == null) { Undefined++; } else if (grade.Passed) { Passed++; } else { Failed++; } } // only add root level request with no parents var rootRequests = results.Where(r => string.IsNullOrWhiteSpace(r.Request.Metadata.ParentId)).Select(r => r.Request); Requests = rootRequests; }
/// <summary> /// Asserts that the specification is met. /// </summary> /// <param name="builder">The specification builder.</param> /// <param name="comparer">The result comparer.</param> public static void Assert(this IResultCentricAggregateQueryTestSpecificationBuilder builder, IResultComparer comparer) { if (builder == null) { throw new ArgumentNullException("builder"); } if (comparer == null) { throw new ArgumentNullException("comparer"); } var specification = builder.Build(); var runner = new ResultCentricAggregateQueryTestRunner(comparer); var result = runner.Run(specification); if (result.Failed) { if (result.ButException.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0}", result.ButException.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.XunitException(writer.ToString()); #endif } } if (result.ButResult.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0}", result.ButResult.Value); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.XunitException(writer.ToString()); #endif } } if (result.ButEvents.HasValue) { using (var writer = new StringWriter()) { writer.WriteLine(" Expected: {0},", result.Specification.Then); writer.WriteLine(" But was: {0} event(s) ({1})", result.ButEvents.Value.Length, String.Join(",", result.ButEvents.Value.Select(_ => _.GetType().Name).ToArray())); #if NUNIT throw new NUnit.Framework.AssertionException(writer.ToString()); #elif XUNIT throw new Xunit.Sdk.XunitException(writer.ToString()); #endif } } } }
public void SetUp() { _comparer = new EqualsResultComparer(); _sut = new ResultCentricAggregateQueryTestRunner(_comparer); }
public void SetUp() { _comparer = new EqualsResultComparer(); _sut = new ResultCentricAggregateQueryTestRunner(_comparer); }
/// <summary> /// Initializes a new instance of the <see cref="ResultCentricAggregateQueryTestRunner"/> class. /// </summary> /// <param name="comparer">The comparer to use when comparing events.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception> public ResultCentricAggregateQueryTestRunner(IResultComparer comparer) => _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
/// <summary> /// Initializes a new instance of the <see cref="ResultCentricAggregateQueryTestRunner"/> class. /// </summary> /// <param name="comparer">The comparer to use when comparing events.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <c>null</c>.</exception> public ResultCentricAggregateQueryTestRunner(IResultComparer comparer) { if (comparer == null) throw new ArgumentNullException("comparer"); _comparer = comparer; }