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

Commit

Permalink
Finalized fluent api for Locate
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Muc committed Sep 10, 2009
1 parent eb46792 commit 3ba82ee
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/Secretary.UnitTests/LocateTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.Collections.Generic;
using Xunit;

namespace Secretary.UnitTests
{
public class LocateTests
public class LocateTests : IDisposable
{
[Fact]
public void IsInitialized_GivenACollectionOfSecretaries_ShouldReturnTrue()
Expand All @@ -20,5 +21,11 @@ public void Usage_WhenUninitialized_ShouldThrowException()
{
Assert.Throws<LocatorUnitializedException>(() => Locate.FolderForType(FileType.Image));
}


public void Dispose()
{
Locate.Reset();
}
}
}
6 changes: 3 additions & 3 deletions src/Secretary/FileLocationQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Secretary
{
public class FileLocationQuery : LocationQueryBase, IFileLocationQuery
public class FileLocationQuery : LocationQueryBase, IFileLocationQuery, IInLocation, IForEntity
{
public string FileName { get; private set; }

Expand All @@ -11,13 +11,13 @@ public FileLocationQuery(string fileName)
FileName = fileName;
}

public FileLocationQuery Of(FileType fileType)
public IInLocation Of(FileType fileType)
{
FileType = fileType;
return this;
}

public FileLocationQuery In(Location location)
public IForEntity In(Location location)
{
LocationContext = location;
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/Secretary/FolderLocationQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Secretary
{
public class FolderLocationQuery : LocationQueryBase, IFolderLocationQuery
public class FolderLocationQuery : LocationQueryBase, IFolderLocationQuery, IForEntity
{
public FolderLocationQuery(FileType fileType)
{
this.FileType = fileType;
}

public FolderLocationQuery In(Location location)
public IForEntity In(Location location)
{
this.LocationContext = location;
return this;
Expand Down
9 changes: 7 additions & 2 deletions src/Secretary/Locate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public static bool IsInitialized
get { return (Secretaries != null); }
}

public static void Reset()
{
Secretaries = null;
}

private static void GuardAgainstUninitializedUsage()
{
if (!IsInitialized)
Expand All @@ -38,7 +43,7 @@ private static void GuardAgainstUninitializedUsage()
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static FileLocationQuery File(string fileName)
public static IFileLocationQuery File(string fileName)
{
GuardAgainstUninitializedUsage();

Expand All @@ -53,7 +58,7 @@ public static FileLocationQuery File(string fileName)
/// </summary>
/// <param name="fileType"></param>
/// <returns></returns>
public static FolderLocationQuery FolderForType(FileType fileType)
public static IFolderLocationQuery FolderForType(FileType fileType)
{
GuardAgainstUninitializedUsage();

Expand Down
18 changes: 17 additions & 1 deletion src/Secretary/Syntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ public interface ISpecializedIn : IFluentInterface
IEnrolledFor SpecializingIn(FileType fileType);
}


/// <summary>
/// Beginning of a file location query
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IFileLocationQuery : IFluentInterface
{
IInLocation Of(FileType fileType);
}

[EditorBrowsable(EditorBrowsableState.Never)]
public interface IInLocation : IFluentInterface
{
IForEntity In(Location fileLocation);
}

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


[EditorBrowsable(EditorBrowsableState.Never)]
public interface IFolderLocationQuery : IFluentInterface
{
string For<TEntity>(TEntity entity);
IForEntity In(Location fileLocation);
}
}

0 comments on commit 3ba82ee

Please sign in to comment.