public IActionResult DissociateCustomerUser([FromBody] DissociateCustomerUserEvent customerUser) { try { customerUser.ReceivedUTC = DateTime.UtcNow; var userCustomerInDb = userCustomerService.GetCustomerUser(customerUser.CustomerUID, customerUser.UserUID); if (userCustomerInDb == null) { logger.LogInformation(Messages.CustomerUserAssociationNotExists); return(BadRequest(Messages.CustomerUserAssociationNotExists)); } if (userCustomerService.DissociateCustomerUser(customerUser)) { return(Ok()); } logger.LogWarning(Messages.UnableToSaveToDb); return(BadRequest(Messages.UnableToSaveToDb)); } catch (Exception ex) { logger.LogError(string.Format(Messages.ExceptionOccured, ex.Message, ex.StackTrace)); return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); } }
public void DissociateCustomerUser_GivenPayload_ExpectedTransactionStatus(DissociateCustomerUserEvent userEvent, bool transactionStatus, int deleteCalls, int publishCalls, bool hasException) { //Arrange var deleteQuery = $"DELETE FROM md_customer_CustomerUser " + $"WHERE fk_CustomerUID = UNHEX('{userEvent.CustomerUID.ToString("N")}') " + $"AND fk_UserUID = UNHEX('{userEvent.UserUID.ToString("N")}');"; transaction.Execute(Arg.Any <List <Action> >()) .Returns(a => { if (hasException) { throw new Exception(); } else { a.Arg <List <Action> >().ForEach(action => action.Invoke()); return(true); } }); //Act if (hasException) { Assert.Throws <Exception>(() => userCustomerService.DissociateCustomerUser(userEvent)); } else { var resultData = userCustomerService.DissociateCustomerUser(userEvent); Assert.Equal(transactionStatus, resultData); } //Assert transaction.Received(deleteCalls).Delete(Arg.Is(deleteQuery)); transaction.Received(publishCalls).Publish( Arg.Is <List <KafkaMessage> >(messages => messages .TrueForAll(m => ValidateCustomerUserKafkaObject(true, m, userEvent)))); }