Skip to content

Commit

Permalink
Made API a bit more clean by using IEnumerable.
Browse files Browse the repository at this point in the history
[release]
Lakritzator committed Dec 7, 2016
1 parent 395368e commit da04abb
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Dapplo.ActiveDirectory.Tests/DistinguishedNameTests.cs
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public void TestBuildDistinguishedName()
{
var dn = DistinguishedName.Create().Cn("Karen Berge").Cn("admin").Dc("corp").Dc("Fabrikam").Dc("COM");

Assert.Equal(5, dn.RelativeDistinguishedNames.Count);
Assert.Equal(5, dn.RelativeDistinguishedNames.Count());
Assert.Equal(TestDnString, dn.ToString());

var dc = string.Join(".", dn.Where(x => x.Key == DistinguishedNameAttributes.DomainComponent).Select(x => x.Value));
@@ -61,15 +61,15 @@ public void TestBuildDistinguishedName()
public void TestCastDistinguishedName()
{
var dn = (DistinguishedName) TestDnString;
Assert.Equal(5, dn.RelativeDistinguishedNames.Count);
Assert.Equal(5, dn.RelativeDistinguishedNames.Count());
Assert.Equal(TestDnString, dn);
}

[Fact]
public void TestDistinguishedName()
{
var dn = DistinguishedName.CreateFrom(TestDnString);
Assert.Equal(5, dn.RelativeDistinguishedNames.Count);
Assert.Equal(5, dn.RelativeDistinguishedNames.Count());
Assert.Equal(TestDnString, dn.ToString());
}
}
5 changes: 4 additions & 1 deletion Dapplo.ActiveDirectory/Dapplo.ActiveDirectory.csproj
Original file line number Diff line number Diff line change
@@ -42,12 +42,15 @@
<Private>True</Private>
</Reference>
<Reference Include="Dapplo.Utils, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Dapplo.Utils.1.0.128\lib\net45\Dapplo.Utils.dll</HintPath>
<HintPath>..\packages\Dapplo.Utils.1.0.130\lib\net45\Dapplo.Utils.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>
<ItemGroup>
14 changes: 8 additions & 6 deletions Dapplo.ActiveDirectory/Entities/DistinguishedName.cs
Original file line number Diff line number Diff line change
@@ -50,6 +50,8 @@ static DistinguishedName()
}
}

private readonly List<KeyValuePair<DistinguishedNameAttributes, string>> _relativeDistinguishedNames = new List<KeyValuePair<DistinguishedNameAttributes, string>>();

/// <summary>
/// Made private to force factory method
/// </summary>
@@ -60,15 +62,15 @@ private DistinguishedName()
/// <summary>
/// List of the distinguished names, this is just the collection of all available dn's
/// </summary>
public IList<KeyValuePair<DistinguishedNameAttributes, string>> RelativeDistinguishedNames { get; } = new List<KeyValuePair<DistinguishedNameAttributes, string>>();
public IEnumerable<KeyValuePair<DistinguishedNameAttributes, string>> RelativeDistinguishedNames => _relativeDistinguishedNames.AsReadOnly();

/// <summary>
/// Enumerator for the destinguished names
/// </summary>
/// <returns>IEnumerator</returns>
public IEnumerator<KeyValuePair<DistinguishedNameAttributes, string>> GetEnumerator()
{
return RelativeDistinguishedNames.GetEnumerator();
return _relativeDistinguishedNames.GetEnumerator();
}

/// <summary>
@@ -77,7 +79,7 @@ public IEnumerator<KeyValuePair<DistinguishedNameAttributes, string>> GetEnumera
/// <returns>IEnumerator</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return RelativeDistinguishedNames.GetEnumerator();
return _relativeDistinguishedNames.GetEnumerator();
}

/// <summary>
@@ -92,7 +94,7 @@ public DistinguishedName Add(DistinguishedNameAttributes distinguishedNameAttrib
{
throw new ArgumentNullException(nameof(value));
}
RelativeDistinguishedNames.Add(new KeyValuePair<DistinguishedNameAttributes, string>(distinguishedNameAttribute, value.Trim()));
_relativeDistinguishedNames.Add(new KeyValuePair<DistinguishedNameAttributes, string>(distinguishedNameAttribute, value.Trim()));
return this;
}

@@ -108,7 +110,7 @@ public DistinguishedName Add(string relativeDistinguishedName)
throw new ArgumentNullException(nameof(relativeDistinguishedName));
}
var parts = relativeDistinguishedName.Split('=');
RelativeDistinguishedNames.Add(new KeyValuePair<DistinguishedNameAttributes, string>(AttributeLookup[parts[0].Trim()],parts[1].Trim()));
_relativeDistinguishedNames.Add(new KeyValuePair<DistinguishedNameAttributes, string>(AttributeLookup[parts[0].Trim()],parts[1].Trim()));
return this;
}

@@ -206,7 +208,7 @@ public override string ToString()
builder.Append($"{relativeDistinguishedName.Key.EnumValueOf()}={relativeDistinguishedName.Value},");
}
// Remote trailing ,
if (RelativeDistinguishedNames.Count > 0)
if (_relativeDistinguishedNames.Any())
{
builder.Length -= 1;
}
2 changes: 1 addition & 1 deletion Dapplo.ActiveDirectory/packages.config
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@
<packages>
<package id="Dapplo.InterfaceImpl" version="0.2.5" targetFramework="net45" />
<package id="Dapplo.Log" version="1.0.22" targetFramework="net45" />
<package id="Dapplo.Utils" version="1.0.128" targetFramework="net45" />
<package id="Dapplo.Utils" version="1.0.130" targetFramework="net45" />
</packages>

0 comments on commit da04abb

Please sign in to comment.