Пример #1
0
            public async Task Save_ShouldValidateSubscriptionBeforeSendingItToTheServer()
            {
                async Task <AblyRequest> CallSave(PushChannelSubscription subscription)
                {
                    AblyRequest request = null;
                    var         rest    = GetRestClient(r =>
                    {
                        request = r;
                        return(Task.FromResult(new AblyResponse()
                        {
                            TextResponse = string.Empty
                        }));
                    });

                    await rest.Push.Admin.ChannelSubscriptions.SaveAsync(subscription);

                    return(request);
                }

                Func <Task> nullSubscription = () => CallSave(null);
                Func <Task> withEmptyChannel = () => CallSave(PushChannelSubscription.ForDevice(string.Empty));

                (await nullSubscription.Should().ThrowAsync <AblyException>()).Which.ErrorInfo.Code.Should()
                .Be(ErrorCodes.BadRequest);

                (await withEmptyChannel.Should().ThrowAsync <AblyException>()).Which.ErrorInfo.Code.Should()
                .Be(ErrorCodes.BadRequest);
            }
Пример #2
0
            public async Task Remove_ShouldCallTheCorrectUrl()
            {
                async Task <AblyRequest> CallRemove(PushChannelSubscription subscription)
                {
                    AblyRequest request = null;
                    var         rest    = GetRestClient(r =>
                    {
                        request = r;
                        return(Task.FromResult(new AblyResponse()
                        {
                            TextResponse = string.Empty
                        }));
                    });

                    await rest.Push.Admin.ChannelSubscriptions.RemoveAsync(subscription);

                    return(request);
                }

                var request = await CallRemove(PushChannelSubscription.ForDevice("channel", "device"));

                request.Url.Should().Be("/push/channelSubscriptions");
                request.Method.Should().Be(HttpMethod.Delete);

                request.QueryParameters.Should().ContainKey("channel").WhoseValue.Should().Be("channel");
                request.QueryParameters.Should().ContainKey("deviceId").WhoseValue.Should().Be("device");

                var requestWithClientId = await CallRemove(PushChannelSubscription.ForClientId("channel", "123"));

                requestWithClientId.QueryParameters.Should().ContainKey("channel").WhoseValue.Should().Be("channel");
                requestWithClientId.QueryParameters.Should().ContainKey("clientId").WhoseValue.Should().Be("123");
            }
Пример #3
0
            public async Task Save_ShouldCallsTheCorrectUrlAndHaveTheCorrectBody()
            {
                async Task <AblyRequest> CallSave(PushChannelSubscription subscription)
                {
                    AblyRequest request = null;
                    var         rest    = GetRestClient(r =>
                    {
                        request = r;
                        return(Task.FromResult(new AblyResponse()
                        {
                            TextResponse = string.Empty
                        }));
                    });

                    await rest.Push.Admin.ChannelSubscriptions.SaveAsync(subscription);

                    return(request);
                }

                var sub     = PushChannelSubscription.ForDevice("test");
                var request = await CallSave(sub);

                request.Url.Should().Be("/push/channelSubscriptions");
                request.Method.Should().Be(HttpMethod.Post);
                request.PostData.Should().BeSameAs(sub);
            }
Пример #4
0
            public async Task ShouldSuccessfullyRemoveAChannelSubscriptionWithCustomFilter(Protocol protocol)
            {
                // Arrange
                var client = await GetRestClient(protocol, options => options.PushAdminFullWait = true);

                var device = GetTestLocalDevice(client);

                var savedDevice = await client.Push.Admin.DeviceRegistrations.SaveAsync(device);

                Func <Task> executeTest = async() =>
                {
                    var channelName = "pushenabled:test".AddRandomSuffix();
                    var channelSub  = PushChannelSubscription.ForDevice(channelName, savedDevice.Id);
                    var savedSub    = await client.Push.Admin.ChannelSubscriptions.SaveAsync(channelSub);

                    await client.Push.Admin.ChannelSubscriptions.RemoveWhereAsync(new Dictionary <string, string> {
                        { "channel", savedSub.Channel }, { "deviceId", savedSub.DeviceId }
                    });

                    var channelSubForClient = PushChannelSubscription.ForClientId(channelName, "123");
                    var clientSavedSub      = await client.Push.Admin.ChannelSubscriptions.SaveAsync(channelSubForClient);

                    await client.Push.Admin.ChannelSubscriptions.RemoveWhereAsync(new Dictionary <string, string> {
                        { "channel", clientSavedSub.Channel }, { "clientId", clientSavedSub.ClientId }
                    });

                    await client.Push.Admin.ChannelSubscriptions.RemoveWhereAsync(new Dictionary <string, string> {
                        { "channel", "not-existent" }, { "deviceId", "not-existent" }
                    });
                };

                await executeTest.Should().NotThrowAsync();
            }
Пример #5
0
            public async Task ShouldSuccessfullyRemoveAChannelSubscription(Protocol protocol)
            {
                // Arrange
                var client = await GetRestClient(protocol, options => options.PushAdminFullWait = true);

                var device = GetTestLocalDevice(client);

                var savedDevice = await client.Push.Admin.DeviceRegistrations.SaveAsync(device);

                Func <Task> executeTest = async() =>
                {
                    var channelName = "pushenabled:test".AddRandomSuffix();
                    var channelSub  = PushChannelSubscription.ForDevice(channelName, savedDevice.Id);
                    var savedSub    = await client.Push.Admin.ChannelSubscriptions.SaveAsync(channelSub);

                    await client.Push.Admin.ChannelSubscriptions.RemoveAsync(savedSub);

                    var channelSubForClient = PushChannelSubscription.ForClientId(channelName, "123");
                    var clientSavedSub      = await client.Push.Admin.ChannelSubscriptions.SaveAsync(channelSubForClient);

                    await client.Push.Admin.ChannelSubscriptions.RemoveAsync(clientSavedSub);

                    await client.Push.Admin.ChannelSubscriptions.RemoveAsync(
                        PushChannelSubscription.ForDevice("not-existent", "not-existent"));
                };

                await executeTest.Should().NotThrowAsync();
            }
Пример #6
0
            public async Task Save_ShouldUseDeviceAuthIfDeviceIdMatches()
            {
                AblyRequest request = null;
                var         rest    = GetRestClient(r =>
                {
                    request = r;
                    return(Task.FromResult(new AblyResponse()
                    {
                        TextResponse = string.Empty
                    }));
                });

                rest.Device = new LocalDevice()
                {
                    Id = "123", DeviceIdentityToken = "token"
                };

                var sub = PushChannelSubscription.ForDevice("test", "123");
                await rest.Push.Admin.ChannelSubscriptions.SaveAsync(sub);

                request.Headers.Should().ContainKey(Defaults.DeviceIdentityTokenHeader).WhoseValue.Should().Be("token");
            }
Пример #7
0
            public async Task ShouldSuccessfullySetAndUpdateChannelSubscription(Protocol protocol)
            {
                // Arrange
                var client = await GetRestClient(protocol, options => options.PushAdminFullWait = true);

                var device = GetTestLocalDevice(client);

                var savedDevice = await client.Push.Admin.DeviceRegistrations.SaveAsync(device);

                var channelName = "pushenabled:test".AddRandomSuffix();
                var channelSub  = PushChannelSubscription.ForDevice(channelName, savedDevice.Id);
                var savedSub    = await client.Push.Admin.ChannelSubscriptions.SaveAsync(channelSub);

                savedSub.Channel.Should().Be(channelSub.Channel);
                savedSub.DeviceId.Should().Be(channelSub.DeviceId);

                var channelSubForClient = PushChannelSubscription.ForClientId(channelName, "123");
                var clientSavedSub      = await client.Push.Admin.ChannelSubscriptions.SaveAsync(channelSubForClient);

                clientSavedSub.Channel.Should().Be(channelSubForClient.Channel);
                clientSavedSub.ClientId.Should().Be(channelSubForClient.ClientId);
            }