public static SoftKeySet CreateCommandName([NotNull] Type commadType) { if (commadType == null) { throw new ArgumentNullException(nameof(commadType)); } if (!typeof(IConsoleCommand).IsAssignableFrom(commadType)) { throw new ArgumentException(paramName: nameof(commadType), message: $"'{nameof(commadType)}' needs to be derived from '{nameof(ICommand)}'"); } var names = GetCommandNames(); var category = commadType.GetCustomAttribute <CategoryAttribute>()?.Category; if (category.IsNotNull()) { names = names.Select(n => SoftString.Create($"{category}.{n}")); } return(SoftKeySet.Create(names)); IEnumerable <SoftString> GetCommandNames() { yield return(GetCommandDefaultName(commadType)); foreach (var name in commadType.GetCustomAttribute <AliasAttribute>() ?? Enumerable.Empty <SoftString>()) { yield return(name); } } }
public static Identifier GetCommandId([NotNull] Type commandType) { if (commandType == null) { throw new ArgumentNullException(nameof(commandType)); } if (!typeof(IConsoleCommand).IsAssignableFrom(commandType)) { throw new ArgumentException( paramName: nameof(commandType), message: $"'{nameof(commandType)}' needs to be derived from '{nameof(ICommand)}'"); } return(CommandNameCache.GetOrAdd(commandType, t => { var category = t.GetCustomAttribute <CategoryAttribute>()?.Category; var names = GetCommandNames(t).Distinct(); return new Identifier( category is null ? names : names.SelectMany(name => new[] { name, SoftString.Create($"{category}.{name}") }) ); })); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jToken = JToken.Load(reader); var softString = jToken.Value <string>(); return(SoftString.Create(softString)); }
private IEnumerable <SoftString> GetComponents(SoftString scheme) { if (scheme) { yield return($"{scheme.ToString()}:"); } if (Authority) { yield return($"//{Authority.ToString()}{(Path.Original ? "/" : string.Empty)}"); } yield return(Path.Original); if (Query.Any()) { var queryPairs = Query .OrderBy(x => x.Key) .Select(x => $"{x.Key.ToString()}{(x.Value ? "=" : string.Empty)}{x.Value.ToString()}"); yield return($"?{string.Join("&", queryPairs)}"); } if (Fragment) { yield return($"#{Fragment.ToString()}"); } }
internal Logger([NotNull] SoftString name, [NotNull] LogPredicate logPredicate, Action dispose) { _name = name ?? throw new ArgumentNullException(nameof(name)); _logPredicate = logPredicate; _dispose = dispose; _observers = new HashSet <IObserver <ILog> >(); }
public void Add([NotNull] SoftString id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } Add((Identifier)id); }
private Func <HttpRequest, ResponseInfo> GetResponseFactory(UriString path, SoftString method) { if (_teacup is null) { throw new InvalidOperationException($"Cannot get response without scope. Call '{nameof(BeginScope)}' first."); } return(_teacup.GetResponseFactory(path, method)); }
public void Comparable_IsCanonical_True() { Assert.That.Comparable().IsCanonical( SoftString.Create("b"), SoftString.Create("a"), SoftString.Create("b"), SoftString.Create("c") ); }
public void Add([NotNull] SoftString id, [NotNull] string value) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } Add((Identifier)id, value); }
public static IImmutableDictionary <SoftString, Type> From(IEnumerable <Type> types) { return (( from type in types.Select(ValidateHasNoGenericArguments) // Pick the nearest namespace-attribute or one derived from it. let prefix = type.GetCustomAttributes <NamespaceAttribute>().FirstOrDefault()?.ToString() let prettyName = type.ToPrettyString() where !prettyName.IsDynamicType() //from name in new[] { prettyName, type.GetCustomAttribute<AliasAttribute>()?.ToString() } //where name.IsNotNullOrEmpty() select(type, prettyName: SoftString.Create((prefix.IsNullOrEmpty() ? string.Empty : $"{prefix}.") + prettyName)) ).ToImmutableDictionary(t => t.prettyName, t => t.type)); }
public void GetValue_StaticPropertyLocal_GotValue() { var configuration = Mock.Create <IConfiguration>(); Mock .Arrange(() => configuration.GetValue( Arg.Matches <SoftString>(name => name == SoftString.Create($"{Namespace}+TestClass.Bar")), Arg.IsAny <Type>(), Arg.IsAny <SoftString>()) ) .Returns("bar") .OccursOnce(); TestClass.AssertGetValueStatic(configuration); }
public void Select_SettingDoesNotExist_SettingNotFoundException() { Assert.That.ThrowsExceptionFiltered <DynamicException>(() => { var config = new Configuration(options => { options .UseJsonConverter() .UseInMemory(Enumerable.Empty <ISetting>()); }); config.Select <int>(SoftString.Create("abc")); Assert.Fail(); }, ex => ex.NameEquals("SettingNotFoundException")); }
public void GetValue_InstancePropertyLocal_GotValue() { var configuration = Mock.Create <IConfiguration>(); Mock .Arrange(() => configuration.GetValue( Arg.Matches <SoftString>(name => name == SoftString.Create($"{Namespace}+TestClass.Foo")), Arg.IsAny <Type>(), Arg.IsAny <SoftString>()) ) .Returns("foo") .OccursOnce(); var testClass = new TestClass(); testClass.AssertGetValue(configuration); }
public void GetValue_StaticProperty_GotValue() { var configuration = Mock.Create <IConfiguration>(); Mock .Arrange(() => configuration.GetValue( Arg.Matches <SoftString>(name => name == SoftString.Create($"{Namespace}+TestClass.Bar")), Arg.IsAny <Type>(), Arg.IsAny <SoftString>()) ) .Returns("bar") .OccursOnce(); var value = configuration.GetValueFor(() => TestClass.Bar); configuration.Assert(); Assert.AreEqual("bar", value); }
public void AssignValue_InstanceProperty_Assigned() { var configuration = Mock.Create <IConfiguration>(); Mock .Arrange(() => configuration.GetValue( Arg.Matches <SoftString>(name => name == SoftString.Create($"{Namespace}+TestClass.Foo")), Arg.IsAny <Type>(), Arg.IsAny <SoftString>()) ) .Returns("foo") .OccursOnce(); var testClass = new TestClass(); configuration.AssignValueTo(() => testClass.Foo); configuration.Assert(); Assert.AreEqual("foo", testClass.Foo); }
private NLog.ILogger GetLogger(SoftString name) { return(_cache.GetOrAdd(name, n => NLog.LogManager.GetLogger(name.ToString()))); }
internal static HtmlTableColumn Create <T>(SoftString name) => new HtmlTableColumn { Name = name, Type = typeof(T) };
public static T ValueOrDefault <T>(this HtmlTableRow row, SoftString name) => row[name] is T value ? value : default;
public HtmlTableCell this[SoftString name] => this.Single(cell => cell.Column.Name.Equals(name));
public Func <HttpRequest, ResponseInfo> GetResponseFactory(UriString uri, SoftString method) { return(_mocks.FirstOrDefault(m => m.Uri == uri)?.GetResponseFactory(method)); }
public UriStringComponent([NotNull] SoftString value) => Original = value ?? throw new ArgumentNullException(nameof(value));
public void opEqual_CanIdentifyDifferentValues() { Assert.That.BinaryOperator().Equality().IsFalse(SoftString.Create("foo"), "bar", " fOob"); }
public void Equals_CanIdentifyDifferentValues() { Assert.That.Equatable().EqualsMethod().IsFalse(SoftString.Create("foo"), "bar", "bar ", " bar", " bar "); }
public void Equals_CanIdentifySimilarValues() { Assert.That.Equatable().EqualsMethod().IsTrue(SoftString.Create("foo"), "foo", "fOo", "foo ", " fOo", " foo "); }
public void Length_GetsLengthOfTrimmedValue() { Assert.AreEqual(3, SoftString.Create(" fOo ").Length); }
public string ToString(SoftString scheme) => string.Join(string.Empty, GetComponents(scheme));
public void opExplicit_CanExplicitlyCastToString() { Assert.That.UnaryOperator().Convert(SoftString.Create("foo")).IsEqual("foo"); }
public void Equatable_IsCanonical_True() { Assert.That.Equatable().IsCanonical <SoftString>(SoftString.Create("foo")); Assert.That.Equatable().IsCanonical <string>(SoftString.Create("foo")); }
public void opEqual_CanIdentifySimilarValues() { Assert.That.BinaryOperator().Equality().IsTrue(default(SoftString), default(string)); Assert.That.BinaryOperator().Equality().IsTrue(SoftString.Create("foo"), "foo", "fOo", "foo ", " fOo", " foo "); }
public void opImplicit_CanImplicitlyCastFromString() { Assert.That.UnaryOperator().Convert("foo").IsEqual(SoftString.Create("foo")); }