Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add network requests allowed API #1519

Merged
merged 42 commits into from
May 12, 2021
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
599ca9f
Add new API to App Center SDK
Apr 19, 2021
197affd
Update android version
Apr 19, 2021
bc8316d
Update test apps
Apr 19, 2021
35bc6eb
Rename methods
Apr 19, 2021
f5ae576
Update test apps
Apr 19, 2021
c41a16b
Add block for network requests API
Apr 20, 2021
a576f53
Update API for iOS
Apr 20, 2021
8fe2233
Update tests
Apr 20, 2021
b72e2bb
Resolve feedback
Apr 21, 2021
865db40
Resolve feedback
Apr 21, 2021
06c404f
Fix test
Apr 21, 2021
05ace1a
Update changelog
Apr 21, 2021
a7630d0
Save block network requests state
Apr 22, 2021
ccaa275
Fix block network requests after adding the channel
Apr 23, 2021
f6fa627
Update test apps
Apr 23, 2021
390c635
Add user default values
Apr 23, 2021
24eaef4
Merge pull request #1517 from microsoft/feature/block-network-request…
Apr 23, 2021
bea7fa4
Merge branch 'feature/block-network-requests' into feature/block-netw…
Apr 23, 2021
f52ece4
Merge pull request #1518 from microsoft/feature/block-network-request…
Apr 23, 2021
552c70c
Fix test
Apr 23, 2021
3ede877
Update block network requests implementation
Apr 27, 2021
4f249ef
Update block network requests implementation
Apr 28, 2021
829f595
Resolve feedback
Apr 28, 2021
99933b5
Update block network requests implementation
Apr 28, 2021
2924683
Remove tests
Apr 29, 2021
7c37992
Update test apps
Apr 29, 2021
3f51fe6
Update the implementation for the blocking network requests
Apr 30, 2021
1338990
Resolve feedback
Apr 30, 2021
2d2d822
Update tests
Apr 30, 2021
abf8cea
Fix some tests
Apr 30, 2021
3a2abd3
Update versions
May 4, 2021
f8f93b8
Update tests
May 4, 2021
ef5529b
Update metadata file
May 5, 2021
6f321d0
Update android version
May 5, 2021
6b54a99
Update test apps
May 5, 2021
e0b4b70
Update test apps
May 5, 2021
ca8f69b
Update changelog
May 5, 2021
2fbb05f
Resolve feedback
May 7, 2021
d394c54
Fix build
May 7, 2021
3f24438
Revert some changes
May 7, 2021
782e3cf
Update tests
May 11, 2021
f5814e7
Update Android and iOS version
May 12, 2021
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
Prev Previous commit
Next Next commit
Update tests
Anastasia Kubova committed May 4, 2021

Verified

This commit was signed with the committer’s verified signature.
mike-sul Mike Sul
commit f8f93b8976870e5fad3ad110f8c89d137c8bc798
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AppCenter.Ingestion.Http;
using Microsoft.AppCenter.Test.Utils;
using Microsoft.AppCenter.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

@@ -15,12 +17,19 @@ namespace Microsoft.AppCenter.Test.Windows.Ingestion.Http
public class IngestionHttpTest : HttpIngestionTest
{
private IngestionHttp _httpIngestion;
private readonly Mock<IApplicationSettings> _settingsMock = new Mock<IApplicationSettings>();

[TestInitialize]
[System.Obsolete]
public void InitializeHttpIngestionTest()
{
_adapter = new Mock<IHttpNetworkAdapter>();
_httpIngestion = new IngestionHttp(_adapter.Object);
AppCenter.Instance = null;
#pragma warning disable 612
AppCenter.SetApplicationSettingsFactory(new MockApplicationSettingsFactory(_settingsMock));
_settingsMock.Setup(settings => settings.GetValue(AppCenter.AllowedNetworkRequestsKey, It.IsAny<bool>())).Returns(true);
#pragma warning restore 612
}

/// <summary>
@@ -29,7 +38,6 @@ public void InitializeHttpIngestionTest()
[TestMethod]
public async Task HttpIngestionStatusCodeOk()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.OK);
var call = _httpIngestion.Call(AppSecret, InstallId, Logs);
await call.ToTask();
@@ -45,7 +53,7 @@ public async Task HttpIngestionStatusCodeOk()
[TestMethod]
public async Task HttpIngestionWhenIngestionIsDisabled()
{
AppCenter.PlatformIsNetworkRequestsAllowed = false;
_settingsMock.Setup(settings => settings.GetValue(AppCenter.AllowedNetworkRequestsKey, It.IsAny<bool>())).Returns(false);
SetupAdapterSendResponse(HttpStatusCode.OK);
try
{
@@ -66,7 +74,6 @@ public async Task HttpIngestionWhenIngestionIsDisabled()
[TestMethod]
public async Task HttpIngestionStatusCodePartialContent()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.PartialContent);
var call = _httpIngestion.Call(AppSecret, InstallId, Logs);
await call.ToTask();
@@ -93,7 +100,6 @@ public async Task HttpIngestionStatusCodeError()
[TestMethod]
public async Task HttpIngestionStatusCodeErrorBelow200()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.SwitchingProtocols);
var call = _httpIngestion.Call(AppSecret, InstallId, Logs);
await Assert.ThrowsExceptionAsync<HttpIngestionException>(() => call.ToTask());
@@ -106,7 +112,6 @@ public async Task HttpIngestionStatusCodeErrorBelow200()
[TestMethod]
public async Task HttpIngestionCancel()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
_adapter
.Setup(a => a.SendAsync(
It.IsAny<string>(),
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@
using System.Threading.Tasks;
using Microsoft.AppCenter.Ingestion;
using Microsoft.AppCenter.Ingestion.Http;
using Microsoft.AppCenter.Test.Utils;
using Microsoft.AppCenter.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

@@ -18,6 +20,7 @@ public class NetworkStateTest : HttpIngestionTest
{
private NetworkStateAdapter _networkState;
private NetworkStateIngestion _networkStateIngestion;
private readonly Mock<IApplicationSettings> _settingsMock = new Mock<IApplicationSettings>();

[TestInitialize]
public void InitializeNetworkStateTest()
@@ -27,6 +30,11 @@ public void InitializeNetworkStateTest()

var httpIngestion = new IngestionHttp(_adapter.Object);
_networkStateIngestion = new NetworkStateIngestion(httpIngestion, _networkState);
AppCenter.Instance = null;
#pragma warning disable 612
AppCenter.SetApplicationSettingsFactory(new MockApplicationSettingsFactory(_settingsMock));
_settingsMock.Setup(settings => settings.GetValue(AppCenter.AllowedNetworkRequestsKey, It.IsAny<bool>())).Returns(true);
#pragma warning restore 612
}

/// <summary>
@@ -35,7 +43,6 @@ public void InitializeNetworkStateTest()
[TestMethod]
public async Task NetworkStateIngestionOnlineAsync()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.OK);
_networkState.IsConnected = true;
var call = _networkStateIngestion.Call(AppSecret, InstallId, Logs);
@@ -65,7 +72,6 @@ public async Task NetworkStateIngestionOffline()
[TestMethod]
public async Task NetworkStateIngestionComeBackOnline()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.OK);
_networkState.IsConnected = false;
var call = _networkStateIngestion.Call(AppSecret, InstallId, Logs);
@@ -83,7 +89,6 @@ public async Task NetworkStateIngestionComeBackOnline()
[TestMethod]
public async Task NetworkStateIngestionComeBackOnlineMultipleCalls()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
const int CallsCount = 5;
SetupAdapterSendResponse(HttpStatusCode.OK);
_networkState.IsConnected = false;
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@
using System.Threading.Tasks;
using Microsoft.AppCenter.Ingestion;
using Microsoft.AppCenter.Ingestion.Http;
using Microsoft.AppCenter.Test.Utils;
using Microsoft.AppCenter.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

@@ -21,12 +23,18 @@ public class RetryableTest : HttpIngestionTest
TimeSpan.FromSeconds(1)
};
private IIngestion _retryableIngestion;
private readonly Mock<IApplicationSettings> _settingsMock = new Mock<IApplicationSettings>();

[TestInitialize]
public void InitializeRetryableTest()
{
_adapter = new Mock<IHttpNetworkAdapter>();
_retryableIngestion = new RetryableIngestion(new IngestionHttp(_adapter.Object), Intervals);
AppCenter.Instance = null;
#pragma warning disable 612
AppCenter.SetApplicationSettingsFactory(new MockApplicationSettingsFactory(_settingsMock));
_settingsMock.Setup(settings => settings.GetValue(AppCenter.AllowedNetworkRequestsKey, It.IsAny<bool>())).Returns(true);
#pragma warning restore 612
}

/// <summary>
@@ -35,7 +43,6 @@ public void InitializeRetryableTest()
[TestMethod]
public async Task RetryableIngestionSuccess()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.OK);
var call = _retryableIngestion.Call(AppSecret, InstallId, Logs);
await call.ToTask();
@@ -50,7 +57,6 @@ public async Task RetryableIngestionSuccess()
[TestMethod]
public async Task RetryableIngestionRepeat1()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;

// RequestTimeout - retryable
SetupAdapterSendResponse(HttpStatusCode.RequestTimeout, HttpStatusCode.OK);
@@ -71,7 +77,6 @@ public async Task RetryableIngestionRepeat1()
[TestMethod]
public async Task RetryableIngestionRepeat3()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;

// RequestTimeout - retryable
SetupAdapterSendResponse(HttpStatusCode.RequestTimeout, HttpStatusCode.RequestTimeout, HttpStatusCode.RequestTimeout, HttpStatusCode.OK);
@@ -100,7 +105,6 @@ public async Task RetryableIngestionRepeat3()
[TestMethod]
public async Task RetryableIngestionCancel()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;

// RequestTimeout - retryable
SetupAdapterSendResponse(HttpStatusCode.RequestTimeout);
@@ -128,7 +132,6 @@ public async Task RetryableIngestionCancel()
[TestMethod]
public async Task RetryableIngestionException()
{
AppCenter.PlatformIsNetworkRequestsAllowed = true;
SetupAdapterSendResponse(HttpStatusCode.BadRequest);
var call = _retryableIngestion.Call(AppSecret, InstallId, Logs);
await Assert.ThrowsExceptionAsync<HttpIngestionException>(() => call.ToTask());