예제 #1
0
파일: CosmosDb.cs 프로젝트: mtikoian/Beef
        public async Task SetUp()
        {
            var c1 = await ReplaceOrCreateContainerAsync(
                new AzCosmos.ContainerProperties
            {
                Id = "Persons1",
                PartitionKeyPath = "/_partitionKey",
                UniqueKeyPolicy  = new AzCosmos.UniqueKeyPolicy {
                    UniqueKeys = { new AzCosmos.UniqueKey {
                                       Paths =            { "/name"}
                                   } }
                }
            }, 400);

            await c1.ImportBatchAsync <CosmosDb, Person1>("Data.yaml");

            var c2 = await ReplaceOrCreateContainerAsync(
                new AzCosmos.ContainerProperties
            {
                Id = "Persons2",
                PartitionKeyPath = "/_partitionKey",
                UniqueKeyPolicy  = new AzCosmos.UniqueKeyPolicy {
                    UniqueKeys = { new AzCosmos.UniqueKey {
                                       Paths =            { "/name"}
                                   } }
                }
            }, 400);

            await c2.ImportBatchAsync <CosmosDb, Person2>("Data.yaml");

            var c3 = await ReplaceOrCreateContainerAsync(
                new AzCosmos.ContainerProperties
            {
                Id = "Persons3",
                PartitionKeyPath = "/_partitionKey",
                UniqueKeyPolicy  = new AzCosmos.UniqueKeyPolicy {
                    UniqueKeys = { new AzCosmos.UniqueKey {
                                       Paths =            { "/type","/value/name" }
                                   } }
                }
            }, 400);

            await c3.ImportValueBatchAsync <CosmosDb, Person3>("Data.yaml");

            // Add other random "type" to Person3.
            var c = new CosmosDbValueContainer <Person1, Person1>(this, CosmosDbMapper.CreateAuto <Person1, Person1>().CreateArgs("Persons3"));
            await c.Container.ImportValueBatchAsync(new Person1[] { new Person1 {
                                                                        Id = 100.ToGuid(), Name = "Greg"
                                                                    } });

            // Load the reference data.
            var rd = await ReplaceOrCreateContainerAsync(
                new AzCosmos.ContainerProperties
            {
                Id = "RefData",
                PartitionKeyPath = "/_partitionKey",
                UniqueKeyPolicy  = new AzCosmos.UniqueKeyPolicy {
                    UniqueKeys = { new AzCosmos.UniqueKey {
                                       Paths =            { "/type","/value/code" }
                                   } }
                }
            }, 400);

            await rd.ImportValueRefDataBatchAsync <ReferenceDataProvider, ReferenceDataProvider>("RefData.yaml");
        }
예제 #2
0
파일: CosmosDb.cs 프로젝트: mtikoian/Beef
 public CosmosDb() : base(new AzCosmos.CosmosClient("https://localhost:8081", "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="), "Beef.UnitTest", true)
 {
     Persons1 = new CosmosDbContainer <Person1, Person1>(this, CosmosDbMapper.CreateAuto <Person1, Person1>().HasProperty(s => s.Id, d => d.Id, p => p.SetUniqueKey()).CreateArgs("Persons1"));
     Persons2 = new CosmosDbContainer <Person2, Person2>(this, CosmosDbMapper.CreateAuto <Person2, Person2>().HasProperty(s => s.Id, d => d.Id, p => p.SetUniqueKey()).CreateArgs("Persons2"));
     Persons3 = new CosmosDbValueContainer <Person3, Person3>(this, CosmosDbMapper.CreateAuto <Person3, Person3>().HasProperty(s => s.Id, d => d.Id, p => p.SetUniqueKey()).CreateArgs("Persons3"));
 }