コード例 #1
0
        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));
            }
        }
コード例 #2
0
        public bool DissociateCustomerUser(DissociateCustomerUserEvent dissociateCustomerUser)
        {
            try
            {
                List <KafkaMessage> messages = CustomerTopics
                                               ?.Select(topic => new KafkaMessage
                {
                    Key     = dissociateCustomerUser.CustomerUID.ToString(),
                    Message = new { DissociateCustomerUserEvent = dissociateCustomerUser },
                    Topic   = topic
                })
                                               ?.ToList();

                var deleteQuery = string.Format("DELETE FROM md_customer_CustomerUser " +
                                                "WHERE fk_CustomerUID = {0} AND fk_UserUID = {1};",
                                                dissociateCustomerUser.CustomerUID.ToStringAndWrapWithUnhex(),
                                                dissociateCustomerUser.UserUID.ToStringAndWrapWithUnhex());

                var actions = new List <Action>
                {
                    () => transaction.Delete(deleteQuery),
                    () => transaction.Publish(messages)
                };
                return(transaction.Execute(actions));
            }
            catch (Exception ex)
            {
                logger.LogError($"Error while dissociating user for customer : {ex.Message}, {ex.StackTrace}");
                throw;
            }
        }
コード例 #3
0
        public static DissociateCustomerUserEvent GetDefaultValidDissociateCustomerUserServiceRequest()
        {
            DissociateCustomerUserEvent defaultValidDissociateCustomerAssetServiceModel = new DissociateCustomerUserEvent();

            defaultValidDissociateCustomerAssetServiceModel.CustomerUID = customerUserServiceSupport.AssociateCustomerUserModel.CustomerUID;
            defaultValidDissociateCustomerAssetServiceModel.UserUID     = customerUserServiceSupport.AssociateCustomerUserModel.UserUID;
            defaultValidDissociateCustomerAssetServiceModel.ActionUTC   = DateTime.UtcNow;
            defaultValidDissociateCustomerAssetServiceModel.ReceivedUTC = null;
            return(defaultValidDissociateCustomerAssetServiceModel);
        }
コード例 #4
0
        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))));
        }