public void Execute_WithThenActionWithError_ShouldCallOnNext( [Frozen(Matching.ImplementedInterfaces)] TestObserver <ActionNotification> observer, [Frozen] DateTimeOffset date, [Frozen] IMeasureDuration measureDuration, ReportingActor sut, ThenAction <object, string> thenAction, Exception error, TimeSpan expectedDuration ) { //arrange Mock.Get(measureDuration).Setup(m => m.Measure(It.IsAny <Func <string> >())) .Returns((expectedDuration, null, error)); //act try { sut.Execute(thenAction); } catch (Exception) { } //assert var expected = new[] { new ActionNotification(thenAction, 1, new BeforeThenNotificationContent(date, thenAction.Question)), new ActionNotification(thenAction, 1, new AfterThenNotificationContent(expectedDuration, ThenOutcome.Error, error)) }; observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers <ActionNotification>()); }
/// <summary> /// Create a new instance of <see cref="ReportingActor"/> /// </summary> /// <param name="observer">An <see cref="IObserver{T}"/> instance which is called when a notification occurs</param> /// <param name="actor">The given actor</param> /// <param name="measureTime">A <see cref="IMeasureDuration"/> instance used to measure the execution time of a function</param> /// <param name="canNotify">A <see cref="ICanNotify"/> instance that is used to filter actions that should not send a notification</param> public ReportingActor( IObserver <ActionNotification> observer, IActor actor, IMeasureDuration measureTime, ICanNotify canNotify) { Observer = observer ?? throw new ArgumentNullException(nameof(observer)); Actor = actor ?? throw new ArgumentNullException(nameof(actor)); MeasureTime = measureTime ?? throw new ArgumentNullException(nameof(measureTime)); CanNotify = canNotify ?? throw new ArgumentNullException(nameof(canNotify)); }
/// <summary> /// Create a new instance of <see cref="ReportingActor"/> /// </summary> /// <param name="observer">An <see cref="IObserver{T}"/> instance which is called when a notification occurs</param> /// <param name="actor">The given actor</param> /// <param name="measureTime">A <see cref="IMeasureDuration"/> instance used to measure the execution time of a function</param> /// <param name="canNotify">A <see cref="ICanNotify"/> instance that is used to filter actions that should not send a notification</param> public ReportingActor( IObserver <ActionNotification> observer, IActor actor, IMeasureDuration measureTime, ICanNotify canNotify) { Guard.ForNull(observer, nameof(observer)); Guard.ForNull(actor, nameof(actor)); Guard.ForNull(measureTime, nameof(measureTime)); Guard.ForNull(canNotify, nameof(canNotify)); Observer = observer; Actor = actor; MeasureTime = measureTime; CanNotify = canNotify; }
public void Execute_WithThenActionWithAssertionError_ShouldCallOnNext( int i, [Frozen(Matching.ImplementedInterfaces)] TestObserver <ActionNotification> observer, [Frozen] DateTimeOffset date, [Frozen] IMeasureDuration measureDuration, ReportingActor sut, ThenAction <object, string> thenAction, TimeSpan expectedDuration ) { //arrange Exception expectedException = null; Mock.Get(measureDuration).Setup(m => m.Measure(It.IsAny <Func <string> >())) .Returns(() => { try { _assertions[i](); } catch (Exception ex) { expectedException = ex; return(expectedDuration, string.Empty, ex); } throw new InvalidOperationException("Should not happen as the assertions actions should throw an exception"); }); //act try { sut.Execute(thenAction); } catch (Exception) { } //assert var expected = new[] { new ActionNotification(thenAction, 1, new BeforeThenNotificationContent(date, thenAction.Question)), new ActionNotification(thenAction, 1, new AfterThenNotificationContent(expectedDuration, ThenOutcome.Failed, expectedException)) }; observer.Values.Should().BeEquivalentTo(expected, o => o.RespectingRuntimeTypes().ComparingByMembers <ActionNotification>()); }
/// <summary> /// Add the ability to report the actor actions /// </summary> /// <param name="actor">The actor</param> /// <param name="observer">The observer used to report the actions</param> /// <param name="measureDuration">A <see cref="IMeasureDuration"/> instance that provides duration and current date</param> /// <returns>An new actor</returns> public static Actor WithReporting( this Actor actor, IObserver <ActionNotification> observer, IMeasureDuration measureDuration) { if (actor == null) { throw new ArgumentNullException(nameof(actor)); } if (observer == null) { throw new ArgumentNullException(nameof(observer)); } if (measureDuration == null) { throw new ArgumentNullException(nameof(measureDuration)); } return(new Actor(actor.Name, actor.Abilities, a => new ReportingActor(observer, actor.InnerActorBuilder(a), measureDuration))); }
public void GetXmlDocument_ShouldReturnCorrectValue( [Frozen] IMeasureDuration measureDuration, [Greedy] XmlDocumentObserver expectedDocumentObserver, INamed named, IFixture fixture, DateTimeOffset date) { // arrange fixture.Customize <XmlDocumentObserver>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery()))); var sut = fixture.Create <SeleniumReporter>(); Mock.Get(measureDuration).Setup(m => m.Now).Returns(date); SetupObserver(expectedDocumentObserver, named); SetupObserver(sut.XmlDocumentObserver, named); var expected = expectedDocumentObserver.GetXmlDocument(); // act var actual = sut.GetXmlDocument(); // assert actual.ToString().Should().Be(expected.ToString()); }
/// <summary> /// Creates a new instance of <see cref="XmlDocumentObserver"/> /// </summary> public XmlDocumentObserver(IMeasureDuration measureDuration) { MeasureDuration = measureDuration ?? throw new ArgumentNullException(nameof(measureDuration)); }
/// <summary> /// Create a new instance of <see cref="ReportingActor"/> /// </summary> /// <param name="observer">An <see cref="IObserver{T}"/> instance which is called when a notification occurs</param> /// <param name="actor">The given actor</param> /// /// <param name="measureTime">A <see cref="IMeasureDuration"/> instance used to measure the execution time of a function</param> public ReportingActor(IObserver <ActionNotification> observer, IActor actor, IMeasureDuration measureTime) : this(observer, actor, measureTime, new CanAlwaysNotify()) { }
/// <summary> /// Add the ability to report the actor actions as text /// </summary> /// <param name="actor">The actor</param> /// <param name="observer">The observer used to report the actions</param> /// <param name="canNotify">A <see cref="ICanNotify"/> instance that is used to filter actions that should not send a notification</param> /// <param name="measureDuration">A <see cref="IMeasureDuration"/> instance that provides duration and current date</param> /// <returns>An new actor</returns> public static Actor WithReporting(this Actor actor, IObserver <string> observer, ICanNotify canNotify, IMeasureDuration measureDuration) { if (actor == null) { throw new ArgumentNullException(nameof(actor)); } if (observer == null) { throw new ArgumentNullException(nameof(observer)); } if (canNotify == null) { throw new ArgumentNullException(nameof(canNotify)); } if (measureDuration == null) { throw new ArgumentNullException(nameof(measureDuration)); } return(new Actor( actor.Name, actor.Abilities, a => new ReportingActor( new RenderedReportingObserver( observer, RenderedReportingObserver.DefaultRenderer), actor.InnerActorBuilder(a), measureDuration, canNotify ) )); }
public MeasureDuration(IMeasureDuration innerMeasureDuration, DateTimeOffset now, TimeSpan duration) { this.innerMeasureDuration = innerMeasureDuration; this.now = now; this.duration = duration; }