-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOCSP-39161 .NET updateBaseURL (#3246)
## Pull Request Info Jira ticket: https://jira.mongodb.org/browse/DOCSP-39161 - [Connect to App Services Backend](https://preview-mongodblindseymoore.gatsbyjs.io/realm/DOCSP-39161/sdk/dotnet/app-services/connect-to-app-services-backend/) - Note: Commented out failing tests. Fixing them will be a part of this ticket: https://jira.mongodb.org/browse/DOCSP-39638. ### Reminder Checklist Before merging your PR, make sure to check a few things. - [ ] Did you tag pages appropriately? - genre - meta.keywords - meta.description - [x] Describe your PR's changes in the Release Notes section - [ ] Create a Jira ticket for related docs-app-services work, if any ### Release Notes <!-- - **Kotlin** SDK - Realm/Manage Realm Files/Encrypt a Realm: Add information on encryption for local and synced realms. --> - .NET SDK - Application Services/Connect to an App Services App: Add a section on updating the base URL during runtime. ### Review Guidelines [REVIEWING.md](https://github.com/mongodb/docs-realm/blob/master/REVIEWING.md) --------- Co-authored-by: MongoCaleb <caleb.thompson@mongodb.com>
- Loading branch information
Showing
12 changed files
with
194 additions
and
18 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
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,86 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using Realms; | ||
using Realms.Sync; | ||
using Realms.Sync.Exceptions; | ||
using Realms.Sync.Testing; | ||
using Realms.Logging; | ||
using System.Threading; | ||
|
||
//:snippet-start: experimental-import | ||
using System.Diagnostics.CodeAnalysis; | ||
//:snippet-end: | ||
|
||
namespace Examples | ||
{ | ||
public class BaseURLChange | ||
{ | ||
|
||
[Test] | ||
|
||
public async Task testEdgeAppWithCustomBaseURL() | ||
{ | ||
var YOUR_APP_ID = "sync-edge-server-cskhoow"; | ||
|
||
// :snippet-start: custom-base-url | ||
// Specify a base URL to connect to a server other than the default. | ||
var appConfig = new AppConfiguration(YOUR_APP_ID); | ||
appConfig.BaseUri = new Uri("http://localhost:80"); | ||
|
||
var app = App.Create(appConfig); | ||
// :snippet-end: | ||
|
||
try { | ||
var user = await app.LogInAsync(Credentials.Anonymous()); | ||
Assert.AreEqual(UserState.LoggedIn, user.State); | ||
await user.LogOutAsync(); | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine(e.Message); | ||
Assert.AreEqual(e.Message, "Could not connect to the server."); | ||
} | ||
|
||
} | ||
|
||
[Test] | ||
|
||
public async Task testChangeBaseURL() | ||
{ | ||
var YOUR_APP_ID = "sync-edge-server-cskhoow"; | ||
|
||
// :snippet-start: update-base-url | ||
// Specify a baseURL to connect to a server other than the default. | ||
// In this case, an Edge Server instance running on the device | ||
var appConfig = new AppConfiguration(YOUR_APP_ID); | ||
appConfig.BaseUri = new Uri("http://localhost:80"); | ||
|
||
var app = App.Create(appConfig); | ||
|
||
// ... log in a user and use the app ... | ||
|
||
// Update the base URL back to the default. | ||
#pragma warning disable Rlm001 // suppress the warning for the experimental method | ||
|
||
await app.UpdateBaseUriAsync(new Uri("https://services.cloud.mongodb.com")); | ||
|
||
#pragma warning restore Rlm001 | ||
// :snippet-end: | ||
|
||
try { | ||
var user = await app.LogInAsync(Credentials.Anonymous()); | ||
Assert.AreEqual(UserState.LoggedIn, user.State); | ||
|
||
await user.LogOutAsync(); | ||
} | ||
catch (Exception e) { | ||
Console.WriteLine(e.Message); | ||
Assert.AreEqual(e.Message, "With a base URL pointing to the cloud, logging in should not fail."); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
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
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
5 changes: 5 additions & 0 deletions
5
source/examples/generated/dotnet/BaseURLChange.snippet.custom-base-url.cs
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,5 @@ | ||
// Specify a base URL to connect to a server other than the default. | ||
var appConfig = new AppConfiguration(YOUR_APP_ID); | ||
appConfig.BaseUri = new Uri("http://localhost:80"); | ||
|
||
var app = App.Create(appConfig); |
1 change: 1 addition & 0 deletions
1
source/examples/generated/dotnet/BaseURLChange.snippet.experimental-import.cs
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 @@ | ||
using System.Diagnostics.CodeAnalysis; |
15 changes: 15 additions & 0 deletions
15
source/examples/generated/dotnet/BaseURLChange.snippet.update-base-url.cs
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,15 @@ | ||
// Specify a baseURL to connect to a server other than the default. | ||
// In this case, an Edge Server instance running on the device | ||
var appConfig = new AppConfiguration(YOUR_APP_ID); | ||
appConfig.BaseUri = new Uri("http://localhost:80"); | ||
|
||
var app = App.Create(appConfig); | ||
|
||
// ... log in a user and use the app ... | ||
|
||
// Update the base URL back to the default. | ||
#pragma warning disable Rlm001 // suppress the warning for the experimental method | ||
|
||
await app.UpdateBaseUriAsync(new Uri("https://services.cloud.mongodb.com")); | ||
|
||
#pragma warning restore Rlm001 |
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