Exemplo n.º 1
0
        public async Task Success()
        {
            // 前準備

            // 実行
            var logic = GetLogic();
            await logic.DeleteMainAsync(_ownerId, _scoreId);

            // 検証

            var req = new TransactWriteItemsRequest()
            {
                ReturnConsumedCapacity = ReturnConsumedCapacity.TOTAL,
                TransactItems          = new List <TransactWriteItem>()
                {
                    new TransactWriteItem()
                    {
                        Delete = new Delete()
                        {
                            Key = new Dictionary <string, AttributeValue>()
                            {
                                ["o"] = new AttributeValue("sc:01234567890123456789aa"),
                                ["s"] = new AttributeValue("01234567890123456789bb")
                            },
                            ExpressionAttributeNames = new Dictionary <string, string>()
                            {
                                ["#score"] = "s"
                            },
                            ConditionExpression = "attribute_exists(#score)",
                            TableName           = _tableName
                        }
                    },
                    new TransactWriteItem()
                    {
                        Update = new Update()
                        {
                            Key = new Dictionary <string, AttributeValue>()
                            {
                                ["o"] = new AttributeValue("sc:01234567890123456789aa"),
                                ["s"] = new AttributeValue("summary")
                            },
                            ExpressionAttributeNames = new Dictionary <string, string>()
                            {
                                ["#sc"]   = "sc",
                                ["#lock"] = "l"
                            },
                            ExpressionAttributeValues = new Dictionary <string, AttributeValue>()
                            {
                                [":increment"] = new AttributeValue()
                                {
                                    N = "-1"
                                },
                                [":newL"] = new AttributeValue("01234567890123456789cc"),
                            },
                            TableName = _tableName
                        }
                    }
                }
            };
            var compare = new LambdaEqualityCompare <TransactWriteItemsRequest>((x, y) =>
            {
                if (x.ReturnConsumedCapacity != y.ReturnConsumedCapacity)
                {
                    return(false);
                }
                throw new NotImplementedException();
                return(true);
            });

            AmazonDynamoDb.Verify(x => x.TransactWriteItemsAsync(It.Is(req, compare), default), Times.Once);
        }
Exemplo n.º 2
0
        public static T Is <T>(T value, Func <T, T, bool> lambda)
        {
            var compare = new LambdaEqualityCompare <T>(lambda);

            return(It.Is(value, compare));
        }