public void ValidateUriGenerationForResources()
        {
            string databaseId = "db1234";
            string crId       = "cr42";
            string spId       = "sp9001";
            string trId       = "tr9002";
            string udfId      = "udf9003";

            CosmosClient       mockClient = MockDocumentClient.CreateMockCosmosClient();
            CosmosDatabaseCore db         = new CosmosDatabaseCore(mockClient, databaseId);

            Assert.AreEqual(db.LinkUri.OriginalString, "/dbs/" + databaseId);

            CosmosContainerCore container = new CosmosContainerCore(db, crId);

            Assert.AreEqual(container.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId);

            CosmosStoredProcedureCore sp = new CosmosStoredProcedureCore(container, spId);

            Assert.AreEqual(sp.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/sprocs/" + spId);

            CosmosTrigger tr = new CosmosTrigger(container, trId);

            Assert.AreEqual(tr.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/triggers/" + trId);

            CosmosUserDefinedFunction udf = new CosmosUserDefinedFunction(container, udfId);

            Assert.AreEqual(udf.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/udfs/" + udfId);
        }
        public async Task DatabaseContractTest()
        {
            DatabaseResponse response = await this.CreateDatabaseHelper();

            Assert.IsNotNull(response);
            Assert.IsTrue(response.RequestCharge > 0);
            Assert.IsNotNull(response.Headers);
            Assert.IsNotNull(response.Headers.ActivityId);

            CosmosDatabaseSettings databaseSettings = response.Resource;

            Assert.IsNotNull(databaseSettings.Id);
            Assert.IsNotNull(databaseSettings.ResourceId);
            Assert.IsNotNull(databaseSettings.ETag);
            Assert.IsTrue(databaseSettings.LastModified.HasValue);
            Assert.IsTrue(databaseSettings.LastModified.Value > new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc), databaseSettings.LastModified.Value.ToString());

            CosmosDatabaseCore databaseCore = response.Database as CosmosDatabaseCore;

            Assert.IsNotNull(databaseCore);
            Assert.IsNotNull(databaseCore.LinkUri);
            Assert.IsFalse(databaseCore.LinkUri.ToString().StartsWith("/"));

            response = await response.Database.DeleteAsync(cancellationToken : this.cancellationToken);

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
        public void ValidateUriGenerationForResources()
        {
            string databaseId = "db1234";
            string crId       = "cr42";

            CosmosClientContext context = new CosmosClientContextCore(
                client: null,
                clientOptions: null,
                userJsonSerializer: null,
                defaultJsonSerializer: null,
                cosmosResponseFactory: null,
                requestHandler: null,
                documentClient: null,
                documentQueryClient: new Mock <IDocumentQueryClient>().Object);

            CosmosDatabaseCore db = new CosmosDatabaseCore(context, databaseId);

            Assert.AreEqual(db.LinkUri.OriginalString, "/dbs/" + databaseId);

            CosmosContainerCore container = new CosmosContainerCore(context, db, crId);

            Assert.AreEqual(container.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId);
        }
Exemplo n.º 4
0
        public void ValidateUriGenerationForResources()
        {
            string databaseId = "db1234";
            string crId       = "cr42";
            string spId       = "sp9001";
            string trId       = "tr9002";
            string udfId      = "udf9003";

            CosmosClientContext context = new CosmosClientContextCore(
                client: null,
                clientConfiguration: null,
                cosmosJsonSerializer: null,
                cosmosResponseFactory: null,
                requestHandler: null,
                documentClient: null,
                documentQueryClient: new Mock <IDocumentQueryClient>().Object);

            CosmosDatabaseCore db = new CosmosDatabaseCore(context, databaseId);

            Assert.AreEqual(db.LinkUri.OriginalString, "/dbs/" + databaseId);

            CosmosContainerCore container = new CosmosContainerCore(context, db, crId);

            Assert.AreEqual(container.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId);

            CosmosStoredProcedureCore sp = new CosmosStoredProcedureCore(context, container, spId);

            Assert.AreEqual(sp.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/sprocs/" + spId);

            CosmosTrigger tr = new CosmosTrigger(context, container, trId);

            Assert.AreEqual(tr.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/triggers/" + trId);

            CosmosUserDefinedFunction udf = new CosmosUserDefinedFunction(context, container, udfId);

            Assert.AreEqual(udf.LinkUri.OriginalString, "/dbs/" + databaseId + "/colls/" + crId + "/udfs/" + udfId);
        }