public IActionResult DeleteUserCustomerRelationship( [FromBody] DeleteUserCustomerRelationshipEvent userCustomerRelationship) { try { userCustomerRelationship.ReceivedUTC = DateTime.UtcNow; if (userCustomerService.GetCustomerUser(userCustomerRelationship.CustomerUID, userCustomerRelationship.UserUID) == null) { logger.LogInformation(Messages.CustomerUserAssociationNotExists); return(BadRequest(Messages.CustomerUserAssociationNotExists)); } if (customerService.DeleteUserCustomerRelationship(userCustomerRelationship)) { 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 DeleteUserCutsomerRelationship_GivenPayload_ExpectedStatus( DeleteUserCustomerRelationshipEvent relationshipEvent, bool transactionStatus, int upsertCalls, int deleteCalls, int publishCalls, bool hasException) { //Arrange if (hasException) { transaction.When(x => x.Delete(Arg.Any <string>())) .Do(e => throw new Exception()); } transaction.Execute(Arg.Any <List <Action> >()) .Returns(a => { a.Arg <List <Action> >().ForEach(action => action.Invoke()); return(true); }); var deleteQuery = $"DELETE FROM md_customer_CustomerUser " + $"WHERE fk_CustomerUID = UNHEX('{relationshipEvent.CustomerUID.ToString("N")}') " + $"AND fk_UserUID = UNHEX('{relationshipEvent.UserUID.ToString("N")}');"; //Act if (hasException) { Assert.Throws <Exception>(() => customerService.DeleteUserCustomerRelationship(relationshipEvent)); } else { var resultData = customerService.DeleteUserCustomerRelationship(relationshipEvent); Assert.Equal(transactionStatus, resultData); } //Assert transaction.Received(upsertCalls).Upsert(Arg.Any <DbUserCustomer>()); transaction.Received(deleteCalls).Delete(Arg.Is(deleteQuery)); transaction.Received(publishCalls).Publish( Arg.Is <List <KafkaMessage> >(messages => messages .TrueForAll(m => ValidateCustomerUserKafkaObject(true, false, m, relationshipEvent)))); }