Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
Back to 100 percent coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Muc committed Aug 13, 2009
1 parent f8ec434 commit cd6922c
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/Secretary.Samples/SampleSetup.cs
Expand Up @@ -52,7 +52,6 @@ public void Setup()
var test3 = FileLocator.Find(FileType.Audio).Named("Test.mp3").For(testArtist);

Assert.Equal(@"C:\test\music\1\Test.mp3", test3);

}
}
}
1 change: 0 additions & 1 deletion src/Secretary.UnitTests/FileLocatorTests.cs
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using Xunit;

Expand Down
19 changes: 19 additions & 0 deletions src/Secretary.UnitTests/LocationQueryTests.cs
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using Xunit;

namespace Secretary.UnitTests
{
public class LocationQueryTests
{
[Fact]
public void For_GivenNoSpecializedSecretaries_ShouldThrowNullReferenceException()
{
var sut = new LocationQuery {Secretaries = new List<Secretary>()};

Assert.Throws<NullReferenceException>(
() => sut.For(new TestEntity() { Id = 1 })
);
}
}
}
2 changes: 2 additions & 0 deletions src/Secretary.UnitTests/Secretary.UnitTests.csproj
Expand Up @@ -58,9 +58,11 @@
<Compile Include="FileTypeTests.cs" />
<Compile Include="GraduationCeremonyTests.cs" />
<Compile Include="LocalFileReferenceTests.cs" />
<Compile Include="LocationQueryTests.cs" />
<Compile Include="SchoolTests.cs" />
<Compile Include="SecretaryTests.cs" />
<Compile Include="SpecializationCollectionTests.cs" />
<Compile Include="SpecializationKeyTests.cs" />
<Compile Include="TestEntity.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
39 changes: 39 additions & 0 deletions src/Secretary.UnitTests/SpecializationKeyTests.cs
@@ -0,0 +1,39 @@
using Xunit;

namespace Secretary.UnitTests
{
public class SpecializationKeyTests
{
[Fact]
public void Equals_GivenKeyWithDifferentFileType_ShouldReturnFalse()
{
var key = new SpecializationKey(typeof (TestEntity), FileType.Default);
var other = new SpecializationKey(typeof(TestEntity), FileType.Image);

var result = key.Equals(other);

Assert.False(result);
}

[Fact]
public void Equals_GivenNullObject_ShouldReturnFalse()
{
var key = new SpecializationKey(typeof(TestEntity), FileType.Default);

var result = key.Equals(null as object);

Assert.False(result);
}

[Fact]
public void GetHashCode_IsComputedFromTypeAndFileType()
{
var key = new SpecializationKey(typeof(TestEntity), FileType.Default);
var expectedHashCode = typeof(TestEntity).GetHashCode() ^ FileType.Default.GetHashCode();

var hashcode = key.GetHashCode();

Assert.Equal(expectedHashCode, hashcode);
}
}
}
1 change: 1 addition & 0 deletions src/Secretary/FileType.cs
Expand Up @@ -7,6 +7,7 @@ public class FileType
public static FileType File = new FileType("File");
public static FileType Image = new FileType("Image");
public static FileType Audio = new FileType("Audio");
public static FileType Default = File;

public FileType(string name)
: this(name, path => new LocalFileReference(path))
Expand Down
5 changes: 2 additions & 3 deletions src/Secretary/IFluentInterface.cs
Expand Up @@ -4,9 +4,8 @@
namespace Secretary
{
/// <summary>
/// Helper interface used to hide the base <see cref="Object"/>
/// members from the fluent API to make for much cleaner
/// Visual Studio intellisense experience.
/// Based on the fluent interface API design by Daniel Cazzulino
/// http://www.clariusconsulting.net/blogs/kzu/archive/2008/03/10/58301.aspx
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IFluentInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Secretary/School.cs
Expand Up @@ -11,7 +11,7 @@ public class School
private readonly IList<Enrollment> enrollments;

public School(string name, string folderToTeach)
: this(name, folderToTeach, new List<Enrollment>(), new SpecializationCollection { DefaultFileType = FileType.File })
: this(name, folderToTeach, new List<Enrollment>(), new SpecializationCollection())
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/Secretary/SpecializationCollection.cs
Expand Up @@ -17,7 +17,7 @@ public SpecializationCollection()
private SpecializationCollection(IDictionary<SpecializationKey, object> specializations)
{
this.specializations = specializations;
DefaultFileType = FileType.File;
DefaultFileType = FileType.Default;
}

public void Add<TENTITY>(Func<TENTITY, string> pathDelegate)
Expand Down
2 changes: 1 addition & 1 deletion src/Secretary/SpecializationKey.cs
Expand Up @@ -10,7 +10,7 @@ public class SpecializationKey
public FileType FileType { get; private set; }

public SpecializationKey(Type entityType, FileType fileType)
{
{
FileType = fileType;
SpecializationType = entityType;

Expand Down
18 changes: 14 additions & 4 deletions src/Secretary/Syntax.cs
@@ -1,21 +1,31 @@
using System.ComponentModel;

// Influence by Funq Screencasts
// http://www.clariusconsulting.net/blogs/kzu/archive/2009/02/02/116399.aspx
namespace Secretary
{
public interface IEnrollment : IFluentInterface, IEnrolledFor
{
IEnrolledFor SpecializingIn(FileType fileType);
}
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IEnrollment : ISpecializedIn, IEnrolledFor { }

[EditorBrowsable(EditorBrowsableState.Never)]
public interface IEnrolledFor : IFluentInterface
{
void For<TEntity>();
}

[EditorBrowsable(EditorBrowsableState.Never)]
public interface ISpecializedIn : IFluentInterface
{
IEnrolledFor SpecializingIn(FileType fileType);
}

[EditorBrowsable(EditorBrowsableState.Never)]
public interface ILocationQuery : IFluentInterface
{
INamed Named(string fileName);
}

[EditorBrowsable(EditorBrowsableState.Never)]
public interface INamed : IFluentInterface
{
string For<TEntity>(TEntity entity);
Expand Down

0 comments on commit cd6922c

Please sign in to comment.