Ejemplo n.º 1
0
 internal virtual bool IsSsoRelatedAction(Constants.MessageActionType messageActionType)
 {
     Constants.MessageActionType[] ssoRelatedActionTypes = new[]
     {
         Constants.MessageActionType.UserCreated,
         Constants.MessageActionType.UserUpdated,
         Constants.MessageActionType.UserActivated,
         Constants.MessageActionType.UserDeActivated
     };
     return(ssoRelatedActionTypes.Contains(messageActionType));
 }
Ejemplo n.º 2
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtCount.Text) && !string.IsNullOrEmpty(txtProductId.Text) && !string.IsNullOrEmpty(txtDatabaseId.Text) && !string.IsNullOrEmpty(txtDSN.Text))
            {
                int productId           = 0;
                var productIds          = txtProductId.Text.Split(_semicolon);
                var productIdCollection = new List <int>();
                if (productIds.Length > 1)
                {
                    for (int i = 0; i < productIds.Length; i++)
                    {
                        productIdCollection.Add(int.Parse(productIds[i]));
                    }
                }
                else
                {
                    productId = int.Parse(txtProductId.Text);
                }

                int count = int.Parse(txtCount.Text);
                Constants.EntityType entityType = (Constants.EntityType)Enum.Parse(typeof(Constants.EntityType),
                                                                                   cbProductType.SelectedItem.ToString());
                Constants.MessageActionType messageType = (Constants.MessageActionType)Enum.Parse(typeof(Constants.MessageActionType), cbMessageType.SelectedItem.ToString());

                int    databaseId = int.Parse(txtDatabaseId.Text);
                string dsn        = txtDSN.Text;

                MsmqManager manager = new MsmqManager(_config.NormalQueueName, _config.PoisonQueueName);
                var         msg     = new UpdateMessage()
                {
                    Action       = (int)messageType,
                    DSN          = dsn,
                    DatabaseID   = databaseId,
                    EntityTypeId = (int)entityType,
                    ExternalId   = databaseId.ToString(),
                    GroupID      = 1,
                    ProductID    = productId
                };

                if (productIdCollection.Any())
                {
                    var json = JsonConvert.SerializeObject(productIdCollection);
                    msg.ExtendedProperties = json;
                    msg.ProductID          = default(int);
                }

                for (int i = 0; i < count; i++)
                {
                    manager.mqSend(msg, MessagePriority.High);
                }
            }
        }
        public void TestProcessingEventEnqueuesNotProcessedMessages(Constants.MessageActionType messageActionType, Constants.EntityType entityType)
        {
            HashSet <OrchestrationLookup> orchestrationLookups = new HashSet <OrchestrationLookup>();

            orchestrationLookups.Add(new OrchestrationLookup((int)entityType, false));

            var moqLister = new Mock <Listener>(new object[] { new Mock <IAppConfiguration>().Object, new Mock <IDatabaseManager>().Object, new Mock <IStarChefMessageSender>().Object });
            var ud        = new UserDatabase(0, string.Empty, string.Empty);

            ud.OrchestrationLookups = orchestrationLookups;

            var messagesToProcess = GetMessages(entityType, messageActionType, 2);

            moqLister.Setup(l => l.GetDatabaseMessages(It.IsAny <UserDatabase>())).Returns(messagesToProcess);

            var enqueueCount = 0;

            moqLister.Setup(l => l.Enqueue(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <OrchestrationQueueStatus>(), It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>()))
            .Callback <string, int, int, OrchestrationQueueStatus, int, DateTime, int, string, int>((conn, entityId, entityTypeId, status, retryCount, dateCreated, databaseId, externalId, messageActionTypeId) =>
            {
                enqueueCount++;
            });

            var obj = moqLister.Object;

            obj.CanProcess = true;

            Mock <StarChef.Common.Engine.IPriceEngine> priceEngine = new Mock <StarChef.Common.Engine.IPriceEngine>();

            priceEngine.Setup(x => x.IsEngineEnabled()).Returns(Task.FromResult(false));
            priceEngine.Setup(x => x.GlobalRecalculation(It.IsAny <bool>(), It.IsAny <DateTime?>())).Returns(Task.FromResult((new List <Common.Model.DbPrice>().AsEnumerable())));

            // Act
            obj.Process(priceEngine.Object, ud, messagesToProcess.Count);

            // Assert
            moqLister.Verify(x => x.Enqueue(
                                 It.Is <string>(c => c == ud.ConnectionString),
                                 It.Is <int>(c => c == messagesToProcess.First().ProductID),
                                 It.Is <int>(c => c == messagesToProcess.First().EntityTypeId),
                                 It.Is <OrchestrationQueueStatus>(c => c == OrchestrationQueueStatus.Blocked),
                                 It.Is <int>(c => c == messagesToProcess.First().RetryCount),
                                 It.Is <DateTime>(c => c == messagesToProcess.First().ArrivedTime),
                                 It.Is <int>(c => c == ud.DatabaseId),
                                 It.Is <string>(c => c == messagesToProcess.First().ExternalId),
                                 It.Is <int>(c => c == messagesToProcess.First().Action)));

            Assert.Equal(messagesToProcess.Count, enqueueCount);
        }
Ejemplo n.º 4
0
 private void AddOrchestrationMessageToQueue(string dsn, int entityId, int entityTypeId, string externalId, Constants.MessageActionType messageActionTypeId)
 {
     ExecuteStoredProc(dsn,
                       "sc_calculation_enqueue",
                       new SqlParameter("@EntityId", entityId),
                       new SqlParameter("@EntityTypeId", entityTypeId),
                       new SqlParameter("@RetryCount", 0)
     {
         Value = 0, DbType = System.Data.DbType.Int32
     },
                       new SqlParameter("@StatusId", 1),
                       new SqlParameter("@DateCreated", DateTime.UtcNow),
                       new SqlParameter("@ExternalId", externalId),
                       new SqlParameter("@MessageActionTypeId", messageActionTypeId));
 }
        public void TestProcessingEventUpdateSuccess(Constants.MessageActionType messageActionType, Constants.EntityType entityType)
        {
            HashSet <CalculateUpdateMessage> sendCommandMessages = new HashSet <CalculateUpdateMessage>();
            HashSet <CalculateUpdateMessage> sendDeleteMessages  = new HashSet <CalculateUpdateMessage>();
            HashSet <CalculateUpdateMessage> sendMessages        = new HashSet <CalculateUpdateMessage>();

            HashSet <OrchestrationLookup> orchestrationLookups = new HashSet <OrchestrationLookup>();

            orchestrationLookups.Add(new OrchestrationLookup((int)entityType, true));

            var moqLister = new Mock <Listener>(new object[] { new Mock <IAppConfiguration>().Object, new Mock <IDatabaseManager>().Object, new Mock <IStarChefMessageSender>().Object });
            var ud        = new UserDatabase(0, string.Empty, string.Empty);

            ud.OrchestrationLookups = orchestrationLookups;

            var messagesToProcess = GetMessages(entityType, messageActionType, 2);

            moqLister.Setup(l => l.GetDatabaseMessages(It.IsAny <UserDatabase>())).Returns(messagesToProcess);

            moqLister.Setup(l => l.SendCommand(It.IsAny <CalculateUpdateMessage>(), It.IsAny <UserDatabase>())).Callback <CalculateUpdateMessage, UserDatabase>((message, database) =>
            {
                sendCommandMessages.Add(message);
            });

            moqLister.Setup(l => l.SendDeleteCommand(It.IsAny <CalculateUpdateMessage>(), It.IsAny <UserDatabase>())).Callback <CalculateUpdateMessage, UserDatabase>((message, database) =>
            {
                sendDeleteMessages.Add(message);
            });

            moqLister.Setup(l => l
                            .Send(It.IsAny <EnumHelper.EntityTypeWrapper>(), It.IsAny <string>(), It.IsAny <CalculateUpdateMessage>(), It.IsAny <int>()))
            .Callback <EnumHelper.EntityTypeWrapper?, string, CalculateUpdateMessage, int>((wrapper, connectionString, message, databaseId) =>
            {
                sendMessages.Add(message);
            });

            var obj = moqLister.Object;

            obj.CanProcess = true;
            //act

            Mock <StarChef.Common.Engine.IPriceEngine> priceEngine = new Mock <StarChef.Common.Engine.IPriceEngine>();

            priceEngine.Setup <Task <bool> >(x => x.IsEngineEnabled()).Returns(Task.FromResult(true));
            priceEngine.Setup <Task <IEnumerable <Common.Model.DbPrice> > >(x => x.GlobalRecalculation(It.IsAny <bool>(), It.IsAny <DateTime?>())).Returns(Task.FromResult((new List <Common.Model.DbPrice>().AsEnumerable())));

            obj.Process(priceEngine.Object, ud, messagesToProcess.Count);
            //assert results
            if (messageActionType == Constants.MessageActionType.StarChefEventsUpdated ||
                messageActionType == Constants.MessageActionType.UserCreated ||
                messageActionType == Constants.MessageActionType.UserActivated ||
                messageActionType == Constants.MessageActionType.SalesForceUserCreated)
            {
                Assert.Equal(sendMessages.Count, messagesToProcess.Count);
                Assert.Empty(sendCommandMessages);
                Assert.Empty(sendDeleteMessages);
            }
            else if (messageActionType == Constants.MessageActionType.UserDeActivated)
            {
                Assert.Equal(sendCommandMessages.Count, messagesToProcess.Count);
                Assert.Empty(sendMessages);
                Assert.Empty(sendDeleteMessages);
            }
            else if (messageActionType == Constants.MessageActionType.EntityDeleted)
            {
                Assert.Equal(sendDeleteMessages.Count, messagesToProcess.Count);
                Assert.Empty(sendCommandMessages);
                Assert.Empty(sendMessages);
            }
        }
        protected HashSet <CalculateUpdateMessage> GetMessages(Constants.EntityType entityType, Constants.MessageActionType messageActionType, int count)
        {
            HashSet <CalculateUpdateMessage> messages = new HashSet <CalculateUpdateMessage>();

            for (int i = 0; i < count; i++)
            {
                var calculateMessage = new CalculateUpdateMessage(i, string.Empty, (int)messageActionType, 0, (int)entityType, i, 0, OrchestrationQueueStatus.New);
                calculateMessage.ExternalId = "ExternalId";
                messages.Add(calculateMessage);
            }

            return(messages);
        }