Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR FIX: Ensure All Dependencies Are Verified For No Other Calls Across All Tests #1238

Open
hassanhabib opened this issue Feb 3, 2022 · 1 comment

Comments

@hassanhabib
Copy link
Owner

There are two issues in our tests:

Issue # 1:
The dependencies are verified twice like this:

        [Fact]
        public async Task ShouldRetrieveCalendarByIdAsync()
        {
            // given
            Guid randomCalendarId = Guid.NewGuid();
            Guid inputCalendarId = randomCalendarId;
            DateTimeOffset randomDateTime = GetRandomDateTime();
            Calendar randomCalendar = CreateRandomCalendar(randomDateTime);
            Calendar storageCalendar = randomCalendar;
            Calendar expectedCalendar = storageCalendar;

            this.storageBrokerMock.Setup(broker =>
                broker.SelectCalendarByIdAsync(inputCalendarId))
                    .ReturnsAsync(storageCalendar);

            // when
            Calendar actualCalendar =
                await this.calendarService.RetrieveCalendarByIdAsync(inputCalendarId);

            // then
            actualCalendar.Should().BeEquivalentTo(expectedCalendar);

            this.dateTimeBrokerMock.Verify(broker =>
                broker.GetCurrentDateTime(),
                    Times.Never);

            this.storageBrokerMock.Verify(broker =>
                broker.SelectCalendarByIdAsync(inputCalendarId),
                    Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }

The solution in this case is the last three lines should be as follows:

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBroker.VerifyNoOtherCalls();

Issue # 2:
The dependencies are not verified at all:

        [Fact]
        public void ShouldRetrieveAllCalendars()
        {
            // given
            IQueryable<Calendar> randomCalendars = CreateRandomCalendars();
            IQueryable<Calendar> storageCalendars = randomCalendars;
            IQueryable<Calendar> expectedCalendars = storageCalendars;

            this.storageBrokerMock.Setup(broker =>
                broker.SelectAllCalendars())
                    .Returns(storageCalendars);

            // when
            IQueryable<Calendar> actualCalendars =
                this.calendarService.RetrieveAllCalendars();

            // then
            actualCalendars.Should().BeEquivalentTo(expectedCalendars);

            this.storageBrokerMock.Verify(broker =>
                broker.SelectAllCalendars(),
                    Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }

The solution for this one would be as follows:

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBroker.VerifyNoOtherCalls();

This issue is assigned to @Bbereket1

@ShriHumrudha
Copy link
Collaborator

@Noahmahi2019 is assigned here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants