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>());
        }
Beispiel #2
0
        public void WithReporting_ShouldDecorateActor(
            [Modest] Actor actor,
            ReportingActor expected)
        {
            //arrange
            //act
            var actual = ActorExtensions.WithReporting(actor, expected.Observer, expected.MeasureTime).InnerActorBuilder(expected.Actor);

            //assert
            actual.Should().BeOfType <ReportingActor>().Which.Should().BeEquivalentTo(expected);
        }
        public void Name_ShouldReturnCorrectValue(
            ReportingActor sut,
            string expected)
        {
            //arrange
            Mock.Get(sut.Actor).Setup(a => a.Name).Returns(expected);
            //act
            var actual = sut.Name;

            //assert
            Assert.Equal(expected, actual);
        }
 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();
 }
        public void AsksFor_WithAbility_ShouldNotNotify(
            [Frozen] TestObserver <ActionNotification> observer,
            ReportingActor sut,
#pragma warning disable CS0618 // Type or member is obsolete
            IQuestion <Ability1, object> question)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            //arrange
            //act
            sut.AsksForWithAbility(question);
            //assert
            observer.Values.Should().BeEmpty();
        }
Beispiel #6
0
        public void WithReporting_WithIObserverOfString_ShouldDecorateActor(
            [Modest] Actor actor,
            ReportingActor expected,
            IObserver <string> observer)
        {
            //arrange
            //act
            var actual = ActorExtensions.WithReporting(actor, observer).InnerActorBuilder(expected.Actor);

            //assert
            actual.Should().BeOfType <ReportingActor>()
            .Which.Observer.Should().BeOfType <RenderedReportingObserver>()
            .Which.Observer.Should().Be(observer);
        }
        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>());
        }
 public void Sut_ShouldBeActor(
     ReportingActor sut)
 {
     sut.Should().BeAssignableTo <IActor>();
 }
 public void Sut_UsingModestConstructor_MeasureDurationShouldBeDefaultMeasureDuration(
     [Modest] ReportingActor sut)
 {
     sut.MeasureTime.Should().BeOfType <DefaultMeasureDuration>();
 }