public async void GetAll_Specified_Parameters() { // Create a mock query that always returns the same result. Mock <ITermsQueryService> querySvc = new Mock <ITermsQueryService>(); querySvc.Setup( svc => svc.GetAll( It.IsAny <string>(), It.IsAny <AudienceType>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <bool>() ) ) .Returns(Task.FromResult(new GlossaryTermResults())); // Call the controller, we don't care about the actual return value. TermsController controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object); await controller.GetAll("glossary", AudienceType.HealthProfessional, "es", 200, 2, true); // Verify that the query layer is called: // a) with the expected values. // b) exactly once. querySvc.Verify( svc => svc.GetAll("glossary", AudienceType.HealthProfessional, "es", 200, 2, true), Times.Once, "ITermsQueryService::getAll() should be called once, with the specified values for size, from, and requestedFields" ); }
public async void GetAll_Error_LanguageBad() { Mock <ITermsQueryService> querySvc = new Mock <ITermsQueryService>(); TermsController controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object); var exception = await Assert.ThrowsAsync <APIErrorException>( () => controller.GetAll("glossary", AudienceType.HealthProfessional, "turducken") ); Assert.Equal("Unsupported Language. Valid values are 'en' and 'es'.", exception.Message); }
public async void GetAll_Error_LanguageMissing() { Mock <ITermsQueryService> querySvc = new Mock <ITermsQueryService>(); TermsController controller = new TermsController(NullLogger <TermsController> .Instance, querySvc.Object); var exception = await Assert.ThrowsAsync <APIErrorException>( () => controller.GetAll("glossary", AudienceType.HealthProfessional, "") ); Assert.Equal("You must supply a valid dictionary, audience and language.", exception.Message); }