Esempio n. 1
0
        public void UserCommandService_UpdateQueue()
        {
            // Create User
            CreateUser();
            CreateQueue();

            // Create Queue
            Queue queue = GetQueue();
            var   userCommandService = GetDependency <IUserCommandService>();

            Assert.IsInstanceOfType(userCommandService, typeof(IUserCommandService));
            QueueDetails queueDetails = new QueueDetails();

            queueDetails.Id    = queue.Id;
            queueDetails.Title = "Updated Queues";
            userCommandService.UpdateQueue(queueDetails);

            // Find Queue after update
            Queue        updatedSavedQueue      = GetQueue();
            QueueDetails queueDetailsPostUpdate = new QueueDetails();

            queueDetailsPostUpdate.Id    = updatedSavedQueue.Id;
            queueDetailsPostUpdate.Title = updatedSavedQueue.Title;
            Assert.IsTrue(Utils.ReflectiveEquals(queueDetails, queueDetailsPostUpdate));
        }
Esempio n. 2
0
        public void EstablishConnectionTest()
        {
            // STEP 1: prepare mocked data
            QueueDetails details = new QueueDetails {
                Host        = "testhost",
                Name        = "testname",
                Password    = "******",
                Port        = 5672,
                UserName    = "******",
                VirtualHost = "vhost"
            };

            Mock <IConsumer> consumer = new Mock <IConsumer>();

            consumer.Setup(x => x.Id).Returns("testing");
            consumer.Setup(x => x.GetQueueDetails()).Returns(details);

            // is the controller in its initial state?
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);

            StreamController.Instance.AddConsumer(consumer.Object, -1, -1);

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);

            StreamController.Instance.RemoveConsumer(consumer.Object);

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
        }
Esempio n. 3
0
 public List <QueueDetails> DeleteAppoinment(int hospitalId, int Id, string Note, string LoginUserRole)
 {
     try
     {
         SqlParameter[] sqlparam;
         sqlparam    = new SqlParameter[5];
         sqlparam[0] = new SqlParameter("@Flag", "2");
         sqlparam[1] = new SqlParameter("@Id", Id);
         sqlparam[2] = new SqlParameter("@HospitalId", hospitalId);
         sqlparam[3] = new SqlParameter("@Note", Note);
         sqlparam[4] = new SqlParameter("@Role", LoginUserRole);
         DataTable           ds  = CommonFunction.GetDataTable("USP_GET_QUELIST", sqlparam, "");
         List <QueueDetails> lst = new List <QueueDetails>();
         if (ds != null && ds.Rows.Count > 0)
         {
             DataTable dt = ds;
             foreach (DataRow dr in dt.Rows)
             {
                 QueueDetails Model = new QueueDetails();
                 CommonFunction.ReflectSingleData(Model, dr);
                 lst.Add(Model);
             }
         }
         return(lst);
     }
     catch (Exception Ex)
     {
         throw Ex;
     }
 }
        public void EstablishConnectionTest()
        {
            // STEP 1: prepare mocked data
            QueueDetails details = new QueueDetails {
                Host = "testhost",
                Name = "testname",
                Password = "******",
                Port = 5672,
                UserName = "******",
                VirtualHost = "vhost"
            };

            Mock<IConsumer> consumer = new Mock<IConsumer>();
            consumer.Setup(x => x.Id).Returns("testing");
            consumer.Setup(x => x.GetQueueDetails()).Returns(details);

            // is the controller in its initial state?
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);

            StreamController.Instance.AddConsumer(consumer.Object, -1, -1);

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);

            StreamController.Instance.RemoveConsumer(consumer.Object);

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
        }
Esempio n. 5
0
        private void CreateConectionFactory(IConsumer consumer)
        {
            QueueDetails queue = null;

            try
            {
                queue = consumer.GetQueueDetails();
                if (queue == null || string.IsNullOrEmpty(queue.Name))
                {
                    var e = new Exception("queue's name is not valid for fixtureId=" + consumer.Id);
                    throw e;
                }
            }
            catch (Exception e)
            {
                Logger.LogError("Error acquiring queue details for fixtureId=" + consumer.Id, e);
                throw;
            }

            //Logger.LogInformation($"ConnectionFactory h={queue.Host} u={queue.UserName} p={queue.Password} ch={queue.VirtualHost}");

            ConnectionFactory = new ConnectionFactory
            {
                RequestedHeartbeat       = TimeSpan.FromSeconds(UDAPI.Configuration.AMQPMissedHeartbeat),
                HostName                 = queue.Host,
                AutomaticRecoveryEnabled = AutoReconnect,
                Port        = queue.Port,
                UserName    = queue.UserName,
                Password    = queue.Password,
                VirtualHost = "/" + queue.VirtualHost // this is not used anymore, we keep it for retro-compatibility
            };
        }
Esempio n. 6
0
        public void IgnoreUpdatesOnDisconnectionTest()
        {
            // STEP 1: prepare mocked data

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);

            object _lock = new object();

            Mock <IConsumer>[] consumers = new Mock <IConsumer> [10000];

            for (int i = 0; i < 10000; i++)
            {
                QueueDetails details = new QueueDetails {
                    Host        = "testhost",
                    Name        = "testname",
                    Password    = "******",
                    Port        = 5672,
                    UserName    = "******",
                    VirtualHost = "vhost"
                };

                Mock <IConsumer> consumer = new Mock <IConsumer>();
                consumer.Setup(x => x.Id).Returns("testing_" + i);
                consumer.Setup(x => x.GetQueueDetails()).Returns(details);
                consumers[i] = consumer;

                // when the stream connected event is raised, just wait...
                // note that the event is raised async
                consumer.Setup(x => x.OnStreamConnected()).Callback(() => { lock (_lock) { Monitor.Wait(_lock); } });
                StreamController.Instance.AddConsumer(consumer.Object, -1, -1);
            }

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
            StreamController.Instance.Dispatcher.SubscribersCount.Should().Be(10000);

            // send some messages
            for (int i = 0; i < 10000; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    StreamController.Instance.Dispatcher.DispatchMessage("testing_" + i, "UPDATE_" + j);
                }
            }

            StreamController.Instance.Dispatcher.RemoveAll();
            lock (_lock)
            {
                Monitor.PulseAll(_lock);
            }

            Thread.Sleep(2000);


            for (int i = 0; i < 10000; i++)
            {
                consumers[i].Verify(x => x.OnStreamEvent(It.IsAny <StreamEventArgs>()), Times.Never, "Updates shouldn't have been processed");
            }
        }
Esempio n. 7
0
        public void UpdateQueue([FromBody] QueueDetails queueData)
        {
            NamespaceManager namespaceManager = CreateNamespaceManager();

            QueueDescription description = namespaceManager.GetQueue(queueData.name);

            queueData.ApplyChangesToDescription(description);

            namespaceManager.UpdateQueue(description);
        }
Esempio n. 8
0
        public void DisposeTest()
        {
            // is the controller in its initial state?
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);
            Mock <IConsumer>[] consumers = new  Mock <IConsumer> [10000];

            // STEP 1: prepare mocked data

            for (int i = 0; i < 10000; i++)
            {
                QueueDetails details = new QueueDetails {
                    Host        = "testhost",
                    Name        = "testname",
                    Password    = "******",
                    Port        = 5672,
                    UserName    = "******",
                    VirtualHost = "vhost"
                };

                Mock <IConsumer> consumer = new Mock <IConsumer>();
                consumer.Setup(x => x.Id).Returns("testing_" + i);
                consumer.Setup(x => x.GetQueueDetails()).Returns(details);
                consumers[i] = consumer;

                // STEP 2: add the consumers
                StreamController.Instance.AddConsumer(consumer.Object, -1, -1);
            }


            // STEP 2: check if the connection was correctly established
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);

            Thread.Sleep(2000);
            Thread.Yield();

            for (int i = 0; i < 10000; i++)
            {
                consumers[i].Verify(x => x.OnStreamConnected(), Times.Once, "Connection event was not raised");
            }

            // STEP 4
            StreamController.Instance.Dispose();

            Thread.Sleep(2000);
            Thread.Yield();

            for (int i = 0; i < 10000; i++)
            {
                consumers[i].Verify(x => x.OnStreamConnected(), Times.Once, "Connection event was not raised");
                consumers[i].Verify(x => x.OnStreamDisconnected(), Times.Once, "Connection event was not raised");
            }

            StreamController.Instance.Dispatcher.SubscribersCount.Should().Be(0);
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);
        }
Esempio n. 9
0
 public ActionResult QueueList(QueueDetails Ob)
 {
     try
     {
         return(Json("1", JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         throw;
     }
 }
        public void StringPalindrome_Always_ReturnsString()
        {
            // Arrange
            var          vm = new MainWindowViewModel();
            QueueDetails objQueueDetails = new QueueDetails()
            {
                QueueID = 1, RandomString = "vinay"
            };

            // Act
            vm.StringPalindrome(objQueueDetails);

            // Assert
            vm.Result.ShouldNotBeEmpty();
        }
Esempio n. 11
0
        public void GetLocalQueueDetails_Returns_Queue_Details()
        {
            const string expectedLongName  = "DIRECT=OS:bur5-9slsv42\\private$\\test";
            const string expectedShortName = "private$\\test";

            GivenAListOfQueues();
            _queueRepositoryMock.Setup(x => x.GetLocalQueues()).Returns(_queueList);

            List <QueueDetails> queueDetails = _queueBuilder.GetLocalQueueDetails();
            QueueDetails        detail       = queueDetails[0];
            string longName = detail.LongName;
            string name     = detail.Name;

            Assert.That(longName, Is.EqualTo(expectedLongName));
            Assert.That(name, Is.EqualTo(expectedShortName));
        }
Esempio n. 12
0
        public void RemoveConsumerTest()
        {
            // STEP 1: prepare mocked data

            QueueDetails details = new QueueDetails {
                Host        = "testhost",
                Name        = "testname",
                Password    = "******",
                Port        = 5672,
                UserName    = "******",
                VirtualHost = "vhost"
            };

            Mock <IConsumer> consumer = new Mock <IConsumer>();

            consumer.Setup(x => x.Id).Returns("testing");
            consumer.Setup(x => x.GetQueueDetails()).Returns(details);

            // is the controller in its initial state?
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);

            // STEP 2: add a consumer
            StreamController.Instance.AddConsumer(consumer.Object, -1, -1);

            // STEP 3: check that up to now, everythin is ok
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
            StreamController.Instance.Dispatcher.GetSubscriber("testing").Should().NotBeNull();

            // STEP 4: remove the consumer
            StreamController.Instance.Dispatcher.RemoveSubscriber(StreamController.Instance.Dispatcher.GetSubscriber("testing"));

            Thread.Sleep(1000);
            Thread.Yield();

            // STEP 5: check the outcome
            consumer.Verify(x => x.OnStreamDisconnected(), Times.Once, "Consumer was not disconnect on connection shutdonw");

            StreamController.Instance.Dispatcher.Should().NotBeNull();
            StreamController.Instance.Dispatcher.SubscribersCount.Should().Be(0);
            StreamController.Instance.Dispatcher.GetSubscriber("testing").Should().BeNull();
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
        }
Esempio n. 13
0
        public List <QueueDetails> GetQueueList(int hospitalId, int UserId, string Date)
        {
            try
            {
                SqlParameter[] sqlparam;
                sqlparam    = new SqlParameter[4];
                sqlparam[0] = new SqlParameter("@Flag", "1");
                sqlparam[1] = new SqlParameter("@HospitalId", hospitalId);
                sqlparam[2] = new SqlParameter("@UserId", UserId);
                if (Date == null)
                {
                    sqlparam[3] = new SqlParameter("@Date", DBNull.Value);
                }
                else
                {
                    sqlparam[3] = new SqlParameter("@Date", Date); //DateTime.ParseExact(Date, "dd/MM/yyyy", CultureInfo.InvariantCulture));/// Date);
                }

                DataTable           ds  = CommonFunction.GetDataTable("USP_GET_QUELIST", sqlparam, "");
                List <QueueDetails> lst = new List <QueueDetails>();
                if (ds != null && ds.Rows.Count > 0)
                {
                    DataTable dt = ds;
                    foreach (DataRow dr in dt.Rows)
                    {
                        QueueDetails Model = new QueueDetails();
                        CommonFunction.ReflectSingleData(Model, dr);
                        lst.Add(Model);
                    }
                }
                return(lst);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
Esempio n. 14
0
        public List <QueueDetails> GetFeatureAppoinmentList(int hospitalId, int UserId, string Date)
        {
            try
            {
                SqlParameter[] sqlparam;
                sqlparam    = new SqlParameter[7];
                sqlparam[0] = new SqlParameter("@Flag", "3");
                sqlparam[1] = new SqlParameter("@HospitalId", hospitalId);
                sqlparam[2] = new SqlParameter("@UserId", UserId);
                sqlparam[3] = new SqlParameter("@Date", Date);

                sqlparam[4] = new SqlParameter("@Id", 0);
                sqlparam[5] = new SqlParameter("@Note", "");
                sqlparam[6] = new SqlParameter("@Role", "");


                DataTable ds = CommonFunction.GetDataTable("USP_GET_DashbordAppoinmentList", sqlparam, "");

                List <QueueDetails> lst = new List <QueueDetails>();
                if (ds != null && ds.Rows.Count > 0)
                {
                    DataTable dt = ds;
                    foreach (DataRow dr in dt.Rows)
                    {
                        QueueDetails Model = new QueueDetails();
                        CommonFunction.ReflectSingleData(Model, dr);
                        lst.Add(Model);
                    }
                }
                return(lst);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
        public void DisposeTest()
        {
            // is the controller in its initial state?
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);
            Mock<IConsumer>[] consumers = new  Mock<IConsumer>[10000];

            // STEP 1: prepare mocked data

            for (int i = 0; i < 10000; i++)
            {
                QueueDetails details = new QueueDetails {
                    Host = "testhost",
                    Name = "testname",
                    Password = "******",
                    Port = 5672,
                    UserName = "******",
                    VirtualHost = "vhost"
                };

                Mock<IConsumer> consumer = new Mock<IConsumer>();
                consumer.Setup(x => x.Id).Returns("testing_" + i);
                consumer.Setup(x => x.GetQueueDetails()).Returns(details);
                consumers[i] = consumer;

                // STEP 2: add the consumers
                StreamController.Instance.AddConsumer(consumer.Object, -1, -1);
            }

           
            // STEP 2: check if the connection was correctly established
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);

            Thread.Sleep(2000);
            Thread.Yield();

            for(int i = 0; i < 10000; i++)
                consumers[i].Verify(x => x.OnStreamConnected(), Times.Once, "Connection event was not raised");

            // STEP 4
            StreamController.Instance.Dispose();

            Thread.Sleep(2000);
            Thread.Yield();

            for (int i = 0; i < 10000; i++)
            {
                consumers[i].Verify(x => x.OnStreamConnected(), Times.Once, "Connection event was not raised");
                consumers[i].Verify(x => x.OnStreamDisconnected(), Times.Once, "Connection event was not raised");
            }

            StreamController.Instance.Dispatcher.SubscribersCount.Should().Be(0);
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);
        }
        public void RemoveConsumerTest()
        {
            // STEP 1: prepare mocked data

            QueueDetails details = new QueueDetails {
                Host = "testhost",
                Name = "testname",
                Password = "******",
                Port = 5672,
                UserName = "******",
                VirtualHost = "vhost"
            };

            Mock<IConsumer> consumer = new Mock<IConsumer>();
            consumer.Setup(x => x.Id).Returns("testing");
            consumer.Setup(x => x.GetQueueDetails()).Returns(details);

            // is the controller in its initial state?
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);

            // STEP 2: add a consumer
            StreamController.Instance.AddConsumer(consumer.Object, -1, -1);

            // STEP 3: check that up to now, everythin is ok
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
            StreamController.Instance.Dispatcher.GetSubscriber("testing").Should().NotBeNull();

            // STEP 4: remove the consumer
            StreamController.Instance.Dispatcher.RemoveSubscriber(StreamController.Instance.Dispatcher.GetSubscriber("testing"));

            Thread.Sleep(1000);
            Thread.Yield();

            // STEP 5: check the outcome
            consumer.Verify(x => x.OnStreamDisconnected(), Times.Once, "Consumer was not disconnect on connection shutdonw");

            StreamController.Instance.Dispatcher.Should().NotBeNull();
            StreamController.Instance.Dispatcher.SubscribersCount.Should().Be(0);
            StreamController.Instance.Dispatcher.GetSubscriber("testing").Should().BeNull();
            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
        }
Esempio n. 17
0
 public void Post(QueueDetails details)
 {
     _userCommandService.UpdateQueue(details);
 }
Esempio n. 18
0
        public QueueDetails GetDetails(string queueName)
        {
            NamespaceManager namespaceManager = CreateNamespaceManager();

            return(QueueDetails.New(namespaceManager.GetQueue(queueName)));
        }
        public void IgnoreUpdatesOnDisconnectionTest()
        {
            // STEP 1: prepare mocked data

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.DISCONNECTED);

            object _lock = new object();

            Mock<IConsumer>[] consumers = new Mock<IConsumer>[10000];

            for (int i = 0; i < 10000; i++)
            {
                QueueDetails details = new QueueDetails {
                    Host = "testhost",
                    Name = "testname",
                    Password = "******",
                    Port = 5672,
                    UserName = "******",
                    VirtualHost = "vhost"
                };
                
                Mock<IConsumer> consumer = new Mock<IConsumer>();
                consumer.Setup(x => x.Id).Returns("testing_" + i);
                consumer.Setup(x => x.GetQueueDetails()).Returns(details);
                consumers[i] = consumer;

                // when the stream connected event is raised, just wait...
                // note that the event is raised async
                consumer.Setup(x => x.OnStreamConnected()).Callback( () => {lock(_lock) { Monitor.Wait( _lock);} });
                StreamController.Instance.AddConsumer(consumer.Object, -1, -1);
            }

            StreamController.Instance.State.ShouldBeEquivalentTo(StreamController.ConnectionState.CONNECTED);
            StreamController.Instance.Dispatcher.SubscribersCount.Should().Be(10000);

            // send some messages
            for(int i = 0; i < 10000; i++)
            {
                for(int j = 0; j < 3; j++)
                {
                    StreamController.Instance.Dispatcher.DispatchMessage("testing_" + i, "UPDATE_" + j);
                }
            }

            StreamController.Instance.Dispatcher.RemoveAll();
            lock(_lock)
            {
                Monitor.PulseAll(_lock);
            }

            Thread.Sleep(2000);


            for(int i = 0; i < 10000; i++)
            {
                consumers[i].Verify(x => x.OnStreamEvent(It.IsAny<StreamEventArgs>()), Times.Never, "Updates shouldn't have been processed");
            }
            
        }