public void When_Creating_A_Table_With_Custom_Properties()
        {
            //arrange
            var tableRequestFactory = new DynamoDbTableFactory();

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput
                (
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>
            {
                {
                    "GlobalSecondaryIndex", new ProvisionedThroughput {
                        ReadCapacityUnits = 10, WriteCapacityUnits = 10
                    }
                }
            }
                )
                );

            //assert
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "Id" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "UUID" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "UniqueIdentifier" && attr.AttributeType == ScalarAttributeType.S);
        }
        public void When_Creating_A_Table_With_Admin_Attributes()
        {
            //arrange
            var tableRequestFactory = new DynamoDbTableFactory();

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput(),
                billingMode: new BillingMode(BillingMode.PAY_PER_REQUEST),
                sseSpecification: new SSESpecification {
                Enabled = false
            },
                streamSpecification: new StreamSpecification {
                StreamEnabled = false
            },
                tags: new List <Tag> {
                new Tag {
                    Key = "beta", Value = "True"
                }, new Tag {
                    Key = "paramore", Value = "Brighter"
                }
            });

            //assert
            Assert.Equal(BillingMode.PAY_PER_REQUEST, tableRequest.BillingMode);
            Assert.False(tableRequest.SSESpecification.Enabled);
            Assert.False(tableRequest.SSESpecification.Enabled);
            Assert.Contains(tableRequest.Tags, tag => tag.Key == "beta" && tag.Value == "True");
            Assert.Contains(tableRequest.Tags, tag => tag.Key == "paramore" && tag.Value == "Brighter");
        }
        public void When_Creating_A_Table_With_Provisioned_Throughput()
        {
            //arrange
            var tableRequestFactory  = new DynamoDbTableFactory();
            var provisonedThroughput = new DynamoDbCreateProvisionedThroughput
                                       (
                table: new ProvisionedThroughput()
            {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                gsiThroughputs: new Dictionary <string, ProvisionedThroughput>()
            {
                { "GlobalSecondaryIndex", new ProvisionedThroughput(readCapacityUnits: 11, writeCapacityUnits: 11) }
            }
                                       );

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(provisonedThroughput);

            //assert
            Assert.Equal(10, tableRequest.ProvisionedThroughput.ReadCapacityUnits);
            Assert.Equal(10, tableRequest.ProvisionedThroughput.WriteCapacityUnits);
            Assert.Equal(11, tableRequest.GlobalSecondaryIndexes.First(gsi => gsi.IndexName == "GlobalSecondaryIndex").ProvisionedThroughput.ReadCapacityUnits);
            Assert.Equal(11, tableRequest.GlobalSecondaryIndexes.First(gsi => gsi.IndexName == "GlobalSecondaryIndex").ProvisionedThroughput.WriteCapacityUnits);
        }
Esempio n. 4
0
        public void When_Building_A_Table_Omit_Non_Key_Schema_Attributes()
        {
            var tableRequestFactory = new DynamoDbTableFactory();
            var builder             = new DynamoDbTableBuilder(CreateClient());

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput
                (
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>
            {
                {
                    "GlobalSecondaryIndex", new ProvisionedThroughput {
                        ReadCapacityUnits = 10, WriteCapacityUnits = 10
                    }
                }
            }
                )
                );

            var modifiedTableRequest = builder.RemoveNonSchemaAttributes(tableRequest);

            //assert
            Assert.DoesNotContain(modifiedTableRequest.AttributeDefinitions, attr => attr.AttributeName == "StringProperty" && attr.AttributeType == ScalarAttributeType.S);
            Assert.DoesNotContain(modifiedTableRequest.AttributeDefinitions, attr => attr.AttributeName == "NumberProperty" && attr.AttributeType == ScalarAttributeType.N);
            Assert.DoesNotContain(modifiedTableRequest.AttributeDefinitions, attr => attr.AttributeName == "ByteArrayProperty" && attr.AttributeType == ScalarAttributeType.B);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "Id" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "RangeKey" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "GlobalSecondaryId" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "GlobalSecondaryRangeKey" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "LocalSecondaryRangeKey" && attr.AttributeType == ScalarAttributeType.S);
        }
        //[Fact]
        public void Create()
        {
            var request = new CreateTableRequest
            {
                TableName = "lakeland-mi-pueblo-receipts",
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "id",
                        KeyType       = "HASH"
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "id",
                        AttributeType = "S"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 5,
                    WriteCapacityUnits = 1
                }
            };
            var tableFactory = new DynamoDbTableFactory(
                new AmazonDynamoDBClient(Factory.CreateCredentialsFromProfile(), Factory.HomeRegion));

            tableFactory.CreateTable(request, false);
        }
Esempio n. 6
0
        protected DynamoDBOutboxBaseTest()
        {
            Client = CreateClient();
            _dynamoDbTableBuilder = new DynamoDbTableBuilder(Client);
            //create a table request
            var createTableRequest = new DynamoDbTableFactory().GenerateCreateTableMapper <MessageItem>(
                new DynamoDbCreateProvisionedThroughput(
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>
            {
                { "Outstanding", new ProvisionedThroughput {
                      ReadCapacityUnits = 10, WriteCapacityUnits = 10
                  } },
                { "Delivered", new ProvisionedThroughput {
                      ReadCapacityUnits = 10, WriteCapacityUnits = 10
                  } }
            }
                    ));

            TableName = createTableRequest.TableName;
            (bool exist, IEnumerable <string> tables)hasTables = _dynamoDbTableBuilder.HasTables(new string[] { TableName }).Result;
            if (!hasTables.exist)
            {
                var buildTable = _dynamoDbTableBuilder.Build(createTableRequest).Result;
                _dynamoDbTableBuilder.EnsureTablesReady(new[] { createTableRequest.TableName }, TableStatus.ACTIVE).Wait();
            }
        }
Esempio n. 7
0
        public void When_Creating_A_Table_With_Mulitple_GSI_Inxdexes_Per_Field()
        {
            //arrange
            var tableRequestFactory = new DynamoDbTableFactory();

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput
                (
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>
            {
                {
                    "GlobalSecondaryIndex", new ProvisionedThroughput {
                        ReadCapacityUnits = 10, WriteCapacityUnits = 10
                    }
                }
            }
                )
                );

            //assert
            Assert.Equal("MyEntity", tableRequest.TableName);
            Assert.Contains(tableRequest.GlobalSecondaryIndexes,
                            gsi => gsi.IndexName == "GlobalSecondaryIndex" &&
                            gsi.KeySchema.Any(kse => kse.AttributeName == "GlobalSecondaryId" && kse.KeyType == KeyType.HASH) &&
                            gsi.KeySchema.Any(kse => kse.AttributeName == "GlobalSecondaryRangeKey" && kse.KeyType == KeyType.RANGE));
            Assert.Contains(tableRequest.GlobalSecondaryIndexes,
                            gsi => gsi.IndexName == "AnotherGlobalSecondaryIndex" &&
                            gsi.KeySchema.Any(kse => kse.AttributeName == "GlobalSecondaryId" && kse.KeyType == KeyType.HASH) &&
                            gsi.KeySchema.Any(kse => kse.AttributeName == "GlobalSecondaryRangeKey" && kse.KeyType == KeyType.RANGE));
        }
 public void When_Creating_A_Table_From_A_Class_Missing_A_Hash_Key()
 {
     //arrange, act, assert
     Assert.Throws <InvalidOperationException>(() =>
     {
         var tableRequestFactory = new DynamoDbTableFactory();
         tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(new DynamoDbCreateProvisionedThroughput());
     });
 }
Esempio n. 9
0
        //[Fact]
        public void A_Create()
        {
            var request = new CreateTableRequest
            {
                TableName = new SpotReservation().GetTable(),
                KeySchema = new List <KeySchemaElement>
                {
                    new KeySchemaElement
                    {
                        AttributeName = "rentalDate",
                        KeyType       = "HASH"
                    },
                    new KeySchemaElement
                    {
                        AttributeName = "spotId",
                        KeyType       = "RANGE"
                    }
                },
                AttributeDefinitions = new List <AttributeDefinition>
                {
                    new AttributeDefinition
                    {
                        AttributeName = "spotId",
                        AttributeType = "S"
                    },
                    new AttributeDefinition
                    {
                        AttributeName = "rentalDate",
                        AttributeType = "S"
                    }
                },
                ProvisionedThroughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = 5,
                    WriteCapacityUnits = 1
                }
            };
            var tableFactory = new DynamoDbTableFactory(
                new AmazonDynamoDBClient(Factory.CreateCredentialsFromProfile(), Factory.HomeRegion));

            tableFactory.CreateTable(request, false);
        }
        public void When_Creating_A_Table_With_Projections()
        {
            var tableRequestFactory = new DynamoDbTableFactory();
            var gsiProjection       = new DynamoGSIProjections
                                      (
                projections: new Dictionary <string, Projection>
            {
                { "GlobalSecondaryIndex", new Projection {
                      ProjectionType = ProjectionType.KEYS_ONLY, NonKeyAttributes = new List <string> {
                          "Id", "Version"
                      }
                  } }
            }
                                      );

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput(
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>
            {
                {
                    "GlobalSecondaryIndex", new ProvisionedThroughput {
                        ReadCapacityUnits = 10, WriteCapacityUnits = 10
                    }
                }
            }
                    ),
                gsiProjection
                );

            //assert
            Assert.Equal(ProjectionType.KEYS_ONLY, tableRequest.GlobalSecondaryIndexes.First(gsi => gsi.IndexName == "GlobalSecondaryIndex").Projection.ProjectionType);
            Assert.Equal(
                new List <string> {
                "Id", "Version"
            },
                tableRequest.GlobalSecondaryIndexes.First(gsi => gsi.IndexName == "GlobalSecondaryIndex").Projection.NonKeyAttributes);
        }
Esempio n. 11
0
        public void When_Creating_A_Table_From_An_Attributed_Class()
        {
            //arrange
            var tableRequestFactory = new DynamoDbTableFactory();

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput
                (
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>
            {
                {
                    "GlobalSecondaryIndex", new ProvisionedThroughput {
                        ReadCapacityUnits = 10, WriteCapacityUnits = 10
                    }
                }
            }
                )
                );

            //assert
            Assert.Equal("MyEntity", tableRequest.TableName);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "StringProperty" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "NumberProperty" && attr.AttributeType == ScalarAttributeType.N);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "ByteArrayProperty" && attr.AttributeType == ScalarAttributeType.B);
            Assert.DoesNotContain(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "UnmarkedProperty");
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "MappedName" && attr.AttributeType == ScalarAttributeType.S);
            Assert.DoesNotContain(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "IgnoredProperty");
            Assert.Contains(tableRequest.KeySchema, kse => kse.AttributeName == "Id" && kse.KeyType == KeyType.HASH);
            Assert.Contains(tableRequest.GlobalSecondaryIndexes,
                            gsi => gsi.IndexName == "GlobalSecondaryIndex" &&
                            gsi.KeySchema.Any(kse => kse.AttributeName == "GlobalSecondaryId" && kse.KeyType == KeyType.HASH) &&
                            gsi.KeySchema.Any(kse => kse.AttributeName == "GlobalSecondaryRangeKey" && kse.KeyType == KeyType.RANGE));
            Assert.Contains(tableRequest.LocalSecondaryIndexes, lsi => lsi.IndexName == "LocalSecondaryIndex" &&
                            lsi.KeySchema.Any(kse => kse.AttributeName == "LocalSecondaryRangeKey" && kse.KeyType == KeyType.RANGE));
        }
        public void When_Creating_A_Table_With_Collection_Properties()
        {
            //arrange
            var tableRequestFactory = new DynamoDbTableFactory();

            //act
            CreateTableRequest tableRequest = tableRequestFactory.GenerateCreateTableMapper <DynamoDbEntity>(
                new DynamoDbCreateProvisionedThroughput
                (
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            }
                )
                );

            //assert
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "Id" && attr.AttributeType == ScalarAttributeType.S);
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "StringArray" && attr.AttributeType.Value == "SS");
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "IntArray" && attr.AttributeType.Value == "NS");
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "DoubleArray" && attr.AttributeType.Value == "NS");
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "GenericList" && attr.AttributeType.Value == "L");
            Assert.Contains(tableRequest.AttributeDefinitions, attr => attr.AttributeName == "GenericMap" && attr.AttributeType.Value == "M");
        }
Esempio n. 13
0
        protected DynamoDBInboxBaseTest()
        {
            //required by AWS 2.2
            Environment.SetEnvironmentVariable("AWS_ENABLE_ENDPOINT_DISCOVERY", "false");

            Client = CreateClient();
            _dynamoDbTableBuilder = new DynamoDbTableBuilder(Client);
            //create a table request
            var createTableRequest = new DynamoDbTableFactory().GenerateCreateTableMapper <CommandItem <MyCommand> >(
                new DynamoDbCreateProvisionedThroughput(
                    new ProvisionedThroughput {
                ReadCapacityUnits = 10, WriteCapacityUnits = 10
            },
                    new Dictionary <string, ProvisionedThroughput>()
                    ));

            TableName = createTableRequest.TableName;
            (bool exist, IEnumerable <string> tables)hasTables = _dynamoDbTableBuilder.HasTables(new string[] { TableName }).Result;
            if (!hasTables.exist)
            {
                var buildTable = _dynamoDbTableBuilder.Build(createTableRequest).Result;
                _dynamoDbTableBuilder.EnsureTablesReady(new[] { createTableRequest.TableName }, TableStatus.ACTIVE).Wait();
            }
        }