public virtual async Task <ChargeResponse> Execute(Business.Dtos.Charge newCharge) { if (await clientChargeRepository.Get(newCharge.identifier) is ChargeAlreadyExist) { return(new ChargeAlreadyExist()); } await clientActivityService.NotifyNewCharge(new ActivityDto { identifier = newCharge.identifier }); var resultAddCharge = await clientChargeRepository.AddCharge(newCharge); bool resultAdd = false; if (resultAddCharge is ChargeResponseOK) { resultAdd = true; } var identifierDto = new ActivityDto { identifier = newCharge.identifier, AddResult = resultAdd }; var result = await clientActivityService.UpdateNotifyCharge(identifierDto); if (result) { return(new ChargeResponseOK()); } else { return(new ChargeResponseKO()); } }
private async Task VerifyResult(Business.Dtos.Charge newCharge, ActivityDto activityDto, ChargeActivityServiceApiClient clientActivityService, ChargeResponse result) { result.Should().BeOfType <ChargeResponseOK>(); await clientActivityService.Received(1).NotifyNewCharge(Arg.Is <ActivityDto>(item => item.identifier == activityDto.identifier)); await clientChargeRepository.Received(1).AddCharge(newCharge); await clientActivityService.Received(1).UpdateNotifyCharge(Arg.Is <ActivityDto>(item => item.identifier == activityDto.identifier && item.AddResult == activityDto.AddResult)); }
private static HttpContent GivenAHttpContent(Business.Dtos.Charge charge2, string requestUri) { string jsonVideo = JsonConvert.SerializeObject(charge2, Formatting.Indented); HttpContent content = new StringContent(jsonVideo, Encoding.UTF8, "application/json"); HttpRequestMessage request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(requestUri), Content = content }; return(content); }
public async Task should_return_charge_already_exist_when_try_add_charge_with_exist_identifier() { var addResult = true; Business.Dtos.Charge newCharge = GivenACharge(); ActivityDto activityDto = GivenAnActivity(newCharge.identifier, addResult); ChargeActivityServiceApiClient clientActivityService = GivenAMockActivityServiceClient(activityDto); var addChargeAction = new AddChargeAction(clientChargeRepository, clientActivityService); clientChargeRepository.Get(newCharge.identifier).Returns(new ChargeAlreadyExist()); var result = await addChargeAction.Execute(newCharge); result.Should().BeOfType <ChargeAlreadyExist>(); clientChargeRepository.Received(1).Get(newCharge.identifier); }
public async Task given_data_for_add_new_charge_we_obtein_a_true_response() { Business.Dtos.Charge newCharge = GivenACharge(); var addResult = true; clientChargeRepository.AddCharge(newCharge).Returns(new ChargeResponseOK()); ActivityDto activityDto = GivenAnActivity(newCharge.identifier, addResult); ChargeActivityServiceApiClient clientActivityService = GivenAMockActivityServiceClient(activityDto); clientActivityService.NotifyNewCharge(Arg.Any <ActivityDto>()).Returns(true);; clientActivityService.UpdateNotifyCharge(Arg.Any <ActivityDto>()).Returns(true);; var addChargeAction = new AddChargeAction(clientChargeRepository, clientActivityService); var result = await addChargeAction.Execute(newCharge); await VerifyResult(newCharge, activityDto, clientActivityService, result); }
public void Setup() { newCharge = GivenANewCharge(); client = TestFixture.HttpClient; identifier = "any identifier"; }
private static async Task verifyResult(Business.Dtos.Charge newCharge, AddChargeAction action, HttpResponseMessage result) { result.StatusCode.Should().Be(HttpStatusCode.OK); await action.Received(1).Execute(Arg.Is <Business.Dtos.Charge>(item => item.identifier == newCharge.identifier && item.Amount == newCharge.Amount && item.Description == newCharge.Description)); }