public void TestGetAllMessageTypes(IEnumerable <DataObject> messageTypes)
        {
            foreach (var dataService in DataServices)
            {
                // Arrange.
                var objsToUpdate = messageTypes.ToArray();
                if (objsToUpdate.Length > 0)
                {
                    dataService.UpdateObjects(ref objsToUpdate);
                }

                // Reset DataObjects status
                foreach (var item in objsToUpdate)
                {
                    item.Prototyping(false);
                }

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

                // Act.
                var actualList = component.GetAllMessageTypes();

                // Assert.
                Assert.Equal(objsToUpdate.Length, actualList.Count());

                if (objsToUpdate.Length > 0)
                {
                    ObjectRepositoryTestHelper.CheckPropertiesOfAllObjects(actualList, objsToUpdate, new[] { "ID", "Name" });
                }
            }
        }
Пример #2
0
        private void TestLoadingAllData <TDataObjectType>(
            IDataService dataService,
            DataObject[] objsToUpdate,
            DataObject[] additionalObjsToUpdate,
            CachedDataServiceObjectRepository component,
            Func <IEnumerable <TDataObjectType> > methodUnderTest,
            int updatePeriod,
            string[] propertiesToCheck)
            where TDataObjectType : DataObject
        {
            // Arrange.
            dataService.UpdateObjects(ref objsToUpdate);
            var objsToCheckCount           = ObjectRepositoryTestHelper.GetObjectsOfSpecifiedTypeCount <TDataObjectType>(objsToUpdate);
            var additionalObjsToCheckCount = ObjectRepositoryTestHelper.GetObjectsOfSpecifiedTypeCount <TDataObjectType>(additionalObjsToUpdate);

            // Act and Assert.
            var actualList = methodUnderTest();

            // If component is not started then no data should be stored in cache.
            Assert.Equal(0, actualList.Count());

            component.Prepare();
            actualList = methodUnderTest();

            // Ititially stored data shuould be loaded to cache after preparing component.
            Assert.Equal(objsToCheckCount, actualList.Count());
            ObjectRepositoryTestHelper.CheckPropertiesOfAllObjects(actualList, objsToUpdate, propertiesToCheck);

            // Add more buses to database.
            dataService.UpdateObjects(ref additionalObjsToUpdate);

            component.Start();
            Thread.Sleep(updatePeriod + 1000);
            actualList = methodUnderTest();

            // Ititially stored data and additional data shuould be loaded to cache after starting component.
            Assert.Equal(objsToCheckCount + additionalObjsToCheckCount, actualList.Count());
            ObjectRepositoryTestHelper.CheckPropertiesOfAllObjects(actualList, objsToUpdate, propertiesToCheck);
            ObjectRepositoryTestHelper.CheckPropertiesOfAllObjects(actualList, additionalObjsToUpdate, propertiesToCheck);

            component.Stop();
            component.ClearCache();
        }
        public void TestGetAllRestrictions(IEnumerable <DataObject> sendingPermissions)
        {
            foreach (var dataService in DataServices)
            {
                // Arrange.
                var sendingPermissionsArray = sendingPermissions.ToArray();

                if (sendingPermissionsArray.Length > 0)
                {
                    var          client1      = ((SendingPermission)sendingPermissionsArray[0]).Client;
                    var          client2      = ((SendingPermission)sendingPermissionsArray[1]).Client;
                    var          messageType1 = ((SendingPermission)sendingPermissionsArray[0]).MessageType;
                    var          messageType2 = ((SendingPermission)sendingPermissionsArray[1]).MessageType;
                    DataObject[] objsToUpdate =
                    {
                        client1,                    client2, messageType1, messageType2,
                        sendingPermissionsArray[0], sendingPermissionsArray[1]
                    };

                    dataService.UpdateObjects(ref objsToUpdate);

                    // Reset DataObjects status
                    foreach (var item in objsToUpdate)
                    {
                        item.Prototyping(false);
                    }
                }

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

                // Act.
                var actualList = component.GetAllRestrictions();

                // Assert.
                Assert.Equal(sendingPermissionsArray.Length, actualList.Count());

                if (sendingPermissionsArray.Length > 0)
                {
                    ObjectRepositoryTestHelper.CheckPropertiesOfAllObjects(actualList, sendingPermissionsArray, new[] { "Client.ID" });
                }
            }
        }