public void Should_fail_when_asserting_nullable_TimeSpan_value_with_a_value_to_be_null()
        {
            TimeSpan? nullableTimeSpan = new TimeSpan();
            Action act = () => nullableTimeSpan.Should().NotHaveValue();
            act.ShouldThrow<AssertFailedException>();

        }
 public void Should_support_chaining_constraints_with_and()
 {
     TimeSpan? nullableTimeSpan = new TimeSpan();
     nullableTimeSpan.Should()
         .HaveValue()
         .And
         .Be(new TimeSpan());
 }
        public void Should_succeed_when_asserting_nullable_TimeSpan_value_with_a_value_to_have_a_value()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            TimeSpan? nullableTimeSpan = new TimeSpan();

            //-------------------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-------------------------------------------------------------------------------------------------------------------
            nullableTimeSpan.Should().HaveValue();
        }
Example #4
0
        public void should_be_able_to_deseralize_timespan_objects_from_floatseconds()
        {
            var timespan = new TimeSpan(days: 1, hours: 2, minutes: 3, seconds: 4, milliseconds: 5);
            var input = new Datum()
                {
                    type = Datum.DatumType.R_NUM,
                    r_num = timespan.TotalSeconds
                };

            var output = DatumConvert.DeserializeObject<TimeSpan>(input, new TimeSpanConverter());
            timespan.Should().Be(output);
        }
        public void When_time_is_within_specified_number_of_milliseconds_from_another_value_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var time = new TimeSpan(1, 12, 15, 31, 035);
            var nearbyTime = new TimeSpan(1, 12, 15, 31, 000);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => time.Should().BeCloseTo(nearbyTime, 35);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
        public void When_time_is_greater_then_and_not_close_to_another_value_it_should_throw_with_descriptive_message()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var time = new TimeSpan(1, 12, 15, 31, 021);
            var nearbyTime = new TimeSpan(1, 12, 15, 31, 000);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => time.Should().BeCloseTo(nearbyTime, 20, "we want to test the error message");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldThrow<AssertFailedException>()
                .WithMessage(
                    "Expected time to be within 20 ms from 1d, 12h, 15m and 31s because we want to test the error message, but found 1d, 12h, 15m and 31.021s.");
        }
        public void When_time_is_greater_then_but_close_to_another_value_it_should_succeed()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            var time = new TimeSpan(1, 12, 15, 31, 020);
            var nearbyTime = new TimeSpan(1, 12, 15, 31, 000);

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action act = () => time.Should().BeCloseTo(nearbyTime);

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            act.ShouldNotThrow();
        }
 public void Should_succeed_when_asserting_nullable_TimeSpan_value_with_a_value_to_have_a_value()
 {
     TimeSpan? nullableTimeSpan = new TimeSpan();
     nullableTimeSpan.Should().HaveValue();
 }
Example #9
0
        public async Task Pipeline_can_be_used_to_time_an_operation()
        {
            var time = new TimeSpan();
            var aggregator = Aggregator
                .Create<BalanceProjection, IDomainEvent>((projection, events) =>
                {
                    return Task.Run(() => Thread.Sleep(1000));
                })
                .Pipeline(async (projection, batch, next) =>
                {
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    await next(projection, batch);
                    time = stopwatch.Elapsed;
                });

            await aggregator.Aggregate(null, null);

            time.Should().BeGreaterOrEqualTo(TimeSpan.FromSeconds(1));
        }
        public void Should_support_chaining_constraints_with_and()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            TimeSpan? nullableTimeSpan = new TimeSpan();

            //-------------------------------------------------------------------------------------------------------------------
            // Act / Assert
            //-------------------------------------------------------------------------------------------------------------------
            nullableTimeSpan.Should()
                .HaveValue()
                .And
                .Be(new TimeSpan());
        }
        public void When_asserting_a_nullable_TimeSpan_is_equal_to_the_same_nullable_TimeSpan_it_should_succed()
        {
            //-------------------------------------------------------------------------------------------------------------------
            // Arrange
            //-------------------------------------------------------------------------------------------------------------------
            TimeSpan? nullableTimeSpanA = new TimeSpan();
            TimeSpan? nullableTimeSpanB = new TimeSpan();

            //-------------------------------------------------------------------------------------------------------------------
            // Act
            //-------------------------------------------------------------------------------------------------------------------
            Action action = () => nullableTimeSpanA.Should().Be(nullableTimeSpanB);

            //-------------------------------------------------------------------------------------------------------------------
            // Assert
            //-------------------------------------------------------------------------------------------------------------------
            action.ShouldNotThrow();
        }