Esempio n. 1
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);
        }
        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_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_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. 5
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());
     });
 }
        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. 8
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");
        }