示例#1
0
        public async Task GetConfig_Integration_ReturnsExpectedResult_Test()
        {
            // Arrange
            var key          = "GetConfigIntegrationTest";
            var expectedData = "IntegrationTestDataContent";
            var cloudTable   = GetActualCloudTable();
            var options      = Options.Create <AzureStorageAccountOptions>(GetActualAzureStorageOptions());

            var setting = new FeedProcessorConfigItem <string>
            {
                PartitionKey = options.Value.TableAccessOptions.PartitionKey,
                RowKey       = key,
                Data         = expectedData
            };

            var setOperation = TableOperation.InsertOrReplace(setting);
            await cloudTable.ExecuteAsync(setOperation);

            // Act
            var reader = new AzureTableStorageConfigReader(cloudTable, options);
            var actual = await reader.GetConfigAsync <string>(key);

            // Assert
            actual.Should().Be(expectedData);

            // Cleanup
            var removeOperation = TableOperation.Delete(setting);
            await cloudTable.ExecuteAsync(removeOperation);
        }
示例#2
0
        public async Task GetConfigAsync_ReturnsExpectedResult_Test()
        {
            // Arrange
            string key      = "getConfigTestKey";
            string expected = "SomeExpectedValue";

            var result = new TableResult()
            {
                Result = new FeedProcessorConfigItem <string>()
                {
                    Data = expected
                }
            };

            TableOperation op = TableOperation.Retrieve(_mockConfig.TableAccessOptions.PartitionKey, key);

            CloudTable table = GetMockCloudTable();

            Mock.Get(table)
            .Setup(p => p.ExecuteAsync(It.IsAny <TableOperation>()))
            .ReturnsAsync(result);

            AzureTableStorageConfigReader reader = GetAzureTableStorageConfigReader(table);

            // Act
            var actual = await reader.GetConfigAsync <string>(key);

            // Assert
            actual.Should().Be(expected, "Because with a specified key expected data can be retrieved.");
        }
示例#3
0
        public void GetConfigAsync_WhenKeyNotFound_ThrowsException_Test()
        {
            // Arrange
            string      key    = "getConfigTestKey";
            TableResult result = null;

            CloudTable table = GetMockCloudTable();

            Mock.Get(table)
            .Setup(p => p.ExecuteAsync(It.IsAny <TableOperation>()))
            .ReturnsAsync(result);

            AzureTableStorageConfigReader reader = GetAzureTableStorageConfigReader(table);

            // Act
            Func <Task <string> > act = async() => await reader.GetConfigAsync <string>(key);

            // Assert
            act.Should().Throw <KeyNotFoundException>("Because when the key is missing, an exception should be raised.");
        }