-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cb7779
commit 351eeae
Showing
8 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ obj | |
.suo | ||
.user | ||
.vs | ||
appsettings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="..\..\..\..\.nuget\packages\microsoft.azure.cosmos\3.19.0\contentFiles\any\netstandard2.0\ThirdPartyNotice.txt" Link="ThirdPartyNotice.txt"> | ||
<Private>False</Private> | ||
<NuGetPackageVersion>3.19.0</NuGetPackageVersion> | ||
<NuGetItemType>Content</NuGetItemType> | ||
<NuGetPackageId>Microsoft.Azure.Cosmos</NuGetPackageId> | ||
<Pack>false</Pack> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.19.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,42 @@ | ||
using System; | ||
using Microsoft.Azure.Cosmos; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace DataLayer | ||
{ | ||
/// <summary> | ||
/// A Data Access Layer (DAL) object for People. | ||
/// </summary> | ||
public class PeopleData | ||
{ | ||
private readonly Container _container; | ||
private string ContainerId { get; set; } | ||
|
||
public PeopleData(CosmosClient client, string databaseId, string containerId = "People") | ||
{ | ||
ContainerId = containerId; | ||
_container = client.GetContainer(databaseId, containerId); | ||
} | ||
|
||
/// <summary> | ||
/// Gets all people. | ||
/// </summary> | ||
/// <returns><see cref="IEnumerable{Person}"/></returns> | ||
public async Task<IEnumerable<Person>> GetAll() | ||
{ | ||
// Define a Query | ||
var query = new QueryDefinition($"SELECT * FROM {ContainerId}"); | ||
|
||
// Get an Iterator | ||
var iterator = _container.GetItemQueryIterator<Person>(query); | ||
|
||
// Get the first page of results | ||
var response = await iterator.ReadNextAsync(); | ||
|
||
//TODO: Paging | ||
|
||
return response.Resource; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DataLayer | ||
{ | ||
/// <summary> | ||
/// A Person Model | ||
/// </summary> | ||
/// <remarks>AKA DTO (data transfer object), POCO (plain old c# object)</remarks> | ||
public class Person | ||
{ | ||
//TODO: Properties | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
using System.IO; | ||
|
||
namespace DataLayerTests | ||
{ | ||
/// <summary> | ||
/// Test helper base class | ||
/// </summary> | ||
public abstract class CosmosTest | ||
{ | ||
// load configuration from appsettings.json file | ||
protected static readonly IConfiguration _config = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false) | ||
.Build(); | ||
|
||
// Constants for App Settings keys | ||
protected const string CosmosDataConnectionStringKey = "Cosmos_ConnectionString"; | ||
protected const string CosmosDataDatabaseIdKey = "Cosmos_DatabaseId"; | ||
|
||
public CosmosTest() | ||
{ | ||
// Ensure app settings exist | ||
if (string.IsNullOrEmpty(_config[CosmosDataConnectionStringKey])) | ||
throw new InvalidOperationException($"{CosmosDataConnectionStringKey} must be set"); | ||
if (string.IsNullOrEmpty(_config[CosmosDataDatabaseIdKey])) | ||
throw new InvalidOperationException($"{CosmosDataDatabaseIdKey} must be set"); } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug" | ||
} | ||
}, | ||
"CosmosData_ConnectionString": "", | ||
"CosmosData_DatabaseId": "" | ||
} |