Ejemplo n.º 1
0
        public void RandGuidResolver_ReturnsExpectedValue()
        {
            BindingParameterResolver resolver = null;

            BindingParameterResolver.TryGetResolver("rand-guid", out resolver);

            string resolvedValue = resolver.Resolve("rand-guid");

            Assert.Equal(36, resolvedValue.Length);
            Assert.Equal(4, resolvedValue.Count(p => p == '-'));

            resolvedValue = resolver.Resolve("rand-guid:");  // no format
            Assert.Equal(36, resolvedValue.Length);
            Assert.Equal(4, resolvedValue.Count(p => p == '-'));

            resolvedValue = resolver.Resolve("rand-guid:D");
            Assert.Equal(36, resolvedValue.Length);
            Assert.Equal(4, resolvedValue.Count(p => p == '-'));

            resolvedValue = resolver.Resolve("rand-guid:N");
            Assert.Equal(32, resolvedValue.Length);
            Assert.Equal(0, resolvedValue.Count(p => p == '-'));

            resolvedValue = resolver.Resolve("rand-guid:B");
            Assert.Equal(38, resolvedValue.Length);
            Assert.Equal(4, resolvedValue.Count(p => p == '-'));
            Assert.True(resolvedValue.StartsWith("{"));
            Assert.True(resolvedValue.EndsWith("}"));
        }
Ejemplo n.º 2
0
        public void IncompatibleBindingExpression_ThrowsArgumentException()
        {
            BindingParameterResolver resolver = null;

            BindingParameterResolver.TryGetResolver("rand-guid", out resolver);

            var ex = Assert.Throws <ArgumentException>(() =>
            {
                resolver.Resolve("datetime:mm-dd-yyyy");
            });

            Assert.Equal($"The value specified is not a 'rand-guid' binding parameter.{Environment.NewLine}Parameter name: value", ex.Message);
        }
Ejemplo n.º 3
0
        public void DateTimeResolver_ReturnsExpectedValue()
        {
            BindingParameterResolver resolver = null;

            BindingParameterResolver.TryGetResolver("datetime", out resolver);

            string resolvedValue = resolver.Resolve("datetime");

            resolvedValue = resolver.Resolve("datetime:G");
            Assert.NotNull(DateTime.Parse(resolvedValue));

            resolvedValue = resolver.Resolve("datetime:MM/yyyy");
            Assert.Equal(DateTime.UtcNow.ToString("MM/yyyy"), resolvedValue);

            resolvedValue = resolver.Resolve("datetime:yyyyMMdd");
            Assert.Equal(DateTime.UtcNow.ToString("yyyyMMdd"), resolvedValue);
        }
        private static void ValidateContractCompatibility(IEnumerable <string> parameterNames, IReadOnlyDictionary <string, Type> bindingDataContract)
        {
            if (parameterNames != null && bindingDataContract != null)
            {
                foreach (string parameterName in parameterNames)
                {
                    if (BindingParameterResolver.IsSystemParameter(parameterName))
                    {
                        continue;
                    }

                    if (!bindingDataContract.ContainsKey(parameterName))
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "No binding parameter exists for '{0}'.", parameterName));
                    }
                }
            }
        }
        private static void ValidateContractCompatibility(IEnumerable <string> parameterNames, IReadOnlyDictionary <string, Type> bindingDataContract)
        {
            if (parameterNames != null && bindingDataContract != null)
            {
                foreach (string parameterName in parameterNames)
                {
                    if (string.Equals(parameterName, SystemBindingData.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    if (BindingParameterResolver.IsSystemParameter(parameterName))
                    {
                        continue;
                    }

                    if (!bindingDataContract.ContainsKey(parameterName))
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Constants.UnableToResolveBindingParameterFormat, parameterName));
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void IsSystemParameter_ReturnsExpectedValue(string value, bool expected)
 {
     Assert.Equal(expected, BindingParameterResolver.IsSystemParameter(value));
 }