infinitesimal
infinitesimal

Reputation: 442

Fluent assertions, how to compare TimeSpan

I have a test in Rx.net and Fluent Assertions:

// Arrange
var testScheduler = new TestScheduler();
var udpStream = new Subject<UdpReceiveResult>();

_functionMock.Setup(x => x.CreateListener<UdpReceiveResult>()!.GetStream()).Returns(udpStream);

var observer = testScheduler.CreateObserver<TimeSpan>();
var sut = new MySutClass(_functionMock.Object);

// Act
var subscription = sut.MyMethod(testScheduler).Subscribe(observer);

testScheduler.AdvanceTo(TimeSpan.FromSeconds(5).Ticks);
udpStream.OnNext(new UdpReceiveResult());
testScheduler.AdvanceTo(TimeSpan.FromSeconds(9).Ticks);
udpStream.OnNext(new UdpReceiveResult());

// Assert
observer.Messages.Count.Should().Be(1);
observer.Messages[0].Value.Should().BeEquivalentTo(TimeSpan.FromSeconds(4));

In my opinion everything works fine but there is a message from console:

Expected observer.Messages[0].Value to be 4s, but found OnNext (00:00:04)

The time value is the same as I expected 4s but I think the comparison format is not valid and these two values can't compare properly.

Upvotes: 0

Views: 56

Answers (1)

infinitesimal
infinitesimal

Reputation: 442

It should be like this:

observer.Messages[0].Value.Value.Should().Be(TimeSpan.FromSeconds(4)); not observer.Messages[0].Value.Should().Be(TimeSpan.FromSeconds(4));

Upvotes: 0

Related Questions