Question 58 of 179 from exam AZ-204: Developing Solutions for Microsoft Azure

Question 58 of 179 from exam AZ-204: Developing Solutions for Microsoft Azure

Question

HOTSPOT - You are developing an Azure-hosted e-commerce web application.

The application will use Azure Cosmos DB to store sales orders.

You are using the latest SDK to manage the sales orders in the database.

You create a new Azure Cosmos DB instance.

You include a valid endpoint and valid authorization key to an appSettings.json file in the code project.

You are evaluating the following application code: (Line number are included for reference only.)

o1
02
03
04
0s
06
07
08
og
10
1
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

using System;
using System. Threading. Tasks;
using Microsoft Azure.Cosmos;
using Microsoft .Extensions.Configuration;
using Newtonsoft.Json;
namespace SalesOrders
{
public class Salesorder

internal class ManageSalesOrders

{
private static async Task GenerateSalesOrders()

{

IConfigurationRoot configuration = new ConfigurationBuilder() .AddJsonFile (“appSettings. json”) .Build();

string endpoint = configuration[“EndPointUrl”];

string authKey = configuration["Authorizationkey”]

using CosmosClient client = new CosmosClient (endpoint, authKey);

Database database = null;

using (await client.GetDatabase ("SalesOrders”) .DeleteStreamAsync()) { }

database = await client.CreateDatabaseI£NotExistsAsync("SalesOrders”)

Container containerl = await database.CreateContainerAsync(id: “Container1”, partitionKeyPath:

Container container? = await database.CreateContainerAsync(id: “Container2”, partitionKeyPath:

SalesOrder salesOrderl = new SalesOrder() { AccountNumber = "123456" };

await containerl.createItemAsync(salesOrderl, new Partitionkey(salesOrder1.AccountNumber)) ;

SalesOrder salesOrder2 = new SalesOrder() { AccountNumber = “654321” };

await containerl.CreateItemAsync(salesOrder2, new PartitionKey(salesOrder2.AccountNumber) ) ;

SalesOrder salesOrder3 = new SalesOrder() { AccountNumber = “109876” };

await container2.CreateItemAsync(salesOrder3, new Partitionkey(salesOrder3.AccountNumber) ) ;
await database.CreateUserAsync("User1”

User userl = database.GetUser (“User”);
await userl.ReadAsync();

“/AccountNumber”) >
“/AccountNumber”) ;

For each of the following statements, select Yes if the statement is true.

Otherwise, select No.

NOTE: Each correct selection is worth one point.

Hot Area:

Answer Area

Statements Yes

A database named SalesOrders is created. The database will ©
include two containers.

Container1 will contain two items. [e)

Container2 will contain one item. fe)

No

Explanations

Answer Area

Statements Yes

A database named SalesOrders is created. The database will |)
include two containers.

Container1 will contain two items. |o |

Container2 will contain one item. iro)

No

Box 1: Yes - The createDatabaseIfNotExistsAsync method checks if a database exists, and if it doesn't, create it.

The Database.CreateContainerAsync method creates a container as an asynchronous operation in the Azure Cosmos service.

Box 2: Yes - The CosmosContainer.CreateItemAsync method creates an item as an asynchronous operation in the Azure Cosmos service.

Box 3: Yes - Reference: https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.cosmosclient.createdatabaseifnotexistsasync https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.cosmos.database.createcontainerasync https://docs.microsoft.com/en-us/dotnet/api/azure.cosmos.cosmoscontainer.createitemasync.