Ejemplo n.º 1
0
        public async Task StorageManagerShouldAddRuleToRulesCollection()
        {
            // Arrange

            string tableName = "MyTable";

            var rule = new RuleEntity(
                "myEventType",
                1)
            {
                RuleId          = 1,
                RuleName        = "Rule001",
                MatchExpression = "myExpresion",
                Rank            = 1,
                Enabled         = true
            };

            var mockTable = new Mock <ITable>();

            mockTable.Setup(t => t.CreateIfNotExistsAsync())
            .ReturnsAsync(true);
            mockTable.Setup(t => t.ExecuteAsync(It.IsAny <TableOperation>()))
            .Returns(Task.FromResult(default(TableResult)));

            var mockCloudTable = new Mock <CloudTable>();

            var mockTableClient = new Mock <ITableClient>();

            mockTableClient.Setup(x => x.GetTableReference(tableName))
            .Returns(Mock.Of <Table>());

            // Act

            var storageManager = new StorageManager <RuleEntity>(mockTableClient.Object, mockTable.Object);

            var result = await storageManager.AddOrUpdateAsync(rule);

            // Assert

            Assert.IsNull(result);
        }