예제 #1
0
        public async Task AssertItemAsync_WhenExistsAndEqual()
        {
            AttributeValue key = GenerateKey();

            Dictionary <string, AttributeValue> item = new Dictionary <string, AttributeValue> {
                { "key", key },
                { "age", new AttributeValue {
                      N = "111"
                  } }
            };

            await m_db
            .PutItemAsync(m_tableName, item)
            .ConfigureAwait(continueOnCapturedContext: false);

            Assert.DoesNotThrowAsync(async() => {
                await AmazonDynamoDBAssert
                .AssertItemAsync(
                    m_db,
                    m_tableName,
                    key: new Dictionary <string, AttributeValue> {
                    { "key", key }
                },
                    expectedItem: item
                    )
                .ConfigureAwait(continueOnCapturedContext: false);
            });
        }
예제 #2
0
        public void AssertItemAsync_WhenDoesNotExist()
        {
            AttributeValue key = GenerateKey();

            Dictionary <string, AttributeValue> itemKey = new Dictionary <string, AttributeValue> {
                { "key", key }
            };

            Dictionary <string, AttributeValue> expectedItem = new Dictionary <string, AttributeValue> {
                { "key", key },
                { "age", new AttributeValue {
                      N = "555"
                  } }
            };

            var err = Assert.Throws <AssertionException>(() => {
                AmazonDynamoDBAssert
                .AssertItemAsync(
                    m_db,
                    m_tableName,
                    key: itemKey,
                    expectedItem: expectedItem
                    )
                .ConfigureAwait(continueOnCapturedContext: false)
                .GetAwaiter()
                .GetResult();
            });

            Assert.That(
                err.Message,
                Is.EqualTo("Item should exist.")
                );
        }
예제 #3
0
        public void AssertItemDoesNotExistAsync_WhenDoesNotExist()
        {
            AttributeValue key = GenerateKey();

            Dictionary <string, AttributeValue> itemKey = new Dictionary <string, AttributeValue> {
                { "key", key }
            };

            Assert.DoesNotThrowAsync(async() => {
                await AmazonDynamoDBAssert
                .AssertItemDoesNotExistAsync(
                    m_db,
                    m_tableName,
                    key: itemKey
                    )
                .ConfigureAwait(continueOnCapturedContext: false);
            });
        }
예제 #4
0
        public async Task AssertItemAsync_WhenExistsAndNotEqual()
        {
            AttributeValue key = GenerateKey();

            Dictionary <string, AttributeValue> item = new Dictionary <string, AttributeValue> {
                { "key", key },
                { "age", new AttributeValue {
                      N = "222"
                  } }
            };

            await m_db
            .PutItemAsync(m_tableName, item)
            .ConfigureAwait(continueOnCapturedContext: false);

            Dictionary <string, AttributeValue> itemKey = new Dictionary <string, AttributeValue> {
                { "key", key }
            };

            Dictionary <string, AttributeValue> expectedItem = new Dictionary <string, AttributeValue> {
                { "key", key },
                { "age", new AttributeValue {
                      N = "333"
                  } }
            };

            var err = Assert.Throws <AssertionException>(() => {
                AmazonDynamoDBAssert
                .AssertItemAsync(
                    m_db,
                    m_tableName,
                    key: itemKey,
                    expectedItem: expectedItem
                    )
                .ConfigureAwait(continueOnCapturedContext: false)
                .GetAwaiter()
                .GetResult();
            });

            Assert.That(
                err.Message,
                Does.StartWith("  M[age].N must be equal")
                );
        }
예제 #5
0
        public async Task AssertItemDoesNotExistAsync_WhenExists()
        {
            AttributeValue key = GenerateKey();

            await m_db
            .PutItemAsync(
                m_tableName,
                item : new Dictionary <string, AttributeValue> {
                { "key", key },
                { "age", new AttributeValue {
                      N = "111"
                  } }
            }
                )
            .ConfigureAwait(continueOnCapturedContext: false);

            Dictionary <string, AttributeValue> itemKey = new Dictionary <string, AttributeValue> {
                { "key", key }
            };

            var err = Assert.Throws <AssertionException>(() => {
                AmazonDynamoDBAssert
                .AssertItemDoesNotExistAsync(
                    m_db,
                    m_tableName,
                    key: itemKey
                    )
                .ConfigureAwait(continueOnCapturedContext: false)
                .GetAwaiter()
                .GetResult();
            });

            Assert.That(
                err.Message,
                Is.EqualTo("Item should not exist.")
                );
        }