public void CanEquate_AgainstString() { // Arrange var moduleId = new ModuleId("module"); var id = new FeatureId(moduleId, "feature"); // Act bool equate0 = id.Equals((string)null); bool equate1 = id.Equals("module.feature"); bool equate2 = id.Equals("module.aaaa"); // Assert Assert.False(equate0); Assert.True(equate1); Assert.False(equate2); }
public void CanEquate_AgainstFeatureId() { // Arrange var moduleId = new ModuleId("module"); var id = new FeatureId(moduleId, "feature"); // Act bool equate0 = id.Equals(FeatureId.Empty); bool equate1 = id.Equals(new FeatureId(moduleId, "feature")); bool equate2 = id.Equals(new FeatureId(moduleId, "aaaa")); // Assert Assert.False(equate0); Assert.True(equate1); Assert.False(equate2); }
/// <summary> /// Resolves the feature id value. /// </summary> /// <param name="parentModuleId"></param> /// <param name="parentFeatureId"></param> /// <param name="value"></param> /// <returns></returns> private static string ResolveValue(ModuleId parentModuleId, FeatureId parentFeatureId, string value) { if (parentFeatureId.Equals(FeatureId.Empty)) { return($"{parentModuleId.Value}.{value}"); } return($"{parentFeatureId.Value}.{value}"); }
/// <inheritdoc /> public FeatureState GetFeatureState(FeatureId featureId) { if (featureId.Equals(FeatureId.Empty)) { throw new ArgumentException("The feature id must be provided and cannot be FeatureId.Empty", nameof(featureId)); } return(_store.GetOrAdd(featureId, GetFeatureStateCore)); }
/// <summary> /// Initialises a new instance of <see cref="FeatureBase"/>. /// </summary> /// <param name="id">The feature id.</param> /// <param name="name">[Optional] The feature name.</param> /// <param name="description">[Optional] The feature description.</param> /// <param name="enabledByDefault">[Optional] Default enabled state.</param> protected FeatureBase(FeatureId id, string name = null, string description = null, bool enabledByDefault = false) { if (id.Equals(FeatureId.Empty)) { throw new ArgumentException("The feature id value must be provided", nameof(id)); } Id = id; Name = name; Description = description; EnabledByDefault = enabledByDefault; }
public void WhenEquating_UsewCaseInsensitiveCompare() { // Arrange var moduleId = new ModuleId("module"); var id = new FeatureId(moduleId, "feature"); // Act bool equals = id.Equals(new FeatureId(moduleId, "FEATURE")); // Assert Assert.True(equals); }
/// <summary> /// Initialises a new instance of <see cref="FeatureId"/>. /// </summary> /// <param name="sourceModuleId">The source module id.</param> /// <param name="parentFeatureId">The parent feature id.</param> /// <param name="value">The feature id value.</param> public FeatureId(ModuleId sourceModuleId, FeatureId parentFeatureId, string value) { if (sourceModuleId.Equals(ModuleId.Empty)) { throw new ArgumentException("The source module id must be provided and cannot be ModuleId.Empty", nameof(sourceModuleId)); } if (parentFeatureId.Equals(Empty)) { throw new ArgumentException("The parent feature id must be provided and cannot be FeatureId.Empty", nameof(parentFeatureId)); } HasValue = true; ParentModuleId = parentFeatureId.ParentModuleId; SourceModuleId = sourceModuleId; _parentFeatureIdThunk = new Lazy <FeatureId>(() => parentFeatureId); LocalValue = Ensure.IsNotNullOrEmpty(value, nameof(value)); Value = ResolveValue(ParentModuleId, parentFeatureId, value); }
/// <inheritdoc /> public IFeature GetFeature(FeatureId featureId) => Features.FirstOrDefault(f => featureId.Equals(f.Id));