public async Task And_All_Fields_Valid_Then_Valid( GetCohortQuery query, GetCohortQueryValidator validator) { var result = await validator.ValidateAsync(query); result.IsValid().Should().BeTrue(); result.ValidationDictionary.Count.Should().Be(0); }
public async Task Then_The_Api_Is_Called_With_The_Request_And_The_Cohort_Is_Returned( GetCohortQuery query, GetCohortResponse apiResponse, [Frozen] Mock <ICommitmentsV2ApiClient <CommitmentsV2ApiConfiguration> > apiClient, GetCohortQueryHandler handler ) { apiClient.Setup(x => x.Get <GetCohortResponse>(It.Is <GetCohortRequest>(x => x.CohortId == query.CohortId))).ReturnsAsync(apiResponse); var actual = await handler.Handle(query, CancellationToken.None); actual.Should().BeEquivalentTo((GetCohortResult)apiResponse); }
public async Task And_No_Id_Then_Invalid( GetCohortQueryValidator validator) { var query = new GetCohortQuery(); var result = await validator.ValidateAsync(query); result.IsValid().Should().BeFalse(); result.ValidationDictionary.Count.Should().Be(1); result.ValidationDictionary .Should().ContainKey(nameof(GetCohortQuery.CohortId)) .WhichValue.Should().Be($"{nameof(GetCohortQuery.CohortId)} has not been supplied"); }
public async Task Then_Gets_Cohort_From_CommitmentsV2_Api( GetCohortQuery query, GetCohortResponse apiResponse, [Frozen] Mock <ICommitmentsV2ApiClient <CommitmentsV2ApiConfiguration> > mockApiClient, GetCohortQueryHandler handler) { mockApiClient .Setup(client => client.Get <GetCohortResponse>(It.Is <GetCohortRequest>(request => request.CohortId == query.CohortId))) .ReturnsAsync(apiResponse); var result = await handler.Handle(query, CancellationToken.None); result.Cohort.Should().BeEquivalentTo(apiResponse); }
public void ThenWillThrowExceptionIfValidationFails( GetCohortQuery query, [Frozen] Mock <ICommitmentService> mockCommitmentService, [Frozen] Mock <IValidator <GetCohortQuery> > mockValidator, GetCohortQueryHandler handler) { //Arrange mockValidator.Setup(v => v.ValidateAsync(It.IsAny <GetCohortQuery>())).ReturnsAsync(new ValidationResult { ValidationDictionary = new Dictionary <string, string> { { "Error", "Test Error" } } }); //Act + Assert Assert.ThrowsAsync <ValidationException>(() => handler.Handle(query, CancellationToken.None)); }
public void ThenWillThrowExceptionIfOneOccurs( GetCohortQuery query, Exception exception, [Frozen] Mock <ICommitmentService> mockCommitmentService, [Frozen] Mock <IValidator <GetCohortQuery> > mockValidator, GetCohortQueryHandler handler) { //Arrange mockValidator.Setup(v => v.ValidateAsync(It.IsAny <GetCohortQuery>())) .ReturnsAsync(new ValidationResult { ValidationDictionary = new Dictionary <string, string>() }); mockCommitmentService.Setup(s => s.GetCohort(It.IsAny <long>())) .ThrowsAsync(exception); //Act var actualException = Assert.ThrowsAsync <Exception>(() => handler.Handle(query, CancellationToken.None)); //Assert Assert.AreEqual(exception, actualException); }
public async Task ThenWillUseCorrectCohortId( Cohort expectedCohort, [Frozen] GetCohortQuery query, [Frozen] Mock <ICommitmentService> mockCommitmentService, [Frozen] Mock <IValidator <GetCohortQuery> > mockValidator, GetCohortQueryHandler handler) { //Arrange mockValidator.Setup(v => v.ValidateAsync(It.IsAny <GetCohortQuery>())) .ReturnsAsync(new ValidationResult { ValidationDictionary = new Dictionary <string, string>() }); mockCommitmentService.Setup(s => s.GetCohort(It.IsAny <long>())) .ReturnsAsync(expectedCohort); //Act await handler.Handle(query, CancellationToken.None); //Assert mockCommitmentService.Verify(s => s.GetCohort(query.CohortId), Times.Once); }
public async Task ThenWillGetCohortFromService( GetCohortQuery query, Cohort expectedCohort, [Frozen] Mock <ICommitmentService> mockCommitmentService, [Frozen] Mock <IValidator <GetCohortQuery> > mockValidator, GetCohortQueryHandler handler) { //Arrange mockValidator.Setup(v => v.ValidateAsync(It.IsAny <GetCohortQuery>())) .ReturnsAsync(new ValidationResult { ValidationDictionary = new Dictionary <string, string>() }); mockCommitmentService.Setup(s => s.GetCohort(It.IsAny <long>())) .ReturnsAsync(expectedCohort); //Act var result = await handler.Handle(query, CancellationToken.None); //Assert Assert.AreEqual(expectedCohort, result.Cohort); }