Exemple #1
0
        public async void Count_QueryValues(string dictionary, AudienceType audience, string language)
        {
            Mock <ITermsQueryService> querySvc   = new Mock <ITermsQueryService>();
            TermsController           controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object);

            // Set up the mock query service to handle the GetCount() call.
            // The return value is unimportant for this test.
            querySvc.Setup(
                mock => mock.GetCount(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>()
                    )
                )
            .Returns(Task.FromResult(default(long)));

            long result = await controller.GetCount(dictionary, audience, language);

            // Verify that the service layer is called:
            //  a) with the expected values.
            //  b) exactly once.
            querySvc.Verify(
                svc => svc.GetCount(dictionary, audience, language),
                Times.Once
                );
        }
Exemple #2
0
        [InlineData(new object[] { "" })]  // Empty string.
        public async void Count_ErrorMessage_Dictionary(string dictionary)
        {
            Mock <ITermsQueryService> querySvc   = new Mock <ITermsQueryService>();
            TermsController           controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object);

            APIErrorException ex = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetCount(dictionary, AudienceType.HealthProfessional, "en")
                );

            Assert.Equal(400, ex.HttpStatusCode);
        }
Exemple #3
0
        [InlineData(new object[] { "" })]  // Empty string.
        public async void Count_ErrorMessage_Language(string badLanguage)
        {
            Mock <ITermsQueryService> querySvc   = new Mock <ITermsQueryService>();
            TermsController           controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object);

            APIErrorException ex = await Assert.ThrowsAsync <APIErrorException>(
                () => controller.GetCount("Cancer.gov", AudienceType.Patient, badLanguage)
                );

            Assert.Equal(400, ex.HttpStatusCode);
        }
Exemple #4
0
        [InlineData(new object[] { int.MaxValue })] // Utterly ridiculous.
        public async void Count_QueryReturn(long returnCount)
        {
            Mock <ITermsQueryService> querySvc   = new Mock <ITermsQueryService>();
            TermsController           controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object);

            // Set up the mock query service to handle the GetCount() call.
            // The return value is unimportant for this test.
            querySvc.Setup(
                mock => mock.GetCount(
                    It.IsAny <string>(),
                    It.IsAny <AudienceType>(),
                    It.IsAny <string>()
                    )
                )
            .Returns(Task.FromResult(returnCount));

            // The arguments don't matter for this test.
            long actual = await controller.GetCount("Cancer.gov", AudienceType.HealthProfessional, "es");

            Assert.Equal(returnCount, actual);
        }