This commit is contained in:
Anastasia Kubova 2020-10-13 10:40:06 +03:00
Родитель 0c34c175eb
Коммит cefdbb34ba
13 изменённых файлов: 1 добавлений и 687 удалений

Просмотреть файл

@ -41,4 +41,3 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("Microsoft.AppCenter.Test.Windows")]
[assembly: InternalsVisibleTo("Microsoft.AppCenter.Analytics.Test.Windows")]
[assembly: InternalsVisibleTo("Microsoft.AppCenter.Push.Test.Windows")]

Просмотреть файл

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8A885E5E-A160-4AD2-BD03-59E3A6366C32}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AppCenter.Push.NET</RootNamespace>
<AssemblyName>Microsoft.AppCenter.Push.NET</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="SQLitePCLRaw.bundle_green">
<Version>2.0.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Push.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AppCenter.NET\Microsoft.AppCenter.NET.csproj">
<Project>{e76dc547-2b63-4911-971c-767587ebfab6}</Project>
<Name>Microsoft.AppCenter.NET</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\..\SDK\AppCenterPush\Microsoft.AppCenter.Push.Windows.Shared\Microsoft.AppCenter.Push.Windows.Shared.projitems" Label="Shared" />
<Import Project="..\..\SDK\AppCenterPush\Microsoft.AppCenter.Push.Shared\Microsoft.AppCenter.Push.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -1,39 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.AppCenter.Push.NET")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.AppCenter.Push.NET")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("8a885e5e-a160-4ad2-bd03-59e3a6366c32")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("3.4.4.0")]

Просмотреть файл

@ -1,12 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
namespace Microsoft.AppCenter.Push
{
public partial class Push : AppCenterService
{
private void ApplyEnabledState(bool enabled)
{
}
}
}

Просмотреть файл

@ -1,46 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Microsoft.AppCenter.Ingestion.Models;
using Microsoft.AppCenter.Push.Ingestion.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
namespace Microsoft.AppCenter.Test.Windows.Ingestion.Models
{
using Device = Microsoft.AppCenter.Ingestion.Models.Device;
[TestClass]
public class PushInstallationLogTest
{
private static readonly DateTime? Timestamp = null;
[TestMethod]
public void TestConstructor()
{
var mockDevice = new Mock<Device>();
PushInstallationLog log = new PushInstallationLog(mockDevice.Object, "token1", Timestamp, default(System.Guid?), "userId1");
Assert.IsNotNull(log);
Assert.AreEqual(default(System.Guid?), log.Sid);
Assert.AreEqual("token1", log.PushToken);
Assert.AreEqual("userId1", log.UserId);
PushInstallationLog log2 = new PushInstallationLog(mockDevice.Object, "token2", Timestamp, System.Guid.NewGuid(), "userId2");
Assert.IsNotNull(log2);
Assert.IsNotNull(log2.Sid);
Assert.AreEqual("token2", log2.PushToken);
Assert.AreEqual("userId2", log2.UserId);
}
[TestMethod]
public void TestValidateThrowsExceptionWhenPushTokenIsNull()
{
var mockDevice = new Mock<Device>();
PushInstallationLog log = new PushInstallationLog(mockDevice.Object, null, Timestamp, null, null);
Assert.ThrowsException<ValidationException>(() => log.Validate());
}
}
}

Просмотреть файл

@ -1,85 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{39DFE901-EBE0-4907-871C-D2638FEA2D49}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.AppCenter.Push.Test.Windows</RootNamespace>
<AssemblyName>Microsoft.AppCenter.Push.Test.Windows</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Ingestion\Models\PushInstallationLogTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PushTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.AppCenter.NET\Microsoft.AppCenter.NET.csproj">
<Project>{e76dc547-2b63-4911-971c-767587ebfab6}</Project>
<Name>Microsoft.AppCenter.NET</Name>
</ProjectReference>
<ProjectReference Include="..\Microsoft.AppCenter.Push.NET\Microsoft.AppCenter.Push.NET.csproj">
<Project>{8a885e5e-a160-4ad2-bd03-59e3a6366c32}</Project>
<Name>Microsoft.AppCenter.Push.NET</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Castle.Core">
<Version>4.4.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.TestPlatform">
<Version>14.0.0</Version>
</PackageReference>
<PackageReference Include="Moq">
<Version>4.13.1</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.1.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.1.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Просмотреть файл

@ -1,39 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microsoft.AppCenter.Push.Test.Windows")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.AppCenter.Push.Test.Windows")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("39dfe901-ebe0-4907-871c-d2638fea2d49")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("3.4.4.0")]

Просмотреть файл

@ -1,34 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.AppCenter.Push.Test.Windows
{
[TestClass]
public class PushTest
{
[TestInitialize]
public void InitializePushTest()
{
Push.Instance = new Push();
}
[TestMethod]
public void InstanceIsNotNull()
{
Push.Instance = null;
Assert.IsNotNull(Push.Instance);
}
[TestMethod]
public void GetEnabled()
{
Push.SetEnabledAsync(false).Wait();
Assert.IsFalse(Push.IsEnabledAsync().Result);
Push.SetEnabledAsync(true).Wait();
Assert.IsTrue(Push.IsEnabledAsync().Result);
}
}
}

Просмотреть файл

@ -98,7 +98,6 @@
<Compile Include="Utils\NetworkStateTests.cs" />
<Compile Include="Utils\DefaultScreenSizeProviderTest.cs" />
<Compile Include="UWPCrashesTest.cs" />
<Compile Include="UWPPushTest.cs" />
<Compile Include="UnitTestApp.xaml.cs">
<DependentUpon>UnitTestApp.xaml</DependentUpon>
</Compile>
@ -139,10 +138,6 @@
<Project>{2f715d51-643c-4f7f-9ea4-6554d4eeccb2}</Project>
<Name>Microsoft.AppCenter.Crashes.UWP</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\AppCenterPush\Microsoft.AppCenter.Push.UWP\Microsoft.AppCenter.Push.UWP.csproj">
<Project>{8072449c-c6a8-4b36-87dc-173f295d161c}</Project>
<Name>Microsoft.AppCenter.Push.UWP</Name>
</ProjectReference>
<ProjectReference Include="..\..\SDK\AppCenter\Microsoft.AppCenter.UWP\Microsoft.AppCenter.UWP.csproj">
<Project>{15e3fc9b-7714-4468-a296-81627a5b8f01}</Project>
<Name>Microsoft.AppCenter.UWP</Name>

Просмотреть файл

@ -1,255 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.AppCenter.Channel;
using Microsoft.AppCenter.Windows.Shared.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Windows.Data.Xml.Dom;
namespace Microsoft.AppCenter.Test.UWP
{
[TestClass]
public class UWPPushTest
{
private Mock<IChannelGroup> _mockChannelGroup;
private Mock<IChannelUnit> _mockChannel;
[TestInitialize]
public void InitializeUWPPushTest()
{
_mockChannelGroup = new Mock<IChannelGroup>();
_mockChannel = new Mock<IChannelUnit>();
_mockChannelGroup.Setup(
group => group.AddChannel(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<TimeSpan>(), It.IsAny<int>()))
.Returns(_mockChannel.Object);
}
/// <summary>
/// Verify ParseLaunchString works when launch string is null
/// </summary>
[TestMethod]
public void ParseLaunchStringWhenStringIsNull()
{
var result = Push.Push.ParseLaunchString(null);
Assert.IsNull(result);
}
/// <summary>
/// Verify ParseLaunchString works when launch string is empty
/// </summary>
[TestMethod]
public void ParseLaunchStringWhenStringIsEmpty()
{
var result = Push.Push.ParseLaunchString(string.Empty);
Assert.IsNull(result);
}
/// <summary>
/// Verify ParseLaunchString works when launch string is not valid Json
/// </summary>
[TestMethod]
public void ParseLaunchStringWhenStringContainsInvalidJson()
{
var actualResult = Push.Push.ParseLaunchString("{\"mobile_center\":{\"key1\":\"value1\",\"key2\":\"value2\"");
Assert.IsNull(actualResult);
}
/// <summary>
/// Verify ParseLaunchString works when launch string doesn't contain "mobile_center"
/// </summary>
[TestMethod]
public void ParseLaunchStringWhenStringDoesNotContainAppCenter()
{
var actualResult = Push.Push.ParseLaunchString("{\"foobar\":{\"key1\":\"value1\",\"key2\":\"value2\"}}");
Assert.IsNull(actualResult);
}
/// <summary>
/// Verify ParseLaunchString works with new key
/// </summary>
[TestMethod]
public void ParseLaunchStringAppCenter()
{
var actualResult = Push.Push.ParseLaunchString("{\"appCenter\":{\"key1\":\"value1\",\"key2\":\"value2\"}}");
var expectedResult = new Dictionary<string, string>
{
["key1"] = "value1",
["key2"] = "value2"
};
Assert.AreEqual(2, actualResult.Count);
Assert.AreEqual(expectedResult["key1"], actualResult["key1"]);
Assert.AreEqual(expectedResult["key2"], actualResult["key2"]);
}
/// <summary>
/// Verify ParseLaunchString works with old key
/// </summary>
[TestMethod]
public void ParseLaunchStringMobileCenter()
{
var actualResult = Push.Push.ParseLaunchString("{\"mobile_center\":{\"key1\":\"value1\",\"key2\":\"value2\"}}");
var expectedResult = new Dictionary<string, string>
{
["key1"] = "value1",
["key2"] = "value2"
};
Assert.AreEqual(2, actualResult.Count);
Assert.AreEqual(expectedResult["key1"], actualResult["key1"]);
Assert.AreEqual(expectedResult["key2"], actualResult["key2"]);
}
/// <summary>
/// Verify ParseAppCenterPush works when custom data is null
/// </summary>
[TestMethod]
public void ParseAppCenterPushWhenCustomDataIsNull()
{
var xmlContent = new XmlDocument();
xmlContent.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><toast><visual><binding template=\"ToastImageAndText02\"><text id=\"1\">test-title</text><text id=\"2\">hello world</text></binding></visual></toast>");
var actualResult = Push.Push.ParseAppCenterPush(xmlContent);
Assert.IsNull(actualResult);
}
/// <summary>
/// Verify ParseAppCenterPush works with new key
/// </summary>
[TestMethod]
public void ParseAppCenterPushAppCenter()
{
var xmlContent = new XmlDocument();
xmlContent.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><toast launch=\"{&quot;appCenter&quot;:{&quot;key1&quot;:&quot;value1&quot;,&quot;key2&quot;:&quot;value2&quot;}}\"><visual><binding template=\"ToastImageAndText02\"><text id=\"1\">test-title</text><text id=\"2\">hello world</text></binding></visual></toast>");
var actualResult = Push.Push.ParseAppCenterPush(xmlContent);
var expectedResult = new Push.PushNotificationReceivedEventArgs
{
Title = "test-title",
Message = "hello world",
CustomData = new Dictionary<string, string>
{
["key1"] = "value1",
["key2"] = "value2"
}
};
Assert.AreEqual(expectedResult.Title, actualResult.Title);
Assert.AreEqual(expectedResult.Message, actualResult.Message);
Assert.AreEqual(expectedResult.CustomData["key1"], actualResult.CustomData["key1"]);
Assert.AreEqual(expectedResult.CustomData["key2"], actualResult.CustomData["key2"]);
}
/// <summary>
/// Verify ParseAppCenterPush works with old key
/// </summary>
[TestMethod]
public void ParseAppCenterPushMobileCenter()
{
var xmlContent = new XmlDocument();
xmlContent.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><toast launch=\"{&quot;mobile_center&quot;:{&quot;key1&quot;:&quot;value1&quot;,&quot;key2&quot;:&quot;value2&quot;}}\"><visual><binding template=\"ToastImageAndText02\"><text id=\"1\">test-title</text><text id=\"2\">hello world</text></binding></visual></toast>");
var actualResult = Push.Push.ParseAppCenterPush(xmlContent);
var expectedResult = new Push.PushNotificationReceivedEventArgs
{
Title = "test-title",
Message = "hello world",
CustomData = new Dictionary<string, string>
{
["key1"] = "value1",
["key2"] = "value2"
}
};
Assert.AreEqual(expectedResult.Title, actualResult.Title);
Assert.AreEqual(expectedResult.Message, actualResult.Message);
Assert.AreEqual(expectedResult.CustomData["key1"], actualResult.CustomData["key1"]);
Assert.AreEqual(expectedResult.CustomData["key2"], actualResult.CustomData["key2"]);
}
/// <summary>
/// Verify Push Service can be enabled or disabled correctly.
/// </summary>
[TestMethod]
public void SetEnabledAsync()
{
Push.Push.SetEnabledAsync(false).Wait();
Assert.IsFalse(Push.Push.IsEnabledAsync().Result);
Push.Push.SetEnabledAsync(true).Wait();
Assert.IsTrue(Push.Push.IsEnabledAsync().Result);
}
/// <summary>
/// Verify OnUserIdUpdated works with userId changes.
/// </summary>
[TestMethod]
public void VerifyEnqueueAsyncIsCalledOnceOnUserIdUpdatedInvocation()
{
Push.Push.Instance.OnChannelGroupReady(_mockChannelGroup.Object, string.Empty);
Push.Push.SetEnabledAsync(true).Wait();
Push.Push.Instance.LatestPushToken = "token";
var userId = "userId";
UserIdContext.Instance.UserId = userId;
var semaphore = new SemaphoreSlim(0);
_mockChannel.Setup(channel => channel.EnqueueAsync(It.Is<Push.Ingestion.Models.PushInstallationLog>(log =>
string.Equals(log.UserId, userId)))).Callback(() =>
{
semaphore.Release();
});
semaphore.Wait(10000);
_mockChannel.Verify(channel => channel.EnqueueAsync(It.Is<Push.Ingestion.Models.PushInstallationLog>(log =>
string.Equals(log.UserId, userId))), Times.AtLeastOnce());
}
/// <summary>
/// Verify OnUserIdUpdated can still listen for userId changes when push service is disabled and then enabled.
/// </summary>
[TestMethod]
public void VerifyUserIdChangeWhenPushDisabledAndThenEnabled()
{
Push.Push.Instance.OnChannelGroupReady(_mockChannelGroup.Object, string.Empty);
// Disable the push service, should not listen for userId changes.
Push.Push.SetEnabledAsync(false).Wait();
var e = new UserIdUpdatedEventArgs { UserId = "newUserId" };
var userId = "userId1";
UserIdContext.Instance.UserId = userId;
var semaphore = new SemaphoreSlim(0);
_mockChannel.Setup(channel => channel.EnqueueAsync(It.Is<Push.Ingestion.Models.PushInstallationLog>(log =>
string.Equals(log.UserId, userId)))).Callback(() =>
{
semaphore.Release();
});
semaphore.Wait(10000);
_mockChannel.Verify(channel => channel.EnqueueAsync(It.Is<Push.Ingestion.Models.PushInstallationLog>(log =>
string.Equals(log.UserId, userId))), Times.Never());
// Enable the push service, should start listen for userId changes.
Push.Push.SetEnabledAsync(true).Wait();
Push.Push.Instance.LatestPushToken = "token";
userId = "userId2";
UserIdContext.Instance.UserId = userId;
semaphore = new SemaphoreSlim(0);
_mockChannel.Setup(channel => channel.EnqueueAsync(It.Is<Push.Ingestion.Models.PushInstallationLog>(log =>
string.Equals(log.UserId, userId)))).Callback(() =>
{
semaphore.Release();
});
semaphore.Wait(10000);
_mockChannel.Verify(channel => channel.EnqueueAsync(It.Is<Push.Ingestion.Models.PushInstallationLog>(log =>
string.Equals(log.UserId, userId))), Times.AtLeastOnce());
}
}
}

Просмотреть файл

@ -9,8 +9,7 @@
<ModulePaths>
<Include>
<ModulePath>.*\Microsoft.AppCenter.NET.dll$</ModulePath>
<ModulePath>.*\Microsoft.AppCenter.Analytics.NET.dll$</ModulePath>
<ModulePath>.*\Microsoft.AppCenter.Push.NET.dll$</ModulePath>               
<ModulePath>.*\Microsoft.AppCenter.Analytics.NET.dll$</ModulePath>               
</Include>
<Exclude>
  <ModulePath>.*Test.Windows.dll</ModulePath>

Просмотреть файл

@ -1,78 +0,0 @@
// <auto-generated>
// Copyright (c) Microsoft Corporation. All rights reserved.
// </auto-generated>
namespace Microsoft.AppCenter.Ingestion.Models
{
using Microsoft.Rest;
using Newtonsoft.Json;
using System.Linq;
/// <summary>
/// Push installation Information.
/// </summary>
[Newtonsoft.Json.JsonObject("pushInstallation")]
public partial class PushInstallationLog : Log
{
/// <summary>
/// Initializes a new instance of the PushInstallationLog class.
/// </summary>
public PushInstallationLog()
{
CustomInit();
}
/// <summary>
/// Initializes a new instance of the PushInstallationLog class.
/// </summary>
/// <param name="pushToken">The PNS handle for this installation.
/// </param>
/// <param name="timestamp">Log timestamp, example:
/// '2017-03-13T18:05:42Z'.
/// </param>
/// <param name="sid">When tracking an analytics session, logs can be
/// part of the session by specifying this identifier.
/// This attribute is optional, a missing value means the session
/// tracking is disabled (like when using only error reporting
/// feature).
/// Concrete types like StartSessionLog or PageLog are always part of a
/// session and always include this identifier.
/// </param>
/// <param name="userId">optional string used for associating logs with
/// users.
/// </param>
public PushInstallationLog(Device device, string pushToken, System.DateTime? timestamp = default(System.DateTime?), System.Guid? sid = default(System.Guid?), string userId = default(string))
: base(device, timestamp, sid, userId)
{
PushToken = pushToken;
CustomInit();
}
/// <summary>
/// An initialization method that performs custom operations like setting defaults
/// </summary>
partial void CustomInit();
/// <summary>
/// Gets or sets the PNS handle for this installation.
///
/// </summary>
[JsonProperty(PropertyName = "pushToken")]
public string PushToken { get; set; }
/// <summary>
/// Validate the object.
/// </summary>
/// <exception cref="ValidationException">
/// Thrown if validation fails
/// </exception>
public override void Validate()
{
base.Validate();
if (PushToken == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "PushToken");
}
}
}
}

Просмотреть файл

@ -274,33 +274,6 @@ Task("ReleaseApplication")
DistributionGroup + mandatorySuffix + ".");
});
// Push tasks
Task("SendPushNotification")
.Does(()=>
{
var name = "Test Notification";
var title = "Test Notification";
var timeSent = DateTime.Now.ToString();
var body = "Notification sent from test script at " + timeSent + ".";
var properties = new Dictionary<string, string> {{"time_sent", timeSent}};
var notificationJson = new JObject(
new JProperty("notification_content",
new JObject(
new JProperty("name", name),
new JProperty("title", title),
new JProperty("body", body),
new JProperty("custom_data",
new JObject(
from key in properties.Keys
select new JProperty(key, properties[key]))))));
Information("Sending notification:\n" + notificationJson.ToString());
var url = GetApiUrl(BaseUrl, CurrentApp.AppOwner, CurrentApp.AppId, "push/notifications");
var request = GetWebRequest(url, Token);
AttachJsonPayload(request, notificationJson);
var responseJson = GetResponseJson(request);
Information("Successfully sent push notification and received result:\n" + responseJson.ToString());
});
Task("BuildAppsInAppCenter").Does(() =>
{
CurrentApp = ( from app in Applications