Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 119 forks source link

[BUG] - Expiration Time for installation/registration is being set to to default value when use PatchInstallation #267

Open smileyiori opened 1 year ago

smileyiori commented 1 year ago

Describe the bug I am trying to change the Channel URI for an Installation, but it is changing the Expiration Time to 9999-12-31 11:59:59 PM. But the problem is that I am using Patch, so it should only update the channel right?

var addChannel = new PartialUpdateOperation
{
     Operation = UpdateOperationType.Replace,
     Path = "/pushChannel",
     Value = newChannelToken
 };

 await _notificationHubClient.PatchInstallationAsync(installationId, new List<PartialUpdateOperation>() { addChannel });

Exception or Stack Trace Add the exception log and stack trace if available

To Reproduce Steps to reproduce the behavior:

Create an installation and set the expiration time. After that, use Patch to modify a channel. After that, you are going to see that the expiration time has been updated.

Code Snippet Add the code snippet that causes the issue.

public async Task CreateAndUpdateInstallationAsync(DeviceInstallation deviceInstallation)
        {
            string deviceInstallationPlatform = deviceInstallation?.Platform ?? string.Empty;

            if (deviceInstallation is null ||
                string.IsNullOrWhiteSpace(deviceInstallation?.InstallationId) ||
                string.IsNullOrWhiteSpace(deviceInstallation?.Platform) ||
                string.IsNullOrWhiteSpace(deviceInstallation?.PushChannel) ||
                !_installationPlatform.TryGetValue(deviceInstallationPlatform, out NotificationPlatform platform))
            {
                throw new ArgumentException("The installation could not be registered.");
            }

            var installation = new Installation()
            {
                InstallationId = deviceInstallation?.InstallationId,
                Platform = platform,
                PushChannel = deviceInstallation?.PushChannel,
                Tags = deviceInstallation?.Tags,
                ExpirationTime = DateTime.Now.AddDays(30)
            };

            if (deviceInstallation!.Templates.Count > 0)
            {
                installation.Templates = new Dictionary<string, InstallationTemplate>();

                foreach (DeviceInstallationTemplate deviceInstallationTemplate in deviceInstallation!.Templates)
                {
                    var installationTemplate = new InstallationTemplate
                    {
                        Body = deviceInstallationTemplate.Body
                    };

                    if (deviceInstallationTemplate.Header.Count > 0)
                    {
                        installationTemplate.Headers = deviceInstallationTemplate.Header;
                    }

                    installation.Templates.Add(deviceInstallationTemplate.Name, installationTemplate);
                }
            }

            try
            {
                await _notificationHubClient.CreateOrUpdateInstallationAsync(installation);
            }
            catch
            {
                throw;
            }
        }

public async Task UpdateDeviceChannelAsync(string installationId, string newChannelToken)
{
            var addChannel = new PartialUpdateOperation
            {
                Operation = UpdateOperationType.Replace,
                Path = "/pushChannel",
                Value = newChannelToken
            };

   await _notificationHubClient.PatchInstallationAsync(installationId, new List<PartialUpdateOperation>() { addChannel });
}

Expected behavior A clear and concise description of what you expected to happen. Expiration time should not be updated.

Screenshots If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

Additional context Add any other context about the problem here.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report