Exemplo n.º 1
0
        public void UpdateUserCustomerRelationship_GivenPayload_ExpectedStatus(
            UpdateUserCustomerRelationshipEvent relationshipEvent, bool transactionStatus, int upsertCalls,
            int publishCalls, bool hasException)
        {
            //Arrange
            if (hasException)
            {
                transaction.When(x => x.Publish(Arg.Any <List <KafkaMessage> >()))
                .Do(x => throw new Exception());
            }

            if (hasException)
            {
                Assert.Throws <Exception>(() => customerService.UpdateUserCustomerRelationship(relationshipEvent));
            }
            else
            {
                var resultData = customerService.UpdateUserCustomerRelationship(relationshipEvent);

                Assert.Equal(transactionStatus, resultData);
            }
            //Act

            transaction.Received(upsertCalls).Upsert(Arg.Any <DbUserCustomer>());
            transaction.Received(publishCalls).Publish(Arg.Is <List <KafkaMessage> >(messages => messages
                                                                                     .TrueForAll(m => ValidateCustomerUserKafkaObject(false, true, m, relationshipEvent))));
        }
Exemplo n.º 2
0
        public IActionResult UpdateUserCustomerRelationship(
            [FromBody] UpdateUserCustomerRelationshipEvent userCustomerRelationship)
        {
            try
            {
                userCustomerRelationship.ReceivedUTC = DateTime.UtcNow;
                if (customerService.GetCustomer(userCustomerRelationship.CustomerUID) == null)
                {
                    logger.LogInformation(Messages.CustomerDoesntExist);
                    return(BadRequest(Messages.CustomerDoesntExist));
                }

                if (userCustomerService.GetCustomerUser(userCustomerRelationship.CustomerUID,
                                                        userCustomerRelationship.UserUID) == null)
                {
                    logger.LogInformation(Messages.CustomerUserDoesntExist);
                    return(BadRequest(Messages.CustomerUserDoesntExist));
                }

                if (customerService.UpdateUserCustomerRelationship(userCustomerRelationship))
                {
                    return(Ok());
                }

                logger.LogWarning(Messages.PublishKafkaFailure);
                return(BadRequest(Messages.PublishKafkaFailure));
            }
            catch (Exception ex)
            {
                logger.LogError(string.Format(Messages.ExceptionOccured, ex.Message, ex.StackTrace));
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }