Exemplo n.º 1
0
        public void GetAssetCustomerByRelationType_ValidCustomerAsset_ReturnsResult()
        {
            //Arrange
            var assetCustomer = new DbAssetCustomer
            {
                AssetCustomerID        = 1,
                Fk_CustomerUID         = Guid.NewGuid(),
                Fk_AssetUID            = Guid.NewGuid(),
                fk_AssetRelationTypeID = 1,
                LastCustomerUTC        = DateTime.UtcNow
            };
            var config = new ComparisonConfig
            {
                IgnoreObjectTypes             = true,
                MaxMillisecondsDateDifference = 500,
                MaxDifferences = 0
            };
            var assetCustomerCompareLogic = new CompareLogic(config);

            transaction.Get <DbAssetCustomer>(Arg.Any <string>()).Returns(new List <DbAssetCustomer> {
                assetCustomer
            });

            //Act
            var resultData = customerAssetService.GetAssetCustomer(assetCustomer.Fk_CustomerUID, assetCustomer.Fk_AssetUID);

            //Arrange
            Assert.NotNull(resultData);
            ComparisonResult compareResult = assetCustomerCompareLogic.Compare(assetCustomer, resultData);

            Assert.True(compareResult.Differences.Count == 0);
        }
Exemplo n.º 2
0
 private bool ValidateCustomerAssetObject(dynamic source, DbAssetCustomer target)
 {
     Enum.TryParse(source.RelationType, true, out TestDataEnums.RelationType relationType);
     return(target.Fk_CustomerUID == source.CustomerUID &&
            target.Fk_AssetUID == source.AssetUID &&
            target.fk_AssetRelationTypeID == (int)relationType);
 }
Exemplo n.º 3
0
        public bool AssociateCustomerAsset(AssociateCustomerAssetEvent associateCustomerAsset)
        {
            try
            {
                var customer = GetCustomer(associateCustomerAsset.CustomerUID);
                if (customer?.CustomerID > 0)
                {
                    Enum.TryParse(associateCustomerAsset.RelationType, true,
                                  out CustomerEnum.RelationType relationType);

                    var messages = CustomerTopics
                                   ?.Select(topic => new KafkaMessage
                    {
                        Key     = associateCustomerAsset.CustomerUID.ToString(),
                        Message = new
                        {
                            AssociateCustomerAssetEvent = new
                            {
                                associateCustomerAsset.CustomerUID,
                                associateCustomerAsset.AssetUID,
                                RelationType = relationType.ToString(),
                                associateCustomerAsset.ActionUTC,
                                associateCustomerAsset.ReceivedUTC
                            }
                        },
                        Topic = topic
                    })
                                   ?.ToList();
                    var assetCustomer = new DbAssetCustomer
                    {
                        Fk_CustomerUID         = associateCustomerAsset.CustomerUID,
                        Fk_AssetUID            = associateCustomerAsset.AssetUID,
                        fk_AssetRelationTypeID = (int)relationType,
                        LastCustomerUTC        = DateTime.UtcNow
                    };

                    var actions = new List <Action>()
                    {
                        () => transaction.Upsert(assetCustomer),
                        () => transaction.Publish(messages)
                    };
                    return(transaction.Execute(actions));
                }

                logger.LogInformation($"Skipping the CustomerAsset Association as the required customeruid" +
                                      $" {associateCustomerAsset.CustomerUID} has not been received yet.");
                return(false);
            }
            catch (Exception ex)
            {
                logger.LogError($"Error while associating asset to customer : {ex.Message}, {ex.StackTrace}");
                throw;
            }
        }