コード例 #1
0
        public async Task UserCanReadUserValue()
        {
            const string userName = "******";
            var          user     = new List <Claim>
            {
                new Claim(ClaimTypes.Name, userName),
                new Claim(ClaimTypes.Role, myApplication)
            };

            const string parameterName = "savedStringValue";

            featureStorageMoq.Setup(q => q.GetFeatureValue(
                                        It.Is <string>(v => v == validApiKey),
                                        It.Is <string>(m => m == myApplication),
                                        It.Is <string>(m => m == parameterName)))
            .ReturnsAsync("Global string value");

            featureStorageMoq.Setup(q => q.GetFeatureValue(
                                        It.Is <string>(v => v == validApiKey),
                                        It.Is <string>(m => m == myApplication + '-' + userName),
                                        It.Is <string>(m => m == parameterName)))
            .ReturnsAsync("User string value");

            // Act
            var setValue = await service.Current <string>(user, validApiKey, myApplication, parameterName);

            Assert.Equal("User string value", setValue);

            featureStorageMoq.Verify(mock => mock.GetFeatureValue(
                                         It.Is <string>(v => v == validApiKey),
                                         It.Is <string>(v => v == myApplication + '-' + userName),
                                         It.Is <string>(v => v == parameterName)
                                         ), Times.Once());

            featureStorageMoq.Verify(mock => mock.GetFeatureValue(
                                         It.Is <string>(v => v == validApiKey),
                                         It.Is <string>(v => v == myApplication),
                                         It.Is <string>(v => v == parameterName)
                                         ), Times.Never());
        }