public void TestDeleteSendingPermission()
        {
            foreach (var dataService in DataServices)
            {
                var clientId      = "Client 1";
                var messageTypeId = "Message type 1";
                var client        = new Client()
                {
                    ID = clientId, Name = "Client name 1"
                };
                var messageType = new MessageType()
                {
                    ID = messageTypeId, Name = "Message type name 1"
                };
                var sendingPermission = new SendingPermission()
                {
                    Client = client, MessageType = messageType
                };

                DataObject[] objsToUpdate = { client, messageType, sendingPermission };
                dataService.UpdateObjects(ref objsToUpdate);

                var component = new DataServiceObjectRepository(dataService, GetMockStatisticsService());

                var actualList = component.GetRestrictionsForClient(clientId);
                Assert.Equal(actualList.Count(), 1);

                // Act.
                component.DeleteSendingPermission(clientId, messageTypeId);

                var newActualList = component.GetRestrictionsForClient(clientId);
                Assert.Equal(newActualList.Count(), 0);
            }
        }
示例#2
0
        public void TestParallelAcceptMessageWithGroup()
        {
            foreach (var dataService in DataServices)
            {
                // Arrange.
                var sender = new Client()
                {
                    ID = "senderId"
                };
                var recipient = new Client()
                {
                    ID = "recipientId"
                };
                var messageType = new MessageType()
                {
                    ID = "messageTypeId"
                };
                var subscription = new Subscription()
                {
                    Client = recipient, MessageType = messageType, ExpiryDate = DateTime.Now.AddDays(1)
                };
                var sendingPermission = new SendingPermission()
                {
                    Client = sender, MessageType = messageType
                };

                var dataObjects = new DataObject[] { sender, recipient, messageType, subscription, sendingPermission };
                dataService.UpdateObjects(ref dataObjects);

                var statisticsService = GetMockStatisticsService();
                var component         = new DefaultReceivingManager(
                    GetMockLogger(),
                    new DataServiceObjectRepository(dataService, statisticsService),
                    new DefaultSubscriptionsManager(dataService, statisticsService),
                    GetMockSendingManager(),
                    dataService,
                    statisticsService);

                // Act.
                var message = new ServiceBusMessage()
                {
                    ClientID = sender.ID, MessageTypeID = messageType.ID, Body = string.Empty
                };
                Task.WhenAll(
                    Task.Run(() => component.AcceptMessage(message, "group")),
                    Task.Run(() => component.AcceptMessage(message, "group")),
                    Task.Run(() => component.AcceptMessage(message, "group"))).Wait();

                // Assert.
                Assert.Equal(1, ((SQLDataService)dataService).Query <Message>().Count());
            }
        }
        public static IEnumerable <object[]> SendingPermissionsData()
        {
            var client1 = new Client()
            {
                ID = "Client 1", Name = "Client name 1"
            };
            var client2 = new Client()
            {
                ID = "Client 2", Name = "Client name 2"
            };
            var messageType1 = new MessageType()
            {
                ID = "Message type 1", Name = "Message type name 1"
            };
            var messageType2 = new MessageType()
            {
                ID = "Message type 2", Name = "Message type name 2"
            };

            var sendingPermission1 = new SendingPermission()
            {
                Client = client1, MessageType = messageType1
            };
            var sendingPermission2 = new SendingPermission()
            {
                Client = client2, MessageType = messageType2
            };

            yield return(new object[]
            {
                new List <SendingPermission>()
                {
                    sendingPermission1, sendingPermission2
                }
            });

            yield return(new object[]
            {
                new List <SendingPermission>(0)
            });
        }
示例#4
0
        /// <summary>
        /// Create sending permission.
        /// </summary>
        /// <param name="clientId">Client's ID.</param>
        /// <param name="messageTypeId">Message type's ID.</param>
        /// <param name="dataService">The data service for loading objects.</param>
        /// <param name="statisticsService">Statistics service.</param>
        public static void CreateSendingPermission(string clientId, string messageTypeId, IDataService dataService, IStatisticsService statisticsService)
        {
            Guid   primaryKeyClient = ServiceHelper.ConvertClientIdToPrimaryKey(clientId, dataService, statisticsService);
            Client currentClient    = ServiceHelper.GetClient(primaryKeyClient, dataService, statisticsService);

            Guid        primaryKeyMessageType = ServiceHelper.ConvertMessageTypeIdToPrimaryKey(messageTypeId, dataService, statisticsService);
            MessageType currentMessageType    = ServiceHelper.GetMessageType(primaryKeyMessageType, dataService, statisticsService);

            SendingPermission currentSendingPermission = new SendingPermission {
                Client = currentClient, MessageType = currentMessageType
            };
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            dataService.UpdateObject(currentSendingPermission);

            stopwatch.Stop();
            long time = stopwatch.ElapsedMilliseconds;

            statisticsService.NotifyAvgTimeSql(null, (int)time, "CommonMetodsObjectRepository.CreateSendingPermission() update sendingPermission.");
        }
示例#5
0
        public void TestGetRestrictionsForMsgType()
        {
            foreach (var dataService in DataServices)
            {
                var client1 = new Client()
                {
                    ID = "Client 1", Name = "Client name 1"
                };
                var client2 = new Client()
                {
                    ID = "Client 2", Name = "Client name 2"
                };
                var client3 = new Client()
                {
                    ID = "Client 3", Name = "Client name 3"
                };
                var messageType1 = new MessageType()
                {
                    ID = "Message type 1", Name = "Message type name 1"
                };
                var messageType2 = new MessageType()
                {
                    ID = "Message type 2", Name = "Message type name 2"
                };
                var messageType3 = new MessageType()
                {
                    ID = "Message type 3", Name = "Message type name 3"
                };

                var sendingPermission1 = new SendingPermission()
                {
                    Client = client1, MessageType = messageType1
                };
                var sendingPermission2 = new SendingPermission()
                {
                    Client = client2, MessageType = messageType2
                };
                var sendingPermission3 = new SendingPermission()
                {
                    Client = client3, MessageType = messageType3
                };
                var sendingPermission4 = new SendingPermission()
                {
                    Client = client1, MessageType = messageType2
                };

                DataObject[] objsToUpdate = { client1, client2, messageType1, messageType2, sendingPermission1, sendingPermission2 };

                DataObject[] additionalObjsToUpdate = { client3, messageType3, sendingPermission3, sendingPermission4 };

                var updatePeriod = 3000;
                var component    = new CachedDataServiceObjectRepository(GetMockLogger(),
                                                                         (IDataService)dataService.Clone(), GetMockStatisticsService())
                {
                    UpdatePeriodMilliseconds = updatePeriod
                };

                var messageTypeId = messageType2.ID;

                TestLoadingDataWithCondition(dataService, objsToUpdate, additionalObjsToUpdate, component, component.GetRestrictionsForMsgType, messageTypeId, updatePeriod, "MessageType.ID");
            }
        }