public async Task CourseSearchServiceFailureTestAsync()
        {
            //Arrange
            var serviceHelperFake           = A.Fake <IServiceHelper>();
            var manageCoursesFake           = A.Fake <ICourseOpportunityBuilder>(ops => ops.Strict());
            var courseSearchAuditRepository = A.Fake <IAuditRepository>(ops => ops.Strict());
            var loggerFake         = A.Fake <IApplicationLogger>();
            var fakePolicy         = A.Fake <ITolerancePolicy>();
            var fakeMessageBuilder = A.Fake <IBuildTribalMessage>();

            //Setup Calls ANY exception will do as we are catching all of them for this call
            A.CallTo(() => serviceHelperFake.UseAsync(A <Func <ServiceInterface, Task <CourseListOutput> > > ._, Constants.CourseSearchEndpointConfigName)).Throws(new HttpException("failed cause I want to"));

            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <CourseListInput> ._)).DoesNothing();
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <Exception> ._)).DoesNothing();
            A.CallTo(() => loggerFake.ErrorJustLogIt(A <string> ._, A <Exception> ._)).DoesNothing();

            var courseSearchService = new CourseSearchService(manageCoursesFake, serviceHelperFake, courseSearchAuditRepository, loggerFake, fakePolicy, fakeMessageBuilder);

            //Act
            var results = await courseSearchService.GetCoursesAsync("CourseKeyWords");

            //Assert
            results.Should().BeEmpty();
            A.CallTo(() => serviceHelperFake.UseAsync(A <Func <ServiceInterface, Task <CourseListOutput> > > ._, Constants.CourseSearchEndpointConfigName)).MustHaveHappened();
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <CourseListInput> ._)).MustHaveHappened();
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <Exception> ._)).MustHaveHappened();
            A.CallTo(() => loggerFake.ErrorJustLogIt(A <string> ._, A <Exception> ._)).MustHaveHappened();
        }
Exemple #2
0
        public async Task CourseSearchServiceTestAsync(string keywords, bool coursesAvailable)
        {
            //Arrange
            var serviceHelperFake           = A.Fake <IServiceHelper>();
            var manageCoursesFake           = A.Fake <ICourseOpportunityBuilder>(ops => ops.Strict());
            var courseSearchAuditRepository = A.Fake <IAuditRepository>(ops => ops.Strict());
            var loggerFake = A.Fake <IApplicationLogger>();
            var fakePolicy = A.Fake <ITolerancePolicy>();

            //Setup Calls and Dummies
            A.CallTo(() => serviceHelperFake.UseAsync(A <Func <ServiceInterface, Task <CourseListOutput> > > ._, Constants.CourseSearchEndpointConfigName)).Returns(coursesAvailable ? GetDummyCourseOutput() : new CourseListOutput());
            A.CallTo(() => manageCoursesFake.SelectCoursesForJobProfile(A <IEnumerable <Course> > ._))
            .Returns(GenerateDummyCourses());
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <CourseListInput> ._)).DoesNothing();
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <CourseListOutput> ._)).DoesNothing();

            var courseSearchService = new CourseSearchService(manageCoursesFake, serviceHelperFake, courseSearchAuditRepository, loggerFake, fakePolicy);

            //Act
            await courseSearchService.GetCoursesAsync(keywords);

            //Assert
            A.CallTo(() => serviceHelperFake.UseAsync(A <Func <ServiceInterface, Task <CourseListOutput> > > ._, Constants.CourseSearchEndpointConfigName)).MustHaveHappened();
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <CourseListInput> ._)).MustHaveHappened();
            A.CallTo(() => courseSearchAuditRepository.CreateAudit(A <CourseListOutput> ._)).MustHaveHappened();
            if (coursesAvailable)
            {
                A.CallTo(() => manageCoursesFake.SelectCoursesForJobProfile(A <IEnumerable <Course> > .That.Matches(m => m.Any()))).MustHaveHappened();
            }
            else
            {
                A.CallTo(() => manageCoursesFake.SelectCoursesForJobProfile(A <IEnumerable <Course> > .That.IsEmpty())).MustHaveHappened();
            }
        }