Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module resources './resources.bicep' = {

output AZSQL_CONNECTION_STRING string = resources.outputs.AZSQL_CONNECTIONSTRING
output COSMOS_CONNECTION_STRING string = resources.outputs.COSMOS_CONNECTIONSTRING
output MONGO_CONNECTION_STRING string = resources.outputs.MONGO_CONNECTIONSTRING
output MONGOACI_CONNECTION_STRING string = resources.outputs.MONGOACI_CONNECTIONSTRING
output MYSQL_CONNECTION_STRING string = resources.outputs.MYSQL_CONNECTIONSTRING
output PGSQL_CONNECTION_STRING string = resources.outputs.PGSQL_CONNECTIONSTRING
output SERVICE_ENDPOINT string = resources.outputs.SERVICE_ENDPOINT
74 changes: 74 additions & 0 deletions infra/modules/aci-mongodb.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
targetScope = 'resourceGroup'

@secure()
@description('The password for the administrator')
param administratorPassword string

@description('The username for the administrator')
param administratorUsername string = 'tester'

@description('The image URI to use.')
param image string = 'mongo'

@minLength(1)
@description('Primary location for all resources')
param location string = resourceGroup().location

@description('The port # to expose in the Docker image')
param port int = 27017

@description('The name of the Mongo Server to create.')
param serverName string

@description('The list of tags to apply to all resources.')
param tags object = {}

/*********************************************************************************/

resource containerGroup 'Microsoft.ContainerInstance/containerGroups@2023-05-01' = {
name: toLower(serverName)
location: location
tags: tags
properties: {
containers: [
{
name: toLower(serverName)
properties: {
image: image
environmentVariables: [
{ name: 'MONGO_INITDB_ROOT_USERNAME', value: administratorUsername }
{ name: 'MONGO_INITDB_ROOT_PASSWORD', secureValue: administratorPassword }
]
ports: [
{
port: port
protocol: 'TCP'
}
]
resources: {
requests: {
cpu: 2
memoryInGB: 2
}
}
}
}
]
osType: 'Linux'
restartPolicy: 'Always'
ipAddress: {
type: 'Public'
ports: [
{
port: port
protocol: 'TCP'
}
]
}
}
}

/*********************************************************************************/

#disable-next-line outputs-should-not-contain-secrets
output MONGO_CONNECTIONSTRING string = 'mongodb://${administratorUsername}:${administratorPassword}@${containerGroup.properties.ipAddress.ip}:27017/'
182 changes: 182 additions & 0 deletions infra/modules/cosmos-mongodb.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
targetScope = 'resourceGroup'

@minLength(1)
@description('The name of the test container to create')
param containerName string = 'Movies'

@minLength(1)
@description('The name of the test database to create')
param databaseName string = 'unittests'

@minLength(1)
@description('Primary location for all resources')
param location string = resourceGroup().location

@allowed(['3.2', '3.6', '4.0', '4.2'])
@description('Specifies the MongoDB server version to use.')
param mongoVersion string = '4.2'

@description('The name of the Mongo Server to create.')
param serverName string

@description('The list of tags to apply to all resources.')
param tags object = {}

/*********************************************************************************/

var compositeIndices = [
[
{ path: '/BestPictureWinner', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/BestPictureWinner', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Duration', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Duration', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Rating', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Rating', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/ReleaseDate', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/ReleaseDate', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Title', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Title', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/UpdatedAt', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/UpdatedAt', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'ascending' }
{ path: '/Title', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'descending' }
{ path: '/Title', order: 'ascending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'ascending' }
{ path: '/Title', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
[
{ path: '/Year', order: 'descending' }
{ path: '/Title', order: 'descending' }
{ path: '/id', order: 'ascending' }
]
]

/*********************************************************************************/

resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
name: toLower(serverName)
location: location
kind: 'MongoDB'
tags: tags
properties: {
apiProperties: {
serverVersion: mongoVersion
}
capabilities: [
{
name: 'DisableRateLimitingResponses'
}
]
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
databaseAccountOfferType: 'Standard'
disableLocalAuth: false
locations: [
{
locationName: location
isZoneRedundant: false
}
]
}
}

resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-05-15' = {
parent: account
name: databaseName
tags: tags
properties: {
resource: {
id: databaseName
}
options: {
throughput: 400
}
}
}

resource collection 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
parent: database
name: containerName
tags: tags
properties: {
resource: {
id: containerName
shardKey: {
_id: 'Hash'
}
indexes: [
{
key: {
keys: [
'_id'
]
}
}
{
key: {
keys: [
'$**'
]
}
}
]
}
}
}
/*********************************************************************************/

#disable-next-line outputs-should-not-contain-secrets
output MONGODB_CONNECTIONSTRING string = account.listConnectionStrings().connectionStrings[1].connectionString
26 changes: 26 additions & 0 deletions infra/resources.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var azsqlServerName = 'sql-${resourceToken}'
var cosmosServerName = 'cosmos-${resourceToken}'
var pgsqlServerName = 'pgsql-${resourceToken}'
var mysqlServerName = 'mysql-${resourceToken}'
var mongoServerName = 'mongo-${resourceToken}'
var mongoaciServerName = 'mongoaci-${resourceToken}'

var testDatabaseName = 'unittests'
var cosmosContainerName = 'Movies'
Expand Down Expand Up @@ -103,6 +105,28 @@ module cosmos './modules/cosmos.bicep' = {
}
}

module mongodb './modules/cosmos-mongodb.bicep' = {
name: 'mongo-deployment-${resourceToken}'
params: {
location: location
tags: tags
databaseName: testDatabaseName
containerName: cosmosContainerName
serverName: mongoServerName
}
}

module mongoaci './modules/aci-mongodb.bicep' = {
name: 'mongoaci-deployment-${resourceToken}'
params: {
location: location
tags: tags
serverName: mongoaciServerName
administratorPassword: sqlAdminPassword

}
}

module app_service './modules/appservice.bicep' = {
name: 'appsvc-deployment-${resourceToken}'
params: {
Expand All @@ -124,6 +148,8 @@ module app_service './modules/appservice.bicep' = {

output AZSQL_CONNECTIONSTRING string = azuresql.outputs.AZSQL_CONNECTIONSTRING
output COSMOS_CONNECTIONSTRING string = cosmos.outputs.COSMOS_CONNECTIONSTRING
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGODB_CONNECTIONSTRING
output MONGOACI_CONNECTIONSTRING string = mongoaci.outputs.MONGO_CONNECTIONSTRING
output MYSQL_CONNECTIONSTRING string = mysql.outputs.MYSQL_CONNECTIONSTRING
output PGSQL_CONNECTIONSTRING string = pgsql.outputs.PGSQL_CONNECTIONSTRING
output SERVICE_ENDPOINT string = app_service.outputs.SERVICE_ENDPOINT
20 changes: 13 additions & 7 deletions infra/scripts/write-runsettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@
$outputs = (azd env get-values --output json | ConvertFrom-Json)
$outputFile = "tests\.runsettings"

$fileContents = @"
$prefix = @"
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<DATASYNC_AZSQL_CONNECTIONSTRING>$($outputs.AZSQL_CONNECTION_STRING)</DATASYNC_AZSQL_CONNECTIONSTRING>
<DATASYNC_COSMOS_CONNECTIONSTRING>$($outputs.COSMOS_CONNECTION_STRING)</DATASYNC_COSMOS_CONNECTIONSTRING>
<DATASYNC_MYSQL_CONNECTIONSTRING>$($outputs.MYSQL_CONNECTION_STRING)</DATASYNC_MYSQL_CONNECTIONSTRING>
<DATASYNC_PGSQL_CONNECTIONSTRING>$($outputs.PGSQL_CONNECTION_STRING)</DATASYNC_PGSQL_CONNECTIONSTRING>
<DATASYNC_SERVICE_ENDPOINT>$($outputs.SERVICE_ENDPOINT)</DATASYNC_SERVICE_ENDPOINT>

"@

$postfix = @"
<ENABLE_SQL_LOGGING>true</ENABLE_SQL_LOGGING>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>
"@

$fileContents | Out-File -FilePath $outputFile
$sb = New-Object System.Text.StringBuilder
$outputs | Get-Member -MemberType Properties | Foreach-Object {
$propertyName = $_.Name
$propertyValue = [System.Security.SecurityElement]::Escape($outputs.$propertyName)
$sb.AppendLine(" <$($propertyName)>$($propertyValue)</$($propertyName)>") | Out-Null
}

$prefix + $sb.ToString() + $postfix | Out-File -FilePath $outputFile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.Datasync.TestCommon.Databases;
using System.Net;
using System.Net.Http.Json;

Expand All @@ -10,8 +11,8 @@ namespace CommunityToolkit.Datasync.Client.Test.Live;
[ExcludeFromCodeCoverage]
public class SampleServerTests
{
private readonly bool liveTestsAreEnabled = Environment.GetEnvironmentVariable("DATASYNC_SERVICE_ENDPOINT") is not null;
private readonly string serviceEndpoint = Environment.GetEnvironmentVariable("DATASYNC_SERVICE_ENDPOINT");
private readonly bool liveTestsAreEnabled = ConnectionStrings.Service is not null;
private readonly string serviceEndpoint = ConnectionStrings.Service;

[SkippableFact]
public async Task Metadata_GetsSetByServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ public class AzureSqlEntityTableRepository_Tests(DatabaseFixture fixture, ITestO
{
#region Setup
private readonly Random random = new();
private readonly string connectionString = Environment.GetEnvironmentVariable("DATASYNC_AZSQL_CONNECTIONSTRING");
private List<AzureSqlEntityMovie> movies = [];

public async Task InitializeAsync()
{
if (!string.IsNullOrEmpty(this.connectionString))
if (!string.IsNullOrEmpty(ConnectionStrings.AzureSql))
{
Context = await AzureSqlDbContext.CreateContextAsync(this.connectionString, output);
Context = await AzureSqlDbContext.CreateContextAsync(ConnectionStrings.AzureSql, output);
this.movies = await Context.Movies.AsNoTracking().ToListAsync();
}
}
Expand All @@ -39,7 +38,7 @@ public async Task DisposeAsync()

private AzureSqlDbContext Context { get; set; }

protected override bool CanRunLiveTests() => !string.IsNullOrEmpty(this.connectionString);
protected override bool CanRunLiveTests() => !string.IsNullOrEmpty(ConnectionStrings.AzureSql);

protected override async Task<AzureSqlEntityMovie> GetEntityAsync(string id)
=> await Context.Movies.AsNoTracking().SingleOrDefaultAsync(m => m.Id == id);
Expand Down
Loading