public void ServiceLayer_DeleteDomainTopic_DataLayerException_ShouldRethrow(bool getClientThrowsException, bool deleteThrowsException)
        {
            // Setup
            _eventGridManager.ThrowExceptionOnGetClient = getClientThrowsException;
            _eventGridManager.ThrowExceptionOnDelete    = deleteThrowsException;

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                _tableManager,
                _log);

            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();

            parameters.DomainTopicName = "domaintopicname";
            Func <Task> act = async() => await serviceLayer.DeleteDomainTopic(parameters);

            // Act
            act.Should().Throw <RequestFailedException>().WithMessage(_eventGridManager.ExceptionMessage);

            // Verify
            _log.Messages.Should().HaveCount(2);
            _log.Messages[0].Message.Should().Be($"Deleting domain topic {parameters.DomainTopicName}");
            _log.Messages[1].Message.Should().Be("Exception encountered in DeleteDomainTopic method.");
        }
Exemple #2
0
        public async Task DataCleanup_DeleteTables_ShouldWork()
        {
            // Setup
            var dataCleanup = new Functions(_ServiceLayer);

            // Act
            var result = await dataCleanup.DeleteTables(TestValues.GetDataCleanupParameters());

            // Verify
            result.Should().BeOfType <OkResult>();
            _ServiceLayer.DeleteTablesCalled.Should().BeTrue();
        }
Exemple #3
0
        public async Task DataCleanup_DomainTopicList_ShouldWork()
        {
            // Setup
            var dataCleanup = new Functions(_ServiceLayer);

            // Act
            await dataCleanup.DomainTopicList(TestValues.GetQueueMessageData());

            // Verify
            _ServiceLayer.PopulateDomainTopicQueueCalled.Should().BeTrue();
            _ServiceLayer.LastParametersPassed.Should().BeEquivalentTo(TestValues.GetDataCleanupParameters());
        }
Exemple #4
0
        public async Task DataCleanup_InitializeCleanup_ShouldWork()
        {
            // Setup
            var dataCleanup = new Functions(_ServiceLayer);

            // Act
            var result = await dataCleanup.InitializeCleanup(TestValues.GetDataCleanupParameters());

            // Verify
            result.Should().BeOfType <OkResult>();
            _ServiceLayer.DeleteQueuesCalled.Should().BeTrue();
            _ServiceLayer.DeleteTablesCalled.Should().BeTrue();
            _ServiceLayer.PopulateDomainTopicQueueCalled.Should().BeTrue();
        }
Exemple #5
0
        public async Task DataCleanup_DomainTopicCleanup_ShouldWork()
        {
            // Setup
            var    dataCleanup = new Functions(_ServiceLayer);
            string topicName   = "domaintopicname";
            string parameters  = TestValues.GetQueueMessageData(topicName);

            // Act
            await dataCleanup.DomainTopicCleanup(parameters);

            // Verify
            _ServiceLayer.DeleteDomainTopicCalled.Should().BeTrue();
            var expectedParameters = TestValues.GetDataCleanupParameters();

            expectedParameters.DomainTopicName = topicName;
            _ServiceLayer.LastParametersPassed.Should().BeEquivalentTo(expectedParameters);
        }
        public void ServiceLayer_PopulateDomainTopicQueue_QueueException_ShouldRethrow(Mock <IQueueManager> queueManagerMock, string exceptionMessage)
        {
            // Setup
            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                queueManagerMock.Object,
                _tableManager,
                _log);

            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();
            Func <Task>           act        = async() => await serviceLayer.PopulateDomainTopicQueue(parameters);

            // Act
            act.Should().Throw <RequestFailedException>().WithMessage(exceptionMessage);

            // Verify
            _log.Messages.Should().HaveCountGreaterOrEqualTo(2);
            _log.Messages[0].Message.Should().Be("Queuing domain topics for deletion.");
            _log.Messages[_log.Messages.Count - 1].Message.Should().Be("Exception encountered in PopulateDomainTopicQueue method.");
        }
        public void ServiceLayer_DeleteTables_DataLayerException_ShouldRethrow(Mock <ITableManager> tableManagerMock, string exceptionMessage)
        {
            // Setup
            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                tableManagerMock.Object,
                _log);

            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();
            Func <Task>           act        = async() => await serviceLayer.DeleteTables(parameters);

            // Act
            act.Should().Throw <RequestFailedException>().WithMessage(exceptionMessage);

            // Verify
            _log.Messages.Should().HaveCount(2);
            _log.Messages[0].Message.Should().Be("Table deletion starting.");
            _log.Messages[1].Message.Should().Be("Exception encountered in DeleteTables method.");
        }
        public async Task ServiceLayer_DeleteDomainTopic_ShouldWork()
        {
            // Setup
            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();

            parameters.DomainTopicName = "domaintopicname";

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                _tableManager,
                _log);

            // Act
            await serviceLayer.DeleteDomainTopic(parameters);

            // Verify
            _log.Messages.Should().HaveCount(2);
            _log.Messages[0].Message.Should().Be($"Deleting domain topic {parameters.DomainTopicName}");
            _log.Messages[1].Message.Should().Be($"Domain topic deletion completed! {parameters.DomainTopicName}");
        }
        public void ServiceLayer_PopulateDomainTopicQueue_EventGridException_ShouldRethrow(bool getClientThrowsException, bool getTopicsThrowsException)
        {
            // Setup
            _eventGridManager.ThrowExceptionOnGetClient = getClientThrowsException;
            _eventGridManager.ThrowExceptionOnGetTopics = getTopicsThrowsException;

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                _tableManager,
                _log);

            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();
            Func <Task>           act        = async() => await serviceLayer.PopulateDomainTopicQueue(parameters);

            // Act
            act.Should().Throw <RequestFailedException>().WithMessage(_eventGridManager.ExceptionMessage);

            // Verify
            _log.Messages.Should().HaveCount(2);
            _log.Messages[0].Message.Should().Be("Queuing domain topics for deletion.");
            _log.Messages[1].Message.Should().Be("Exception encountered in PopulateDomainTopicQueue method.");
        }
        public async Task ServiceLayer_PopulateDomainTopicQueue_ShouldWork()
        {
            // Setup
            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                _tableManager,
                _log);

            // Act
            await serviceLayer.PopulateDomainTopicQueue(parameters);

            // Verify
            _log.Messages.Should().HaveCount(6);
            _log.Messages[0].Message.Should().Be("Queuing domain topics for deletion.");
            _log.Messages[1].Message.Should().Be($"Found {_eventGridManager.ReturnDomainTopicNames[0][0]}");
            _log.Messages[2].Message.Should().Be($"Found {_eventGridManager.ReturnDomainTopicNames[0][1]}");
            _log.Messages[3].Message.Should().Be($"Found {_eventGridManager.ReturnDomainTopicNames[0][2]}");
            _log.Messages[4].Message.Should().Be($"{_eventGridManager.ReturnDomainTopicNames[0].Count} domain topics being added to queue for deletion.");
            _log.Messages[5].Message.Should().Be("Finished processing page of domain topics.");
        }
        public async Task ServiceLayer_PopulateDomainTopicQueue_MultiplePages_ShouldWork()
        {
            // Setup
            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();

            _eventGridManager.ReturnDomainTopicNames = new List <List <string> >()
            {
                new List <string>()
                {
                    "domaintopic1"
                },
                new List <string>()
                {
                    "domaintopic2"
                },
            };

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                _tableManager,
                _log);

            // Act
            await serviceLayer.PopulateDomainTopicQueue(parameters);

            // Verify
            _log.Messages.Should().HaveCount(5);
            _log.Messages[0].Message.Should().Be("Queuing domain topics for deletion.");
            _log.Messages[1].Message.Should().Be($"Found {_eventGridManager.ReturnDomainTopicNames[0][0]}");
            _log.Messages[2].Message.Should().Be($"{_eventGridManager.ReturnDomainTopicNames[0].Count} domain topics being added to queue for deletion.");
            _log.Messages[3].Message.Should().Be("Added next domain topic page to queue.");
            _log.Messages[4].Message.Should().Be("Finished processing page of domain topics.");

            _queueManager.SentMessages.Should().HaveCount(2);
            _queueManager.SentMessages[1].Should().Contain("\"domainTopicNextPage\":\"Nextpage\"");
        }
        public async Task ServiceLayer_DeleteTables_ShouldWork(List <CloudTable> tableList)
        {
            // Setup
            (Mock <ITableManager> tableManagerMock, List <CloudTable> deletedTableList) = GetMockTableManager(tableList);

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                _queueManager,
                tableManagerMock.Object,
                _log);

            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();

            // Act
            await serviceLayer.DeleteTables(parameters);

            // Verify
            tableManagerMock.Verify();
            deletedTableList.Should().HaveCount(tableList?.Count ?? 0);
            deletedTableList.Should().BeEquivalentTo(tableList ?? new List <CloudTable>());
            _log.Messages.Should().HaveCount(2);
            _log.Messages[0].Message.Should().Be("Table deletion starting.");
            _log.Messages[1].Message.Should().Be($"Table deletion completed! Removed {tableList?.Count ?? 0} tables.");
        }
        public async Task ServiceLayer_DeleteQueues_UsingMoq_ShouldWork(List <string> queueList)
        {
            // Setup
            (Mock <IQueueManager> queueManagerMock, List <string> deletedQueueList) = GetMockQueueManager(queueList);

            ServiceLayer serviceLayer = new ServiceLayer(
                _eventGridManager,
                queueManagerMock.Object,
                _tableManager,
                _log);

            DataCleanupParameters parameters = TestValues.GetDataCleanupParameters();

            // Act
            await serviceLayer.DeleteQueues(parameters);

            // Verify
            queueManagerMock.Verify();
            deletedQueueList.Count.Should().Be(queueList?.Count ?? 0);
            deletedQueueList.Should().BeEquivalentTo(queueList ?? new List <string>());
            _log.Messages.Should().HaveCount(2);
            _log.Messages[0].Message.Should().Be("Queue deletion starting.");
            _log.Messages[1].Message.Should().Be($"Queue deletion completed! Removed {queueList?.Count ?? 0} queues.");
        }