コード例 #1
0
        public void ManagementApi_ShouldCreateGetOrDeleteHubOrRecieveConflictException()
        {
            LoadMockData();
            try
            {
                bool notificationHubExists = true;
                IEnumerable <NotificationHubDescription> notificationHubDescriptions;

                // Check that GetNotification returns MessagingEntityNotFoundException than hub does not exist
                Assert.Throws <MessagingEntityNotFoundException>(() => _namespaceManager.GetNotificationHub(_notificationHubName));

                // Check that NotificationHubExists returns false when notification hub does not exist
                notificationHubExists = _namespaceManager.NotificationHubExists(_notificationHubName);
                Assert.False(notificationHubExists);

                // Check that GetNotificationHubs returns collection without hub
                notificationHubDescriptions = _namespaceManager.GetNotificationHubs();
                Assert.DoesNotContain(notificationHubDescriptions, nhd => nhd.Path == _notificationHubName);

                // Check that CreateNotificationHub method create hub with correct Path
                var createNotificationHubDescription = _namespaceManager.CreateNotificationHub(_notificationHubName);
                Assert.Equal(_notificationHubName, createNotificationHubDescription.Path);

                // Check that NotificationHubExists return true when notification hub exist
                notificationHubExists = _namespaceManager.NotificationHubExists(_notificationHubName);
                Assert.True(notificationHubExists);

                // Check that GetNotificationHubs returns collection with existed hub
                notificationHubDescriptions = _namespaceManager.GetNotificationHubs();
                Assert.Single(notificationHubDescriptions);

                // Check that CreateNotificationHub returns MessagingEntityAlreadyExistsException than hub is alredy exist
                Assert.Throws <MessagingEntityAlreadyExistsException>(() => _namespaceManager.CreateNotificationHub(_notificationHubName));

                // Check that GetNotificationHub returns correct hub
                var getNotificationHubDescription = _namespaceManager.GetNotificationHub(_notificationHubName);
                Assert.NotNull(getNotificationHubDescription);

                // Check that UpdateNotificationHub correctly update hub
                createNotificationHubDescription.IsDisabled = true;
                var updatedNotificationHubDescription = _namespaceManager.UpdateNotificationHub(createNotificationHubDescription);
                Assert.True(updatedNotificationHubDescription.IsDisabled);

                // Check that DeleteNotificationHub correctly remove hub
                _namespaceManager.DeleteNotificationHub(_notificationHubName);

                // Check that NotificationHubExists return false when notification hub is not exist
                notificationHubExists = _namespaceManager.NotificationHubExists(_notificationHubName);
                Assert.False(notificationHubExists);

                // Check that GetNotificationHubs returns collection without not existed hub
                notificationHubDescriptions = _namespaceManager.GetNotificationHubs();
                Assert.Empty(notificationHubDescriptions);

                // Check that DeleteNotificationHub returns MessagingEntityNotFoundException than hub is not exist
                Assert.Throws <MessagingEntityNotFoundException>(() => _namespaceManager.DeleteNotificationHub(_notificationHubName));
            }
            finally
            {
                RecordTestResults();
            }
        }