Esempio n. 1
0
 /// <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>
 /// <returns>An new actor</returns>
 public static Actor WithReporting(
     this Actor actor,
     IObserver <string> observer,
     ICanNotify canNotify)
 {
     return(actor.WithReporting(observer, canNotify, new DefaultMeasureDuration()));
 }
Esempio n. 2
0
        public void WithSeleniumReporting_WithCanNotify_ShouldReturnCorrectValue(
            [Modest] Actor actor,
            IActor iactor,
            string screenshotDirectory,
            string screenshotName,
            IObserver <string>[] observers,
            ICanNotify canNotify)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var actual = ActorExtensions.WithSeleniumReporting(
                actor,
                screenshotDirectory,
                screenshotName,
                canNotify,
                out var actualSeleniumReporter,
                observers
                );
#pragma warning restore CS0618 // Type or member is obsolete
            TestWithSeleniumReporting(actualSeleniumReporter,
                                      actual,
                                      actor,
                                      iactor,
                                      screenshotDirectory,
                                      screenshotName,
                                      observers,
                                      new CompositeCanNotify(canNotify, SeleniumReportingConfiguration.DefaultCanNotify),
                                      _defaultTakeScreenshotStrategy);
        }
Esempio n. 3
0
        public void WithSeleniumReporting_WithConfiguration_ShouldReturnCorrectValue(
            [Modest] Actor actor,
            IActor iactor,
            SeleniumReportingConfiguration configuration,
            IObserver <string>[] observers,
            ICanNotify canNotify,
            ITakeScreenshotStrategy takeScreenshotStrategy,
            ScreenshotFormat format)
        {
            var actual = ActorExtensions.WithSeleniumReporting(
                actor,
                configuration,
                out var actualSeleniumReporter
                );

            TestWithSeleniumReporting(actualSeleniumReporter,
                                      actual,
                                      actor,
                                      iactor,
                                      configuration.ScreenshotDirectory,
                                      configuration.ScreenshotNameOrFormat,
                                      observers,
                                      canNotify,
                                      takeScreenshotStrategy,
                                      format);
        }
Esempio n. 4
0
        private static void TestWithSeleniumReporting(
            ISeleniumReporter actualSeleniumReporter,
            Actor actual,
            Actor actor,
            IActor iactor,
            string screenshotDirectory,
            string screenshotName,
            IObserver <string>[] observers,
            ICanNotify canNotify,
            ITakeScreenshotStrategy takeScreenshotStrategy)
        {
            // assert
            var xmlDocumentObserver    = new XmlDocumentObserver();
            var takeScreenshot         = actual.InnerActorBuilder(iactor).Should().BeOfType <TakeScreenshot>().Which;
            var expectedTakeScreenshot = ActorExtensions.TakeScreenshots(
                actor,
                screenshotName,
                new CompositeObserver <ScreenshotInfo>(
                    new ScreenshotInfoToActionAttachmentObserverAdapter(xmlDocumentObserver),
                    new RenderedScreenshotInfoObserver(new CompositeObserver <string>(observers)),
                    new SaveScreenshotsToFileOnComplete(screenshotDirectory)
                    ),
                takeScreenshotStrategy
                )
                                         .InnerActorBuilder(iactor) as TakeScreenshot;

            takeScreenshot.Should().BeEquivalentTo(expectedTakeScreenshot, o => o.Excluding(a => a.Actor)
                                                   .Excluding(a => a.NextScreenshotName)
                                                   .RespectingRuntimeTypes());
            var actualScreenshotNames   = Enumerable.Range(0, 10).Select(_ => takeScreenshot.NextScreenshotName());
            var expectedScreenshotNames = Enumerable.Range(0, 10).Select(_ => expectedTakeScreenshot.NextScreenshotName());

            actualScreenshotNames.Should().BeEquivalentTo(expectedScreenshotNames);

            var reportingActor         = takeScreenshot.Actor.Should().BeOfType <ReportingActor>().Which;
            var expectedReportingActor = actor.WithReporting(
                new CompositeObserver <ActionNotification>(
                    xmlDocumentObserver,
                    new RenderedReportingObserver(
                        new CompositeObserver <string>(observers),
                        RenderedReportingObserver.DefaultRenderer
                        )
                    ),
                canNotify
                )
                                         .InnerActorBuilder(iactor) as ReportingActor;

            reportingActor.Should().BeEquivalentTo(expectedReportingActor, o => o.Excluding(a => a.Actor)
                                                   .Excluding(a => a.MeasureTime.Now)
                                                   .Excluding((IMemberInfo m) => m.RuntimeType == typeof(DateTimeOffset))
                                                   .RespectingRuntimeTypes());

            var expectedSeleniumReporter = new SeleniumReporter(xmlDocumentObserver, new SaveScreenshotsToFileOnComplete(screenshotDirectory));

            actualSeleniumReporter.Should().BeEquivalentTo(expectedSeleniumReporter, o => o.Excluding((IMemberInfo m) => m.RuntimeType == typeof(DateTimeOffset)));
        }
Esempio n. 5
0
 /// <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));
 }
Esempio n. 6
0
 public void AsksFor_WhenCanNotifyReturnsFalse_ShouldNotNotify(
     [Frozen] TestObserver <ActionNotification> observer,
     [Frozen] ICanNotify canNotify,
     ReportingActor sut,
     IQuestion <object> question)
 {
     //arrange
     Mock.Get(canNotify).Setup(c => c.Question(question)).Returns(false);
     //act
     sut.AsksFor(question);
     //assert
     observer.Values.Should().BeEmpty();
 }
Esempio n. 7
0
        /// <summary>
        /// Use the give <see cref="ICanNotify"/> instance to determine if an action can trigger a notification
        /// </summary>
        /// <param name="canNotify">A <see cref="ICanNotify"/> instance that allows to control what actions and questions can send a notification</param>
        /// <returns></returns>
        public SeleniumReportingConfiguration WithCanNotify(ICanNotify canNotify)
        {
            if (canNotify == null)
            {
                throw new ArgumentNullException(nameof(canNotify));
            }

            return(new SeleniumReportingConfiguration(ScreenshotDirectory,
                                                      ScreenshotNameOrFormat,
                                                      canNotify,
                                                      TextOutputObservers,
                                                      TakeScreenshotStrategy));
        }
Esempio n. 8
0
        public static Actor WithSeleniumReporting(
            this Actor actor,
            string screenshotDirectory,
            string screenshotNameOrFormat,
            ICanNotify canNotify,
            out ISeleniumReporter seleniumReporter,
            params IObserver <string>[] textOutputObservers)
        {
            var configuration = new SeleniumReportingConfiguration(screenshotDirectory, screenshotNameOrFormat)
                                .AddTextObservers(textOutputObservers)
                                .WithCanNotify(canNotify);

            return(actor.WithSeleniumReporting(configuration, out seleniumReporter));
        }
Esempio n. 9
0
 /// <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;
 }
Esempio n. 10
0
        public void WithReporting_WithIObserverOfStringAndCanNotify_ShouldDecorateActor(
            [Modest] Actor actor,
            ReportingActor expected,
            IObserver <string> observer,
            ICanNotify canNotify)
        {
            //arrange
            //act
            var actual = ActorExtensions.WithReporting(actor, observer, canNotify).InnerActorBuilder(expected.Actor);
            //assert
            var actorAssertion = actual.Should().BeOfType <ReportingActor>();

            actorAssertion.Which.Observer.Should().BeOfType <RenderedReportingObserver>()
            .Which.Observer.Should().Be(observer);
            actorAssertion.Which.CanNotify.Should().Be(canNotify);
        }
Esempio n. 11
0
 private SeleniumReportingConfiguration(string screenshotDirectory,
                                        string screenshotNameOrFormat,
                                        ICanNotify canNotify,
                                        ImmutableArray <IObserver <string> > textOutputObservers,
                                        ITakeScreenshotStrategy takeScreenshotStrategy)
 {
     if (string.IsNullOrEmpty(screenshotDirectory))
     {
         throw new ArgumentNullException(nameof(screenshotDirectory));
     }
     if (string.IsNullOrEmpty(screenshotNameOrFormat))
     {
         throw new ArgumentNullException(nameof(screenshotNameOrFormat));
     }
     ScreenshotDirectory    = screenshotDirectory;
     ScreenshotNameOrFormat = screenshotNameOrFormat;
     _canNotify             = canNotify;
     TextOutputObservers    = textOutputObservers;
     TakeScreenshotStrategy = takeScreenshotStrategy;
 }
Esempio n. 12
0
 /// <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>
 /// <returns>An new actor</returns>
 public static Actor WithReporting(this Actor actor, IObserver <string> observer, ICanNotify canNotify)
 {
     Guard.ForNull(actor, nameof(actor));
     Guard.ForNull(observer, nameof(observer));
     Guard.ForNull(canNotify, nameof(canNotify));
     return(new Actor(
                actor.Name,
                actor.Abilities,
                a => new ReportingActor(
                    new RenderedReportingObserver(
                        observer,
                        RenderedReportingObserver.DefaultRenderer),
                    actor.InnerActorBuilder(a),
                    new DefaultMeasureDuration(),
                    canNotify
                    )
                ));
 }
Esempio n. 13
0
        /// <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="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 <ActionNotification> 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(observer, actor.InnerActorBuilder(a), measureDuration, canNotify)));
        }