Beispiel #1
0
        When_GetKeys_Is_Executed_And_Existing_Namespace_Is_Provided_Expect_That_Personal_Data_GetAsync_Is_Called()
        {
            var @namespace = KeysService.PersonalDataNamespace;
            var customerId = "test";

            _personalDataServiceMock.Setup(x => x.CustomerProfiles.GetByCustomerIdAsync(It.IsAny <string>(), true, It.IsAny <bool>()))
            .ReturnsAsync(
                new CustomerProfileResponse
            {
                Profile = new CustomerProfile.Client.Models.Responses.CustomerProfile
                {
                    FirstName = "test", LastName = "test", Email = "test", PhoneNumber = "test"
                }
            });

            var result = await _keysService.GetKeysAsync(@namespace, customerId);

            _personalDataServiceMock.Verify(x => x.CustomerProfiles.GetByCustomerIdAsync(It.IsAny <string>(), true, It.IsAny <bool>()),
                                            Times.Once);

            Assert.True(result.ContainsKey("Email"));
            Assert.Equal("test", result.GetValueOrDefault("Email"));

            Assert.True(result.ContainsKey("PhoneNumber"));
            Assert.Equal("test", result.GetValueOrDefault("PhoneNumber"));

            Assert.True(result.ContainsKey("FirstName"));
            Assert.Equal("test", result.GetValueOrDefault("FirstName"));

            Assert.True(result.ContainsKey("LastName"));
            Assert.Equal("test", result.GetValueOrDefault("LastName"));
        }
        public async Task <Dictionary <string, string> > GetKeysAsync([FromRoute] string @namespace,
                                                                      [Required][FromQuery] string customerId)
        {
            if (string.IsNullOrEmpty(@namespace))
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, $"{nameof(@namespace)} is not provided");
            }

            if (string.IsNullOrEmpty(customerId))
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, $"{nameof(customerId)} is not provided");
            }

            var validNamespaces = new List <string>
            {
                KeysService.PersonalDataNamespace,
                KeysService.PushNotificationsNamespace,
                KeysService.CommonInfoNamespace,
                KeysService.SettingsNamespace
            };

            if (validNamespaces.All(vn => string.Compare(@namespace, vn, StringComparison.InvariantCultureIgnoreCase) != 0))
            {
                throw new ValidationApiException(HttpStatusCode.BadRequest, $"Invalid value for {nameof(@namespace)}");
            }

            var result = await _keysService.GetKeysAsync(@namespace, customerId);

            _log.Info("Got Keys For Customer", new { Namespace = @namespace, CustomerId = customerId });

            return(result);
        }