public async Task <IActionResult> BetalingVerwerken([FromBody] BetalingCM betaling) { var betalingVerwerkenCommand = new VerwerkBetalingCommand(betaling, NameConstants.BetaalServiceBetalingVerwerkenCommandQueue); try { await _commandPublisher.Publish <long>(betalingVerwerkenCommand); } catch (InvalidFactuurnummerException) { _logger.LogError("InvalidFactuurnummerException occured, the factuurnummer is: {}", betaling.Factuurnummer); return(BadRequest($"Factuurnummer {betaling.Factuurnummer} kon niet worden gevonden")); } catch (TimeoutException) { _logger.LogError("BetalingVerwerkenCommand resulted in a TimeoutException."); return(StatusCode((int)HttpStatusCode.RequestTimeout, "Aanvraag kon niet worden verwerkt")); } catch (Exception ex) { _logger.LogError("BetalingVerwerkenCommand resulted in an internal server error."); _logger.LogDebug( "Exception occured during execution of UpdateBestelStatusCommand {}, it threw exception: {}. Inner exception: {}", betaling, ex.Message, ex.InnerException?.Message ); return(StatusCode((int)HttpStatusCode.InternalServerError)); } return(StatusCode((int)HttpStatusCode.OK)); }
public void HandleVerWerkBetalingCommand_ShouldInsertNewBetalingAndPublishEvent() { // Arrange var queueName = "TestQueue"; var receiver = _nijnContext.CreateMessageReceiver(queueName, new List <string> { NameConstants.BetaalServiceBetalingGeaccrediteerdEvent }); receiver.DeclareQueue(); var betalingCM = new BetalingCM(1, 200); var command = new VerwerkBetalingCommand(betalingCM, NameConstants.BetaalServiceBetalingVerwerkenCommandQueue); // Act _target.HandleVerWerkBetalingCommand(command); // Assert var queue = _nijnContext.EventBus.Queues[queueName]; var bestellingResult = JsonConvert.DeserializeObject <BestellingGeaccrediteerdEvent>(queue[0].Message); Assert.AreEqual(1, queue.MessageQueueLength); Assert.AreEqual(1, bestellingResult.Factuurnummer); var dbResult = _dbContext.Betalingen.SingleOrDefault(b => b.Factuurnummer == 1); Assert.AreEqual(betalingCM.Bedrag, dbResult.Bedrag); Assert.AreEqual(betalingCM.Factuurnummer, dbResult.Factuurnummer); Assert.AreEqual(1, dbResult.Klantnummer); }
public void HandleVerwerkBetalingCommand_ShouldReturnFactuurnummer() { // Arrange var commandModel = new BetalingCM(1, 400); var command = new VerwerkBetalingCommand(commandModel, ""); _betalingVerwerkenServiceMock.Setup(b => b.HandleBetalingVerwerken(It.IsAny <Betaling>())); // Act var result = _target.HandleVerWerkBetalingCommand(command); // Assert _betalingVerwerkenServiceMock.VerifyAll(); Assert.AreEqual(1, result); }
public void HandleVerWerkBetalingCommand_ShouldInsertNewBetaling() { // Arrange var betalingCM = new BetalingCM(1, 100); var command = new VerwerkBetalingCommand(betalingCM, NameConstants.BetaalServiceBetalingVerwerkenCommandQueue); // Act _target.HandleVerWerkBetalingCommand(command); // Assert var dbResult = _dbContext.Betalingen.SingleOrDefault(b => b.Factuurnummer == 1); Assert.AreEqual(betalingCM.Bedrag, dbResult.Bedrag); Assert.AreEqual(betalingCM.Factuurnummer, dbResult.Factuurnummer); Assert.AreEqual(1, dbResult.Klantnummer); }
public async Task BetalingVerwerken_ShouldReturn408OnTimeout() { // Arrange var betaling = new BetalingCM(1, 200); _commandPublisherMock.Setup(publisher => publisher.Publish <long>(It.IsAny <VerwerkBetalingCommand>())) .Throws <TimeoutException>(); // Act var result = await _target.BetalingVerwerken(betaling); // Assert _commandPublisherMock.VerifyAll(); var requestResult = result as ObjectResult; Assert.IsNotNull(requestResult); Assert.AreEqual(408, requestResult.StatusCode); }
public async Task BetalingVerwerken_ShouldReturn200StatusCode() { // Arrange var betaling = new BetalingCM(1, 200); _commandPublisherMock.Setup(publisher => publisher.Publish <long>(It.IsAny <VerwerkBetalingCommand>())) .ReturnsAsync(1); // Act var result = await _target.BetalingVerwerken(betaling); // Assert _commandPublisherMock.VerifyAll(); var requestResult = result as StatusCodeResult; Assert.IsNotNull(requestResult); Assert.AreEqual(200, requestResult.StatusCode); }
public async Task BetalingVerwerken_ShouldReturn500OnUnknownException() { // Arrange var betaling = new BetalingCM(1, 200); _commandPublisherMock.Setup(publisher => publisher.Publish <long>(It.IsAny <VerwerkBetalingCommand>())) .Throws <InsufficientExecutionStackException>(); // Act var result = await _target.BetalingVerwerken(betaling); // Assert _commandPublisherMock.VerifyAll(); var requestResult = result as StatusCodeResult; Assert.IsNotNull(requestResult); Assert.AreEqual(500, requestResult.StatusCode); }
public async Task BetalingVerwerken_ShouldReturnBadRequestOnInvalidFactuurnummerException() { // Arrange var betaling = new BetalingCM(1, 200); _commandPublisherMock.Setup(publisher => publisher.Publish <long>(It.IsAny <VerwerkBetalingCommand>())) .Throws(new InvalidFactuurnummerException("")); // Act var result = await _target.BetalingVerwerken(betaling); // Assert _commandPublisherMock.VerifyAll(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); var objectResult = result as BadRequestObjectResult; Assert.AreEqual("Factuurnummer 1 kon niet worden gevonden", objectResult.Value); }
public VerwerkBetalingCommand(BetalingCM betalingCM, string routingKey) : base(routingKey) { BetalingCM = betalingCM; }