public async Task GivenWeGenerateSomeAssets_WhenWeSearchForAssets_ThenWeCanFindThoseRecords(int recordCount) { //arrange var request = new GenerateAssetsRequest { Records = recordCount }; //act using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var response = await _classUnderTest.ExecuteAsync(request, CancellationToken.None).ConfigureAwait(false); //assert for (int i = 0; i < response.RecordsGenerated.Count; i++) { var generatedAsset = response.RecordsGenerated.ElementAtOrDefault(i); var record = await FindAsset(generatedAsset); record.Should().NotBeNull(); record.AssetOutputModelIsEqual(generatedAsset); } trans.Dispose(); } }
bool IsValidRequest(GenerateAssetsRequest request) { if (request?.Records == null) { return(false); } return(request.Records > 0); }
public async Task GivenValidRequest_ThenUseCase_CallsCreateAssetUseCaseCorrectNumberOfTimes(int recordCount) { //arrange var request = new GenerateAssetsRequest { Records = recordCount }; //act await _classUnderTest.ExecuteAsync(request, CancellationToken.None).ConfigureAwait(false); //assert _mockUseCase.Verify(s => s.ExecuteAsync(It.IsAny <IList <CreateAssetRequest> >(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task <GenerateAssetsResponse> ExecuteAsync(GenerateAssetsRequest requests, CancellationToken cancellationToken) { IList <CreateAssetRequest> createAssetRequests = GenerateCreateAssetRequest(requests.Records.Value); IList <CreateAssetResponse> response = await _createAssetRegisterVersionUseCase.ExecuteAsync(createAssetRequests, cancellationToken) .ConfigureAwait(false); var generateAssetsResponse = new GenerateAssetsResponse { RecordsGenerated = response?.Select(s => s.Asset).ToList() }; return(generateAssetsResponse); }
public void GivenValidInput_ThenIsValidIsTrue(int?id) { //arrange var request = new GenerateAssetsRequest { Records = id }; //act var response = _classUnderTest.Validate(request); //assert response.Should().NotBeNull(); response.IsValid.Should().BeTrue(); }
private GenerateAssetsRequest ValidateInput(string[] args) { if (args == null) { _logger.Log(LogLevel.Information, "Please enter input '--records {numberOfRecordsToGenerate}'"); throw new ArgumentNullException(nameof(args)); } GenerateAssetsRequest request = _inputParser.Parse(args); if (!IsValidRequest(request)) { throw new ArgumentException(); } return(request); }
public void GivenInValidRequest_ThenIsValidIsFalse(int?id, string message) { //arrange var request = new GenerateAssetsRequest { Records = id }; //act var response = _classUnderTest.Validate(request); //assert response.Should().NotBeNull(); response.IsValid.Should().BeFalse(); response.Errors.Should().NotBeNullOrEmpty(); response.Errors[0].PropertyName.Should().BeEquivalentTo("Records"); response.Errors[0].ErrorMessage.Should().BeEquivalentTo(message); }
public async Task GivenWeGenerateSomeAssets_ThenWeKnowHowManyAssetsWereCreated(int recordCount) { //arrange var request = new GenerateAssetsRequest { Records = recordCount }; //act using (var trans = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var response = await _classUnderTest.ExecuteAsync(request, CancellationToken.None) .ConfigureAwait(false); //assert response.Should().NotBeNull(); response.RecordsGenerated.Count.Should().Be(recordCount); trans.Dispose(); } }
public async Task GivenValidRequest_ThenUseCaseGeneratesCorrectNumberOfRecords(int recordCount) { //arrange var request = new GenerateAssetsRequest { Records = recordCount }; var list = new List <CreateAssetResponse>(); for (int i = 0; i < recordCount; i++) { list.Add(new CreateAssetResponse()); } _mockUseCase .Setup(s => s.ExecuteAsync(It.IsAny <IList <CreateAssetRequest> >(), It.IsAny <CancellationToken>())) .ReturnsAsync(list); //act var response = await _classUnderTest.ExecuteAsync(request, CancellationToken.None).ConfigureAwait(false); //assert response.Should().NotBeNull(); response.RecordsGenerated.Should().NotBeNull(); response.RecordsGenerated.Count.Should().Be(recordCount); }