Ejemplo n.º 1
0
        public async Task NoMeetings()
        {
            // ARRANGE
            Mock <ILogger <MyHomeController> > loggerMock = CreateLoggerMock();

            IList <IMeeting> meetingList = new List <IMeeting>();
            ISetupStatus     setupStatus = new SetupStatus(
                haveOrganisations: false,
                haveCommittees: false);

            Mock <IAgendaService> agendaServiceMock = CreateAgendaServiceMock(meetingList, setupStatus);

            Mock <IFeatureManager> featureManagerMock = CreateFeatureManagerMock(
                newReferenceSearch: true);

            using MyHomeController controller = CreateHomeController(
                      loggerMock,
                      agendaServiceMock,
                      featureManagerMock);

            // ACT
            IActionResult actionResult = await controller.Index().ConfigureAwait(false);

            // ASSERT
            // Assert that this is a View Result
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)actionResult;

            // Assert that is has the correct view model.
            Assert.IsNotNull(viewResult.Model);
            Assert.IsInstanceOfType(viewResult.Model, typeof(IndexViewModel));

            // Verify service level methods called the correct number of times.
            agendaServiceMock.Verify(
                x =>
                x.GetRecentMeetingsMostRecentFirstAsync(
                    It.IsAny <IWho>(),
                    It.IsAny <TimeSpan?>(),
                    It.IsAny <int?>()),
                Times.Once());

            agendaServiceMock.Verify(
                x =>
                x.GetSetupStatusAsync(
                    It.IsAny <IWho>()),
                Times.Once);
        }
Ejemplo n.º 2
0
        public async Task HaveMeetings()
        {
            // ARRANGE
            Mock <ILogger <MyHomeController> > loggerMock = CreateLoggerMock();

            IOrganisation organisation = new Organisation(
                id: Guid.NewGuid(),
                code: "BRADGATE",
                name: "Bradgate Bridge Club",
                bgColour: "000000");

            IList <IMeeting> meetingList = new List <IMeeting>
            {
                new Meeting(
                    id: Guid.NewGuid(),
                    committee: new Committee(
                        id: Guid.NewGuid(),
                        organisation: organisation,
                        name: "Executive",
                        description: "Executive Committee"),
                    meetingDateTime: DateTime.Today.AddHours(19).AddMinutes(30))
            };

            Mock <IAgendaService> agendaServiceMock = CreateAgendaServiceMock(
                meetingList: meetingList,
                setupStatus: null);

            Mock <IFeatureManager> featureManagerMocker = CreateFeatureManagerMock(
                newReferenceSearch: true);

            using MyHomeController controller = CreateHomeController(
                      loggerMock,
                      agendaServiceMock,
                      featureManagerMocker);

            // ACT
            IActionResult actionResult = await controller.Index().ConfigureAwait(false);

            // ASSERT
            // Assert that this is a View Result
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            ViewResult viewResult = (ViewResult)actionResult;

            // Assert that is has the correct view model.
            Assert.IsNotNull(viewResult.Model);
            Assert.IsInstanceOfType(viewResult.Model, typeof(IndexViewModel));

            // Verify service level methods called the correct number of times.
            agendaServiceMock.Verify(
                x =>
                x.GetRecentMeetingsMostRecentFirstAsync(
                    It.IsAny <IWho>(),
                    It.IsAny <TimeSpan?>(),
                    It.IsAny <int?>()),
                Times.Once());

            agendaServiceMock.Verify(
                x =>
                x.GetSetupStatusAsync(
                    It.IsAny <IWho>()),
                Times.Never);
        }