diff options
| author | mo khan <mo.khan@gmail.com> | 2019-10-20 19:47:59 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-10-20 19:47:59 -0600 |
| commit | cc4b5d12c761b7322d8db928e5ff485fb8fd06f7 (patch) | |
| tree | 3ec7edde86cedc75f9bf8c6a76d3b1169afcc345 | |
| parent | 0a7ddbc3baad14ccb2bb2a1069fd13228cf83a58 (diff) | |
Rename gorilla to jive
133 files changed, 3341 insertions, 3647 deletions
diff --git a/lib/infrastructure/cloning/BinarySerializer.cs b/lib/infrastructure/cloning/BinarySerializer.cs index 1fab937..2e5ff2a 100644 --- a/lib/infrastructure/cloning/BinarySerializer.cs +++ b/lib/infrastructure/cloning/BinarySerializer.cs @@ -1,11 +1,11 @@ -using System.Runtime.Serialization.Formatters.Binary;
-
-namespace gorilla.infrastructure.cloning
-{
- public class BinarySerializer<T> : FileStreamSerializer<T>
- {
- public BinarySerializer(string file_path) : base(file_path, new BinaryFormatter())
- {
- }
- }
-}
\ No newline at end of file +using System.Runtime.Serialization.Formatters.Binary; + +namespace jive.infrastructure.cloning +{ + public class BinarySerializer<T> : FileStreamSerializer<T> + { + public BinarySerializer(string file_path) : base(file_path, new BinaryFormatter()) + { + } + } +} diff --git a/lib/infrastructure/cloning/FileStreamSerializer.cs b/lib/infrastructure/cloning/FileStreamSerializer.cs index 1cecbdf..07e8673 100644 --- a/lib/infrastructure/cloning/FileStreamSerializer.cs +++ b/lib/infrastructure/cloning/FileStreamSerializer.cs @@ -1,34 +1,34 @@ -using System.IO;
-using System.Runtime.Serialization;
-
-namespace gorilla.infrastructure.cloning
-{
- public class FileStreamSerializer<T> : Serializer<T>
- {
- public FileStreamSerializer(string file_path, IFormatter formatter)
- {
- this.file_path = file_path;
- this.formatter = formatter;
- }
-
- public void serialize(T to_serialize)
- {
- using (var stream = new FileStream(file_path, FileMode.Create, FileAccess.Write))
- formatter.Serialize(stream, to_serialize);
- }
-
- public T deserialize()
- {
- using (var stream = new FileStream(file_path, FileMode.Open, FileAccess.Read))
- return (T) formatter.Deserialize(stream);
- }
-
- public void Dispose()
- {
- File.Delete(file_path);
- }
-
- readonly string file_path;
- readonly IFormatter formatter;
- }
-}
\ No newline at end of file +using System.IO; +using System.Runtime.Serialization; + +namespace jive.infrastructure.cloning +{ + public class FileStreamSerializer<T> : Serializer<T> + { + public FileStreamSerializer(string file_path, IFormatter formatter) + { + this.file_path = file_path; + this.formatter = formatter; + } + + public void serialize(T to_serialize) + { + using (var stream = new FileStream(file_path, FileMode.Create, FileAccess.Write)) + formatter.Serialize(stream, to_serialize); + } + + public T deserialize() + { + using (var stream = new FileStream(file_path, FileMode.Open, FileAccess.Read)) + return (T) formatter.Deserialize(stream); + } + + public void Dispose() + { + File.Delete(file_path); + } + + readonly string file_path; + readonly IFormatter formatter; + } +} diff --git a/lib/infrastructure/cloning/Prototype.cs b/lib/infrastructure/cloning/Prototype.cs index 497796b..1cc159f 100644 --- a/lib/infrastructure/cloning/Prototype.cs +++ b/lib/infrastructure/cloning/Prototype.cs @@ -1,21 +1,21 @@ -using System.IO;
-
-namespace gorilla.infrastructure.cloning
-{
- public interface IPrototype
- {
- T clone<T>(T item);
- }
-
- public class Prototype : IPrototype
- {
- public T clone<T>(T item)
- {
- using (var serializer = new BinarySerializer<T>(Path.GetTempFileName()))
- {
- serializer.serialize(item);
- return serializer.deserialize();
- }
- }
- }
-}
\ No newline at end of file +using System.IO; + +namespace jive.infrastructure.cloning +{ + public interface IPrototype + { + T clone<T>(T item); + } + + public class Prototype : IPrototype + { + public T clone<T>(T item) + { + using (var serializer = new BinarySerializer<T>(Path.GetTempFileName())) + { + serializer.serialize(item); + return serializer.deserialize(); + } + } + } +} diff --git a/lib/infrastructure/cloning/Serializer.cs b/lib/infrastructure/cloning/Serializer.cs index f8a761f..dcefa77 100644 --- a/lib/infrastructure/cloning/Serializer.cs +++ b/lib/infrastructure/cloning/Serializer.cs @@ -1,10 +1,10 @@ -using System;
-
-namespace gorilla.infrastructure.cloning
-{
- public interface Serializer<T> : IDisposable
- {
- void serialize(T to_serialize);
- T deserialize();
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.cloning +{ + public interface Serializer<T> : IDisposable + { + void serialize(T to_serialize); + T deserialize(); + } +} diff --git a/lib/infrastructure/container/DependencyRegistry.cs b/lib/infrastructure/container/DependencyRegistry.cs index 6ab1fb4..6a615ce 100644 --- a/lib/infrastructure/container/DependencyRegistry.cs +++ b/lib/infrastructure/container/DependencyRegistry.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic;
-
-namespace gorilla.infrastructure.container
-{
- public interface DependencyRegistry
- {
- Contract get_a<Contract>();
- IEnumerable<Contract> get_all<Contract>();
- }
-}
\ No newline at end of file +using System.Collections.Generic; + +namespace jive.infrastructure.container +{ + public interface DependencyRegistry + { + Contract get_a<Contract>(); + IEnumerable<Contract> get_all<Contract>(); + } +} diff --git a/lib/infrastructure/container/DependencyResolutionException.cs b/lib/infrastructure/container/DependencyResolutionException.cs index 4de7e4a..8a7b753 100644 --- a/lib/infrastructure/container/DependencyResolutionException.cs +++ b/lib/infrastructure/container/DependencyResolutionException.cs @@ -1,13 +1,13 @@ -using System;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.container
-{
- public class DependencyResolutionException<T> : Exception
- {
- public DependencyResolutionException(Exception inner_exception)
- : base("Could not resolve {0}".format(typeof (T).FullName), inner_exception)
- {
- }
- }
-}
\ No newline at end of file +using System; +using jive.utility; + +namespace jive.infrastructure.container +{ + public class DependencyResolutionException<T> : Exception + { + public DependencyResolutionException(Exception inner_exception) + : base("Could not resolve {0}".format(typeof (T).FullName), inner_exception) + { + } + } +} diff --git a/lib/infrastructure/container/Resolve.cs b/lib/infrastructure/container/Resolve.cs index dae7414..24b452c 100644 --- a/lib/infrastructure/container/Resolve.cs +++ b/lib/infrastructure/container/Resolve.cs @@ -1,33 +1,33 @@ -using System;
-
-namespace gorilla.infrastructure.container
-{
- static public class Resolve
- {
- static DependencyRegistry underlying_registry;
- static bool initialized;
-
- static public void initialize_with(DependencyRegistry registry)
- {
- underlying_registry = registry;
- initialized = registry != null;
- }
-
- static public DependencyToResolve the<DependencyToResolve>()
- {
- try
- {
- return underlying_registry.get_a<DependencyToResolve>();
- }
- catch (Exception e)
- {
- throw new DependencyResolutionException<DependencyToResolve>(e);
- }
- }
-
- static public bool is_initialized()
- {
- return initialized;
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.container +{ + static public class Resolve + { + static DependencyRegistry underlying_registry; + static bool initialized; + + static public void initialize_with(DependencyRegistry registry) + { + underlying_registry = registry; + initialized = registry != null; + } + + static public DependencyToResolve the<DependencyToResolve>() + { + try + { + return underlying_registry.get_a<DependencyToResolve>(); + } + catch (Exception e) + { + throw new DependencyResolutionException<DependencyToResolve>(e); + } + } + + static public bool is_initialized() + { + return initialized; + } + } +} diff --git a/lib/infrastructure/infrastructure.csproj b/lib/infrastructure/infrastructure.csproj deleted file mode 100644 index 1a34d65..0000000 --- a/lib/infrastructure/infrastructure.csproj +++ /dev/null @@ -1,151 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>gorilla.infrastructure</RootNamespace>
- <AssemblyName>gorilla.infrastructure</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- <TargetFrameworkProfile />
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="cloning\BinarySerializer.cs" />
- <Compile Include="cloning\Serializer.cs" />
- <Compile Include="cloning\Prototype.cs" />
- <Compile Include="cloning\FileStreamSerializer.cs" />
- <Compile Include="container\DependencyResolutionException.cs" />
- <Compile Include="container\DependencyRegistry.cs" />
- <Compile Include="container\Resolve.cs" />
- <Compile Include="logging\TextLogger.cs" />
- <Compile Include="logging\LogFactory.cs" />
- <Compile Include="logging\Loggable.cs" />
- <Compile Include="logging\Logger.cs" />
- <Compile Include="logging\Log.cs" />
- <Compile Include="logging\LoggingExtensions.cs" />
- <Compile Include="proxies\ExceptionExtensions.cs" />
- <Compile Include="proxies\Interceptor.cs" />
- <Compile Include="proxies\Invocation.cs" />
- <Compile Include="proxies\MethodCallInvocation.cs" />
- <Compile Include="proxies\ProxyFactory.cs" />
- <Compile Include="proxies\RemotingProxyFactory.cs" />
- <Compile Include="reflection\ApplicationAssembly.cs" />
- <Compile Include="reflection\EnvironmentExtensions.cs" />
- <Compile Include="reflection\Assembly.cs" />
- <Compile Include="registries\DefaultRegistry.cs" />
- <Compile Include="threading\AsynchronousCommandProcessor.cs" />
- <Compile Include="threading\BackgroundThread.cs" />
- <Compile Include="threading\ITimerFactory.cs" />
- <Compile Include="threading\Timer.cs" />
- <Compile Include="threading\WorkderBackgroundThread.cs" />
- <Compile Include="threading\BackgroundThreadFactory.cs" />
- <Compile Include="threading\CommandProcessor.cs" />
- <Compile Include="threading\CurrentThread.cs" />
- <Compile Include="threading\IntervalTimer.cs" />
- <Compile Include="threading\ApplicationThread.cs" />
- <Compile Include="threading\TimerClient.cs" />
- <Compile Include="threading\IWorkerThread.cs" />
- <Compile Include="threading\PerThread.cs" />
- <Compile Include="threading\PerThreadScopedStorage.cs" />
- <Compile Include="threading\SynchronizationContextFactory.cs" />
- <Compile Include="threading\SynchronizedCommand.cs" />
- <Compile Include="threading\SynchronizedContext.cs" />
- <Compile Include="threading\SynchronousCommandProcessor.cs" />
- <Compile Include="threading\ThreadingExtensions.cs" />
- <Compile Include="threading\TimerFactory.cs" />
- <Compile Include="threading\WorkerThread.cs">
- <SubType>Component</SubType>
- </Compile>
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\utility\utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>utility</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - -->
-</Project>
\ No newline at end of file diff --git a/lib/infrastructure/logging/Log.cs b/lib/infrastructure/logging/Log.cs index c680358..19d6626 100644 --- a/lib/infrastructure/logging/Log.cs +++ b/lib/infrastructure/logging/Log.cs @@ -1,25 +1,25 @@ -using System;
-using gorilla.infrastructure.container;
-
-namespace gorilla.infrastructure.logging
-{
- static public class Log
- {
- static public Logger For<T>(T item_to_create_logger_for)
- {
- return For(typeof (T));
- }
-
- static public Logger For(Type type_to_create_a_logger_for)
- {
- try
- {
- return Resolve.the<LogFactory>().create_for(type_to_create_a_logger_for);
- }
- catch
- {
- return new TextLogger(Console.Out);
- }
- }
- }
-}
\ No newline at end of file +using System; +using jive.infrastructure.container; + +namespace jive.infrastructure.logging +{ + static public class Log + { + static public Logger For<T>(T item_to_create_logger_for) + { + return For(typeof (T)); + } + + static public Logger For(Type type_to_create_a_logger_for) + { + try + { + return Resolve.the<LogFactory>().create_for(type_to_create_a_logger_for); + } + catch + { + return new TextLogger(Console.Out); + } + } + } +} diff --git a/lib/infrastructure/logging/LogFactory.cs b/lib/infrastructure/logging/LogFactory.cs index d6f25fe..4b3eade 100644 --- a/lib/infrastructure/logging/LogFactory.cs +++ b/lib/infrastructure/logging/LogFactory.cs @@ -1,9 +1,9 @@ -using System;
-
-namespace gorilla.infrastructure.logging
-{
- public interface LogFactory
- {
- Logger create_for(Type type_to_create_logger_for);
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.logging +{ + public interface LogFactory + { + Logger create_for(Type type_to_create_logger_for); + } +} diff --git a/lib/infrastructure/logging/Loggable.cs b/lib/infrastructure/logging/Loggable.cs index 80b36d3..a36fa0b 100644 --- a/lib/infrastructure/logging/Loggable.cs +++ b/lib/infrastructure/logging/Loggable.cs @@ -1,7 +1,6 @@ -namespace gorilla.infrastructure.logging
-{
- public interface Loggable
- {
-
- }
-}
\ No newline at end of file +namespace jive.infrastructure.logging +{ + public interface Loggable + { + } +} diff --git a/lib/infrastructure/logging/Logger.cs b/lib/infrastructure/logging/Logger.cs index f5dd7a6..4cbc732 100644 --- a/lib/infrastructure/logging/Logger.cs +++ b/lib/infrastructure/logging/Logger.cs @@ -1,11 +1,11 @@ -using System;
-
-namespace gorilla.infrastructure.logging
-{
- public interface Logger
- {
- void informational(string formatted_string, params object[] arguments);
- void debug(string formatted_string, params object[] arguments);
- void error(Exception e);
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.logging +{ + public interface Logger + { + void informational(string formatted_string, params object[] arguments); + void debug(string formatted_string, params object[] arguments); + void error(Exception e); + } +} diff --git a/lib/infrastructure/logging/LoggingExtensions.cs b/lib/infrastructure/logging/LoggingExtensions.cs index 90aaa19..29b8eeb 100644 --- a/lib/infrastructure/logging/LoggingExtensions.cs +++ b/lib/infrastructure/logging/LoggingExtensions.cs @@ -1,17 +1,17 @@ -using System;
-
-namespace gorilla.infrastructure.logging
-{
- public static class LoggingExtensions
- {
- public static Logger log<T>(this T item_to_log)
- {
- return Log.For(item_to_log);
- }
-
- public static void add_to_log(this Exception error_to_log)
- {
- Log.For(error_to_log).error(error_to_log);
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.logging +{ + public static class LoggingExtensions + { + public static Logger log<T>(this T item_to_log) + { + return Log.For(item_to_log); + } + + public static void add_to_log(this Exception error_to_log) + { + Log.For(error_to_log).error(error_to_log); + } + } +} diff --git a/lib/infrastructure/logging/TextLogger.cs b/lib/infrastructure/logging/TextLogger.cs index f9dd3ae..904467a 100644 --- a/lib/infrastructure/logging/TextLogger.cs +++ b/lib/infrastructure/logging/TextLogger.cs @@ -1,33 +1,33 @@ -using System;
-using System.IO;
-using System.Threading;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.logging
-{
- public class TextLogger : Logger
- {
- readonly TextWriter writer;
-
- public TextLogger(TextWriter writer)
- {
- this.writer = writer;
- }
-
- public void informational(string formatted_string, params object[] arguments)
- {
- writer.WriteLine(formatted_string, arguments);
- }
-
- public void debug(string formatted_string, params object[] arguments)
- {
- writer.WriteLine("[{0}] - {1}", Thread.CurrentThread.ManagedThreadId,
- formatted_string.format(arguments));
- }
-
- public void error(Exception e)
- {
- writer.WriteLine("{0}", e);
- }
- }
-}
\ No newline at end of file +using System; +using System.IO; +using System.Threading; +using jive.utility; + +namespace jive.infrastructure.logging +{ + public class TextLogger : Logger + { + readonly TextWriter writer; + + public TextLogger(TextWriter writer) + { + this.writer = writer; + } + + public void informational(string formatted_string, params object[] arguments) + { + writer.WriteLine(formatted_string, arguments); + } + + public void debug(string formatted_string, params object[] arguments) + { + writer.WriteLine("[{0}] - {1}", Thread.CurrentThread.ManagedThreadId, + formatted_string.format(arguments)); + } + + public void error(Exception e) + { + writer.WriteLine("{0}", e); + } + } +} diff --git a/lib/infrastructure/proxies/ExceptionExtensions.cs b/lib/infrastructure/proxies/ExceptionExtensions.cs index 58e6b41..7b7b4d5 100644 --- a/lib/infrastructure/proxies/ExceptionExtensions.cs +++ b/lib/infrastructure/proxies/ExceptionExtensions.cs @@ -1,18 +1,18 @@ -using System;
-using System.Reflection;
-
-namespace gorilla.infrastructure.proxies
-{
- static public class ExceptionExtensions
- {
- static readonly MethodInfo method =
- typeof (Exception).GetMethod("InternalPreserveStackTrace",
- BindingFlags.NonPublic | BindingFlags.Instance);
-
- static public Exception preserve_stack_trace(this Exception exception)
- {
- method.Invoke(exception, new object[0]);
- return exception;
- }
- }
-}
\ No newline at end of file +using System; +using System.Reflection; + +namespace jive.infrastructure.proxies +{ + static public class ExceptionExtensions + { + static readonly MethodInfo method = + typeof (Exception).GetMethod("InternalPreserveStackTrace", + BindingFlags.NonPublic | BindingFlags.Instance); + + static public Exception preserve_stack_trace(this Exception exception) + { + method.Invoke(exception, new object[0]); + return exception; + } + } +} diff --git a/lib/infrastructure/proxies/Interceptor.cs b/lib/infrastructure/proxies/Interceptor.cs index bb22f84..9cf2dc1 100644 --- a/lib/infrastructure/proxies/Interceptor.cs +++ b/lib/infrastructure/proxies/Interceptor.cs @@ -1,7 +1,7 @@ -namespace gorilla.infrastructure.proxies
-{
- public interface Interceptor
- {
- void intercept(Invocation invocation);
- }
-}
\ No newline at end of file +namespace jive.infrastructure.proxies +{ + public interface Interceptor + { + void intercept(Invocation invocation); + } +} diff --git a/lib/infrastructure/proxies/Invocation.cs b/lib/infrastructure/proxies/Invocation.cs index 8ae84e8..8530050 100644 --- a/lib/infrastructure/proxies/Invocation.cs +++ b/lib/infrastructure/proxies/Invocation.cs @@ -1,12 +1,12 @@ -using System.Reflection;
-
-namespace gorilla.infrastructure.proxies
-{
- public interface Invocation
- {
- void proceed();
- object[] arguments { get; }
- MethodInfo method { get; }
- object return_value { get; set; }
- }
-}
\ No newline at end of file +using System.Reflection; + +namespace jive.infrastructure.proxies +{ + public interface Invocation + { + void proceed(); + object[] arguments { get; } + MethodInfo method { get; } + object return_value { get; set; } + } +} diff --git a/lib/infrastructure/proxies/MethodCallInvocation.cs b/lib/infrastructure/proxies/MethodCallInvocation.cs index a9332bf..0759c11 100644 --- a/lib/infrastructure/proxies/MethodCallInvocation.cs +++ b/lib/infrastructure/proxies/MethodCallInvocation.cs @@ -1,47 +1,47 @@ -//using System.Collections.Generic;
-//using System.Reflection;
-//using System.Runtime.Remoting.Messaging;
-//using gorilla.utility;
-
-//namespace gorilla.infrastructure.proxies
-//{
- //public class MethodCallInvocation<T> : Invocation
- //{
- //readonly IMethodCallMessage call;
- //readonly T target;
- //readonly Stack<Interceptor> interceptors;
-
- //public MethodCallInvocation(IEnumerable<Interceptor> interceptors, IMethodCallMessage call, T target)
- //{
- //this.call = call;
- //this.target = target;
- //this.interceptors = new Stack<Interceptor>(interceptors);
- //arguments = call.Properties["__Args"].downcast_to<object[]>();
- //method = call.MethodBase.downcast_to<MethodInfo>();
- //}
-
- //public object[] arguments { get; set; }
-
- //public MethodInfo method { get; set; }
-
- //public object return_value { get; set; }
-
- //public void proceed()
- //{
- //if (interceptors.Count > 0)
- //{
- //interceptors.Pop().intercept(this);
- //return;
- //}
-
- //try
- //{
- //return_value = call.MethodBase.Invoke(target, arguments);
- //}
- //catch (TargetInvocationException e)
- //{
- //throw e.InnerException.preserve_stack_trace();
- //}
- //}
- //}
-//}
+//using System.Collections.Generic; +//using System.Reflection; +//using System.Runtime.Remoting.Messaging; +//using jive.utility; + +//namespace jive.infrastructure.proxies +//{ + //public class MethodCallInvocation<T> : Invocation + //{ + //readonly IMethodCallMessage call; + //readonly T target; + //readonly Stack<Interceptor> interceptors; + + //public MethodCallInvocation(IEnumerable<Interceptor> interceptors, IMethodCallMessage call, T target) + //{ + //this.call = call; + //this.target = target; + //this.interceptors = new Stack<Interceptor>(interceptors); + //arguments = call.Properties["__Args"].downcast_to<object[]>(); + //method = call.MethodBase.downcast_to<MethodInfo>(); + //} + + //public object[] arguments { get; set; } + + //public MethodInfo method { get; set; } + + //public object return_value { get; set; } + + //public void proceed() + //{ + //if (interceptors.Count > 0) + //{ + //interceptors.Pop().intercept(this); + //return; + //} + + //try + //{ + //return_value = call.MethodBase.Invoke(target, arguments); + //} + //catch (TargetInvocationException e) + //{ + //throw e.InnerException.preserve_stack_trace(); + //} + //} + //} +//} diff --git a/lib/infrastructure/proxies/ProxyFactory.cs b/lib/infrastructure/proxies/ProxyFactory.cs index 8593034..456dce5 100644 --- a/lib/infrastructure/proxies/ProxyFactory.cs +++ b/lib/infrastructure/proxies/ProxyFactory.cs @@ -1,10 +1,10 @@ -//namespace gorilla.infrastructure.proxies
-//{
- //static public class ProxyFactory
- //{
- //static public T create<T>(T target, params Interceptor[] interceptors)
- //{
- //return new RemotingProxyFactory<T>(target, interceptors).create_proxy();
- //}
- //}
-//}
+//namespace jive.infrastructure.proxies +//{ + //static public class ProxyFactory + //{ + //static public T create<T>(T target, params Interceptor[] interceptors) + //{ + //return new RemotingProxyFactory<T>(target, interceptors).create_proxy(); + //} + //} +//} diff --git a/lib/infrastructure/proxies/RemotingProxyFactory.cs b/lib/infrastructure/proxies/RemotingProxyFactory.cs index 3932f1e..a0eaf17 100644 --- a/lib/infrastructure/proxies/RemotingProxyFactory.cs +++ b/lib/infrastructure/proxies/RemotingProxyFactory.cs @@ -1,44 +1,44 @@ -//using System.Collections.Generic;
-//using System.Runtime.Remoting.Messaging;
-//using System.Runtime.Remoting.Proxies;
-//using gorilla.utility;
-
-//namespace gorilla.infrastructure.proxies
-//{
- //public class RemotingProxyFactory<T> : RealProxy
- //{
- //readonly T target;
- //readonly IEnumerable<Interceptor> interceptors;
-
- //public RemotingProxyFactory(T target, IEnumerable<Interceptor> interceptors) : base(typeof (T))
- //{
- //this.target = target;
- //this.interceptors = interceptors;
- //}
-
- //public override IMessage Invoke(IMessage message)
- //{
- //if (message.is_an_implementation_of<IMethodCallMessage>())
- //{
- //var call = message.downcast_to<IMethodCallMessage>();
- //var invocation = new MethodCallInvocation<T>(interceptors, call, target);
- //invocation.proceed();
- //return return_value(invocation.return_value, invocation.arguments, call);
- //}
- //return null;
- //}
-
- //IMessage return_value(object return_value, object[] out_parameters, IMethodCallMessage call)
- //{
- //return new ReturnMessage(return_value,
- //out_parameters,
- //out_parameters == null ? 0 : out_parameters.Length,
- //call.LogicalCallContext, call);
- //}
-
- //public T create_proxy()
- //{
- //return GetTransparentProxy().downcast_to<T>();
- //}
- //}
-//}
+//using System.Collections.Generic; +//using System.Runtime.Remoting.Messaging; +//using System.Runtime.Remoting.Proxies; +//using jive.utility; + +//namespace jive.infrastructure.proxies +//{ + //public class RemotingProxyFactory<T> : RealProxy + //{ + //readonly T target; + //readonly IEnumerable<Interceptor> interceptors; + + //public RemotingProxyFactory(T target, IEnumerable<Interceptor> interceptors) : base(typeof (T)) + //{ + //this.target = target; + //this.interceptors = interceptors; + //} + + //public override IMessage Invoke(IMessage message) + //{ + //if (message.is_an_implementation_of<IMethodCallMessage>()) + //{ + //var call = message.downcast_to<IMethodCallMessage>(); + //var invocation = new MethodCallInvocation<T>(interceptors, call, target); + //invocation.proceed(); + //return return_value(invocation.return_value, invocation.arguments, call); + //} + //return null; + //} + + //IMessage return_value(object return_value, object[] out_parameters, IMethodCallMessage call) + //{ + //return new ReturnMessage(return_value, + //out_parameters, + //out_parameters == null ? 0 : out_parameters.Length, + //call.LogicalCallContext, call); + //} + + //public T create_proxy() + //{ + //return GetTransparentProxy().downcast_to<T>(); + //} + //} +//} diff --git a/lib/infrastructure/reflection/ApplicationAssembly.cs b/lib/infrastructure/reflection/ApplicationAssembly.cs index 9d19e11..5a69350 100644 --- a/lib/infrastructure/reflection/ApplicationAssembly.cs +++ b/lib/infrastructure/reflection/ApplicationAssembly.cs @@ -1,20 +1,20 @@ -using System;
-using System.Collections.Generic;
-
-namespace gorilla.infrastructure.reflection
-{
- public class ApplicationAssembly : Assembly
- {
- readonly System.Reflection.Assembly assembly;
-
- public ApplicationAssembly(System.Reflection.Assembly assembly)
- {
- this.assembly = assembly;
- }
-
- public IEnumerable<Type> all_types()
- {
- return assembly.GetTypes();
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; + +namespace jive.infrastructure.reflection +{ + public class ApplicationAssembly : Assembly + { + readonly System.Reflection.Assembly assembly; + + public ApplicationAssembly(System.Reflection.Assembly assembly) + { + this.assembly = assembly; + } + + public IEnumerable<Type> all_types() + { + return assembly.GetTypes(); + } + } +} diff --git a/lib/infrastructure/reflection/Assembly.cs b/lib/infrastructure/reflection/Assembly.cs index 63c9568..cc0fd8e 100644 --- a/lib/infrastructure/reflection/Assembly.cs +++ b/lib/infrastructure/reflection/Assembly.cs @@ -1,10 +1,10 @@ -using System;
-using System.Collections.Generic;
-
-namespace gorilla.infrastructure.reflection
-{
- public interface Assembly
- {
- IEnumerable<Type> all_types();
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; + +namespace jive.infrastructure.reflection +{ + public interface Assembly + { + IEnumerable<Type> all_types(); + } +} diff --git a/lib/infrastructure/reflection/EnvironmentExtensions.cs b/lib/infrastructure/reflection/EnvironmentExtensions.cs index c20560d..f77e160 100644 --- a/lib/infrastructure/reflection/EnvironmentExtensions.cs +++ b/lib/infrastructure/reflection/EnvironmentExtensions.cs @@ -1,12 +1,12 @@ -using System;
-
-namespace gorilla.infrastructure.reflection
-{
- public static class EnvironmentExtensions
- {
- public static string startup_directory<T>(this T item)
- {
- return AppDomain.CurrentDomain.BaseDirectory;
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.reflection +{ + public static class EnvironmentExtensions + { + public static string startup_directory<T>(this T item) + { + return AppDomain.CurrentDomain.BaseDirectory; + } + } +} diff --git a/lib/infrastructure/registries/DefaultRegistry.cs b/lib/infrastructure/registries/DefaultRegistry.cs index 690fcaf..d404086 100644 --- a/lib/infrastructure/registries/DefaultRegistry.cs +++ b/lib/infrastructure/registries/DefaultRegistry.cs @@ -1,32 +1,32 @@ -using System.Collections;
-using System.Collections.Generic;
-using gorilla.infrastructure.container;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.registries
-{
- public class DefaultRegistry<T> : Registry<T>
- {
- readonly DependencyRegistry registry;
-
- public DefaultRegistry(DependencyRegistry registry)
- {
- this.registry = registry;
- }
-
- public IEnumerable<T> all()
- {
- return registry.get_all<T>();
- }
-
- public IEnumerator<T> GetEnumerator()
- {
- return all().GetEnumerator();
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- }
-}
\ No newline at end of file +using System.Collections; +using System.Collections.Generic; +using jive.infrastructure.container; +using jive.utility; + +namespace jive.infrastructure.registries +{ + public class DefaultRegistry<T> : Registry<T> + { + readonly DependencyRegistry registry; + + public DefaultRegistry(DependencyRegistry registry) + { + this.registry = registry; + } + + public IEnumerable<T> all() + { + return registry.get_all<T>(); + } + + public IEnumerator<T> GetEnumerator() + { + return all().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } +} diff --git a/lib/infrastructure/threading/ApplicationThread.cs b/lib/infrastructure/threading/ApplicationThread.cs index 71eebd7..a02a144 100755..100644 --- a/lib/infrastructure/threading/ApplicationThread.cs +++ b/lib/infrastructure/threading/ApplicationThread.cs @@ -1,7 +1,7 @@ -namespace gorilla.infrastructure.threading
-{
- public interface ApplicationThread
- {
- T provide_slot_for<T>() where T : class, new();
- }
-}
\ No newline at end of file +namespace jive.infrastructure.threading +{ + public interface ApplicationThread + { + T provide_slot_for<T>() where T : class, new(); + } +} diff --git a/lib/infrastructure/threading/AsynchronousCommandProcessor.cs b/lib/infrastructure/threading/AsynchronousCommandProcessor.cs index f776ac1..6540f83 100755..100644 --- a/lib/infrastructure/threading/AsynchronousCommandProcessor.cs +++ b/lib/infrastructure/threading/AsynchronousCommandProcessor.cs @@ -1,113 +1,113 @@ -using System;
-using System.Collections.Generic;
-using System.Threading;
-using gorilla.infrastructure.logging;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- public class AsynchronousCommandProcessor : CommandProcessor
- {
- readonly Queue<Command> queued_commands;
- readonly EventWaitHandle manual_reset;
- readonly IList<Thread> worker_threads;
- bool keep_working;
-
- static public readonly Command Empty = new EmptyCommand();
-
- public AsynchronousCommandProcessor()
- {
- queued_commands = new Queue<Command>();
- worker_threads = new List<Thread>();
- manual_reset = new ManualResetEvent(false);
- }
-
- public void add(Action command)
- {
- add(new AnonymousCommand(command));
- }
-
- public void add(Command command_to_process)
- {
- lock (queued_commands)
- {
- if (queued_commands.Contains(command_to_process)) return;
- queued_commands.Enqueue(command_to_process);
- reset_thread();
- }
- }
-
- public void run()
- {
- reset_thread();
- keep_working = true;
- var worker_thread = new Thread(run_commands);
- worker_thread.SetApartmentState(ApartmentState.STA);
- worker_threads.Add(worker_thread);
- worker_thread.Start();
- }
-
- public void stop()
- {
- keep_working = false;
- manual_reset.Set();
- //manual_reset.Close();
- }
-
- [STAThread]
- void run_commands()
- {
- while (keep_working)
- {
- manual_reset.WaitOne();
- run_next_command();
- }
- }
-
- void run_next_command()
- {
- var command = Empty;
- within_lock(() =>
- {
- if (queued_commands.Count == 0)
- manual_reset.Reset();
- else
- command = queued_commands.Dequeue();
- });
- safely_invoke(() =>
- {
- command.run();
- });
- reset_thread();
- }
-
- void safely_invoke(Action action)
- {
- try
- {
- action();
- }
- catch (Exception e)
- {
- this.log().error(e);
- }
- }
-
- void reset_thread()
- {
- within_lock(() =>
- {
- if (queued_commands.Count > 0) manual_reset.Set();
- else manual_reset.Reset();
- });
- }
-
- void within_lock(Action action)
- {
- lock (queued_commands)
- {
- action();
- }
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using System.Threading; +using jive.infrastructure.logging; +using jive.utility; + +namespace jive.infrastructure.threading +{ + public class AsynchronousCommandProcessor : CommandProcessor + { + readonly Queue<Command> queued_commands; + readonly EventWaitHandle manual_reset; + readonly IList<Thread> worker_threads; + bool keep_working; + + static public readonly Command Empty = new EmptyCommand(); + + public AsynchronousCommandProcessor() + { + queued_commands = new Queue<Command>(); + worker_threads = new List<Thread>(); + manual_reset = new ManualResetEvent(false); + } + + public void add(Action command) + { + add(new AnonymousCommand(command)); + } + + public void add(Command command_to_process) + { + lock (queued_commands) + { + if (queued_commands.Contains(command_to_process)) return; + queued_commands.Enqueue(command_to_process); + reset_thread(); + } + } + + public void run() + { + reset_thread(); + keep_working = true; + var worker_thread = new Thread(run_commands); + worker_thread.SetApartmentState(ApartmentState.STA); + worker_threads.Add(worker_thread); + worker_thread.Start(); + } + + public void stop() + { + keep_working = false; + manual_reset.Set(); + //manual_reset.Close(); + } + + [STAThread] + void run_commands() + { + while (keep_working) + { + manual_reset.WaitOne(); + run_next_command(); + } + } + + void run_next_command() + { + var command = Empty; + within_lock(() => + { + if (queued_commands.Count == 0) + manual_reset.Reset(); + else + command = queued_commands.Dequeue(); + }); + safely_invoke(() => + { + command.run(); + }); + reset_thread(); + } + + void safely_invoke(Action action) + { + try + { + action(); + } + catch (Exception e) + { + this.log().error(e); + } + } + + void reset_thread() + { + within_lock(() => + { + if (queued_commands.Count > 0) manual_reset.Set(); + else manual_reset.Reset(); + }); + } + + void within_lock(Action action) + { + lock (queued_commands) + { + action(); + } + } + } +} diff --git a/lib/infrastructure/threading/BackgroundThread.cs b/lib/infrastructure/threading/BackgroundThread.cs index 63a7281..1cf3ce7 100755..100644 --- a/lib/infrastructure/threading/BackgroundThread.cs +++ b/lib/infrastructure/threading/BackgroundThread.cs @@ -1,6 +1,6 @@ -using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- public interface BackgroundThread : DisposableCommand {}
-}
\ No newline at end of file +using jive.utility; + +namespace jive.infrastructure.threading +{ + public interface BackgroundThread : DisposableCommand {} +} diff --git a/lib/infrastructure/threading/BackgroundThreadFactory.cs b/lib/infrastructure/threading/BackgroundThreadFactory.cs index 38c82d0..a42e4d9 100755..100644 --- a/lib/infrastructure/threading/BackgroundThreadFactory.cs +++ b/lib/infrastructure/threading/BackgroundThreadFactory.cs @@ -1,49 +1,49 @@ -using System;
-using gorilla.infrastructure.container;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- public interface IBackgroundThreadFactory
- {
- BackgroundThread create_for<CommandToExecute>() where CommandToExecute : DisposableCommand;
- BackgroundThread create_for(Action action);
- }
-
- public class BackgroundThreadFactory : IBackgroundThreadFactory
- {
- readonly DependencyRegistry registry;
-
- public BackgroundThreadFactory(DependencyRegistry registry)
- {
- this.registry = registry;
- }
-
- public BackgroundThread create_for<CommandToExecute>() where CommandToExecute : DisposableCommand
- {
- return new WorkderBackgroundThread(registry.get_a<CommandToExecute>());
- }
-
- public BackgroundThread create_for(Action action)
- {
- return new WorkderBackgroundThread(new AnonymousDisposableCommand(action));
- }
-
- class AnonymousDisposableCommand : DisposableCommand
- {
- readonly Action action;
-
- public AnonymousDisposableCommand(Action action)
- {
- this.action = action;
- }
-
- public void run()
- {
- action();
- }
-
- public void Dispose() {}
- }
- }
-}
\ No newline at end of file +using System; +using jive.infrastructure.container; +using jive.utility; + +namespace jive.infrastructure.threading +{ + public interface IBackgroundThreadFactory + { + BackgroundThread create_for<CommandToExecute>() where CommandToExecute : DisposableCommand; + BackgroundThread create_for(Action action); + } + + public class BackgroundThreadFactory : IBackgroundThreadFactory + { + readonly DependencyRegistry registry; + + public BackgroundThreadFactory(DependencyRegistry registry) + { + this.registry = registry; + } + + public BackgroundThread create_for<CommandToExecute>() where CommandToExecute : DisposableCommand + { + return new WorkderBackgroundThread(registry.get_a<CommandToExecute>()); + } + + public BackgroundThread create_for(Action action) + { + return new WorkderBackgroundThread(new AnonymousDisposableCommand(action)); + } + + class AnonymousDisposableCommand : DisposableCommand + { + readonly Action action; + + public AnonymousDisposableCommand(Action action) + { + this.action = action; + } + + public void run() + { + action(); + } + + public void Dispose() {} + } + } +} diff --git a/lib/infrastructure/threading/CommandProcessor.cs b/lib/infrastructure/threading/CommandProcessor.cs index 0306732..35f81ff 100755..100644 --- a/lib/infrastructure/threading/CommandProcessor.cs +++ b/lib/infrastructure/threading/CommandProcessor.cs @@ -1,12 +1,12 @@ -using System;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading +using System; +using jive.utility; + +namespace jive.infrastructure.threading { - public interface CommandProcessor : Command - { - void add(Action command); - void add(Command command_to_process); - void stop(); - } -}
\ No newline at end of file + public interface CommandProcessor : Command + { + void add(Action command); + void add(Command command_to_process); + void stop(); + } +} diff --git a/lib/infrastructure/threading/CurrentThread.cs b/lib/infrastructure/threading/CurrentThread.cs index 81e3ae6..75afa12 100755..100644 --- a/lib/infrastructure/threading/CurrentThread.cs +++ b/lib/infrastructure/threading/CurrentThread.cs @@ -1,19 +1,19 @@ -using System.Threading;
-
-namespace gorilla.infrastructure.threading +using System.Threading; + +namespace jive.infrastructure.threading { - public class CurrentThread : ApplicationThread + public class CurrentThread : ApplicationThread + { + public T provide_slot_for<T>() where T : class, new() { - public T provide_slot_for<T>() where T : class, new() - { - var slot = Thread.GetNamedDataSlot(create_key_for<T>()); - if (null == Thread.GetData(slot)) Thread.SetData(slot, new T()); - return (T) Thread.GetData(slot); - } + var slot = Thread.GetNamedDataSlot(create_key_for<T>()); + if (null == Thread.GetData(slot)) Thread.SetData(slot, new T()); + return (T) Thread.GetData(slot); + } - string create_key_for<T>() - { - return Thread.CurrentThread.ManagedThreadId + GetType().FullName + typeof (T).FullName; - } + string create_key_for<T>() + { + return Thread.CurrentThread.ManagedThreadId + GetType().FullName + typeof (T).FullName; } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/ITimerFactory.cs b/lib/infrastructure/threading/ITimerFactory.cs index 397bbef..2dd1e1e 100755..100644 --- a/lib/infrastructure/threading/ITimerFactory.cs +++ b/lib/infrastructure/threading/ITimerFactory.cs @@ -1,9 +1,9 @@ -using System;
-
-namespace gorilla.infrastructure.threading
-{
- public interface ITimerFactory
- {
- System.Timers.Timer create_for(TimeSpan span);
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.threading +{ + public interface ITimerFactory + { + System.Timers.Timer create_for(TimeSpan span); + } +} diff --git a/lib/infrastructure/threading/IWorkerThread.cs b/lib/infrastructure/threading/IWorkerThread.cs index 3313ba6..e17c64a 100755..100644 --- a/lib/infrastructure/threading/IWorkerThread.cs +++ b/lib/infrastructure/threading/IWorkerThread.cs @@ -1,12 +1,12 @@ -using System;
-using System.ComponentModel;
-
-namespace gorilla.infrastructure.threading +using System; +using System.ComponentModel; + +namespace jive.infrastructure.threading { - public interface IWorkerThread : IDisposable - { - event DoWorkEventHandler DoWork; - event EventHandler Disposed; - void begin(); - } -}
\ No newline at end of file + public interface IWorkerThread : IDisposable + { + event DoWorkEventHandler DoWork; + event EventHandler Disposed; + void begin(); + } +} diff --git a/lib/infrastructure/threading/IntervalTimer.cs b/lib/infrastructure/threading/IntervalTimer.cs index 3977978..74f3055 100755..100644 --- a/lib/infrastructure/threading/IntervalTimer.cs +++ b/lib/infrastructure/threading/IntervalTimer.cs @@ -1,48 +1,48 @@ -using System;
-using System.Collections.Generic;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- public class IntervalTimer : Timer
- {
- readonly ITimerFactory factory;
- readonly IDictionary<TimerClient, System.Timers.Timer> timers;
-
- public IntervalTimer() : this(new TimerFactory())
- {
- }
-
- public IntervalTimer(ITimerFactory factory)
- {
- this.factory = factory;
- timers = new Dictionary<TimerClient, System.Timers.Timer>();
- }
-
- public void start_notifying(TimerClient client_to_be_notified, TimeSpan span)
- {
- stop_notifying(client_to_be_notified);
-
- var timer = factory.create_for(span);
- timer.Elapsed += (o, e) =>
- {
- client_to_be_notified.notify();
- };
- timer.Start();
- timers[client_to_be_notified] = timer;
- }
-
- public void stop_notifying(TimerClient client_to_stop_notifying)
- {
- if (!timers.ContainsKey(client_to_stop_notifying)) return;
- timers[client_to_stop_notifying].Stop();
- timers[client_to_stop_notifying].Dispose();
- }
-
- public void Dispose()
- {
- timers.each(x => x.Value.Dispose());
- timers.Clear();
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using jive.utility; + +namespace jive.infrastructure.threading +{ + public class IntervalTimer : Timer + { + readonly ITimerFactory factory; + readonly IDictionary<TimerClient, System.Timers.Timer> timers; + + public IntervalTimer() : this(new TimerFactory()) + { + } + + public IntervalTimer(ITimerFactory factory) + { + this.factory = factory; + timers = new Dictionary<TimerClient, System.Timers.Timer>(); + } + + public void start_notifying(TimerClient client_to_be_notified, TimeSpan span) + { + stop_notifying(client_to_be_notified); + + var timer = factory.create_for(span); + timer.Elapsed += (o, e) => + { + client_to_be_notified.notify(); + }; + timer.Start(); + timers[client_to_be_notified] = timer; + } + + public void stop_notifying(TimerClient client_to_stop_notifying) + { + if (!timers.ContainsKey(client_to_stop_notifying)) return; + timers[client_to_stop_notifying].Stop(); + timers[client_to_stop_notifying].Dispose(); + } + + public void Dispose() + { + timers.each(x => x.Value.Dispose()); + timers.Clear(); + } + } +} diff --git a/lib/infrastructure/threading/PerThread.cs b/lib/infrastructure/threading/PerThread.cs index eb09756..6eed137 100755..100644 --- a/lib/infrastructure/threading/PerThread.cs +++ b/lib/infrastructure/threading/PerThread.cs @@ -1,59 +1,59 @@ -using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Threading;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- public class PerThread : Context
- {
- readonly IDictionary<int, LocalDataStoreSlot> slots;
- readonly object mutex = new object();
-
- public PerThread()
- {
- slots = new Dictionary<int, LocalDataStoreSlot>();
- }
-
- public bool contains<T>(Key<T> key)
- {
- return key.is_found_in(get_items());
- }
-
- public void add<T>(Key<T> key, T value)
- {
- key.add_value_to(get_items(), value);
- }
-
- public T value_for<T>(Key<T> key)
- {
- return key.parse_from(get_items());
- }
-
- public void remove<T>(Key<T> key)
- {
- key.remove_from(get_items());
- }
-
- IDictionary get_items()
- {
- var id = Thread.CurrentThread.ManagedThreadId;
- within_lock(() =>
- {
- if (!slots.ContainsKey(id))
- {
- var slot = Thread.GetNamedDataSlot(GetType().FullName);
- slots.Add(id, slot);
- Thread.SetData(slot, new Hashtable());
- }
- });
- return (IDictionary) Thread.GetData(slots[id]);
- }
-
- void within_lock(Action action)
- {
- lock (mutex) action();
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading; +using jive.utility; + +namespace jive.infrastructure.threading +{ + public class PerThread : Context + { + readonly IDictionary<int, LocalDataStoreSlot> slots; + readonly object mutex = new object(); + + public PerThread() + { + slots = new Dictionary<int, LocalDataStoreSlot>(); + } + + public bool contains<T>(Key<T> key) + { + return key.is_found_in(get_items()); + } + + public void add<T>(Key<T> key, T value) + { + key.add_value_to(get_items(), value); + } + + public T value_for<T>(Key<T> key) + { + return key.parse_from(get_items()); + } + + public void remove<T>(Key<T> key) + { + key.remove_from(get_items()); + } + + IDictionary get_items() + { + var id = Thread.CurrentThread.ManagedThreadId; + within_lock(() => + { + if (!slots.ContainsKey(id)) + { + var slot = Thread.GetNamedDataSlot(GetType().FullName); + slots.Add(id, slot); + Thread.SetData(slot, new Hashtable()); + } + }); + return (IDictionary) Thread.GetData(slots[id]); + } + + void within_lock(Action action) + { + lock (mutex) action(); + } + } +} diff --git a/lib/infrastructure/threading/PerThreadScopedStorage.cs b/lib/infrastructure/threading/PerThreadScopedStorage.cs index 1a16b3b..594bd89 100755..100644 --- a/lib/infrastructure/threading/PerThreadScopedStorage.cs +++ b/lib/infrastructure/threading/PerThreadScopedStorage.cs @@ -1,20 +1,20 @@ -using System.Collections;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading +using System.Collections; +using jive.utility; + +namespace jive.infrastructure.threading { - public class PerThreadScopedStorage : ScopedStorage - { - readonly ApplicationThread current_thread; + public class PerThreadScopedStorage : ScopedStorage + { + readonly ApplicationThread current_thread; - public PerThreadScopedStorage(ApplicationThread current_thread) - { - this.current_thread = current_thread; - } + public PerThreadScopedStorage(ApplicationThread current_thread) + { + this.current_thread = current_thread; + } - public IDictionary provide_storage() - { - return current_thread.provide_slot_for<Hashtable>(); - } + public IDictionary provide_storage() + { + return current_thread.provide_slot_for<Hashtable>(); } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/SynchronizationContextFactory.cs b/lib/infrastructure/threading/SynchronizationContextFactory.cs index 854e3e6..23b82d8 100755..100644 --- a/lib/infrastructure/threading/SynchronizationContextFactory.cs +++ b/lib/infrastructure/threading/SynchronizationContextFactory.cs @@ -1,23 +1,23 @@ -using System.Threading;
-using gorilla.infrastructure.container;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading +using System.Threading; +using jive.infrastructure.container; +using jive.utility; + +namespace jive.infrastructure.threading { - public interface ISynchronizationContextFactory : Factory<ISynchronizationContext> {} + public interface ISynchronizationContextFactory : Factory<ISynchronizationContext> {} - public class SynchronizationContextFactory : ISynchronizationContextFactory - { - readonly DependencyRegistry registry; + public class SynchronizationContextFactory : ISynchronizationContextFactory + { + readonly DependencyRegistry registry; - public SynchronizationContextFactory(DependencyRegistry registry) - { - this.registry = registry; - } + public SynchronizationContextFactory(DependencyRegistry registry) + { + this.registry = registry; + } - public ISynchronizationContext create() - { - return new SynchronizedContext(registry.get_a<SynchronizationContext>()); - } + public ISynchronizationContext create() + { + return new SynchronizedContext(registry.get_a<SynchronizationContext>()); } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/SynchronizedCommand.cs b/lib/infrastructure/threading/SynchronizedCommand.cs index fb78905..2da6671 100755..100644 --- a/lib/infrastructure/threading/SynchronizedCommand.cs +++ b/lib/infrastructure/threading/SynchronizedCommand.cs @@ -1,28 +1,28 @@ -using System;
-using System.Threading;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading +using System; +using System.Threading; +using jive.utility; + +namespace jive.infrastructure.threading { - public interface ISynchronizedCommand : Command<Action>, Command<Command> {} + public interface ISynchronizedCommand : Command<Action>, Command<Command> {} - public class SynchronizedCommand : ISynchronizedCommand - { - readonly SynchronizationContext context; + public class SynchronizedCommand : ISynchronizedCommand + { + readonly SynchronizationContext context; - public SynchronizedCommand(SynchronizationContext context) - { - this.context = context; - } + public SynchronizedCommand(SynchronizationContext context) + { + this.context = context; + } - public void run(Action item) - { - context.Post(x => item(), new object()); - } + public void run(Action item) + { + context.Post(x => item(), new object()); + } - public void run(Command item) - { - run(item.run); - } + public void run(Command item) + { + run(item.run); } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/SynchronizedContext.cs b/lib/infrastructure/threading/SynchronizedContext.cs index 0637c42..9cd15cd 100755..100644 --- a/lib/infrastructure/threading/SynchronizedContext.cs +++ b/lib/infrastructure/threading/SynchronizedContext.cs @@ -1,23 +1,23 @@ -using System.Threading;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading +using System.Threading; +using jive.utility; + +namespace jive.infrastructure.threading { - public interface ISynchronizationContext : Command<Command> {} + public interface ISynchronizationContext : Command<Command> {} - public class SynchronizedContext : ISynchronizationContext - { - readonly SynchronizationContext context; + public class SynchronizedContext : ISynchronizationContext + { + readonly SynchronizationContext context; - public SynchronizedContext(SynchronizationContext context) - { - this.context = context; - } + public SynchronizedContext(SynchronizationContext context) + { + this.context = context; + } - public void run(Command item) - { - context.Post(x => item.run(), new object()); - //context.Send(x => item.run(), new object()); - } + public void run(Command item) + { + context.Post(x => item.run(), new object()); + //context.Send(x => item.run(), new object()); } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/SynchronousCommandProcessor.cs b/lib/infrastructure/threading/SynchronousCommandProcessor.cs index 051fedd..c3263f2 100755..100644 --- a/lib/infrastructure/threading/SynchronousCommandProcessor.cs +++ b/lib/infrastructure/threading/SynchronousCommandProcessor.cs @@ -1,36 +1,36 @@ -using System;
-using System.Collections.Generic;
-using gorilla.utility;
-
-namespace gorilla.infrastructure.threading +using System; +using System.Collections.Generic; +using jive.utility; + +namespace jive.infrastructure.threading { - public class SynchronousCommandProcessor : CommandProcessor - { - readonly Queue<Command> queued_commands; + public class SynchronousCommandProcessor : CommandProcessor + { + readonly Queue<Command> queued_commands; - public SynchronousCommandProcessor() - { - queued_commands = new Queue<Command>(); - } + public SynchronousCommandProcessor() + { + queued_commands = new Queue<Command>(); + } - public void add(Action command) - { - add(new AnonymousCommand(command)); - } + public void add(Action command) + { + add(new AnonymousCommand(command)); + } - public void add(Command command_to_process) - { - queued_commands.Enqueue(command_to_process); - } + public void add(Command command_to_process) + { + queued_commands.Enqueue(command_to_process); + } - public void run() - { - while (queued_commands.Count > 0) queued_commands.Dequeue().run(); - } + public void run() + { + while (queued_commands.Count > 0) queued_commands.Dequeue().run(); + } - public void stop() - { - queued_commands.Clear(); - } + public void stop() + { + queued_commands.Clear(); } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/ThreadingExtensions.cs b/lib/infrastructure/threading/ThreadingExtensions.cs index 6b123b3..963d353 100755..100644 --- a/lib/infrastructure/threading/ThreadingExtensions.cs +++ b/lib/infrastructure/threading/ThreadingExtensions.cs @@ -1,12 +1,12 @@ -using gorilla.utility;
-
-namespace gorilla.infrastructure.threading
-{
- static public class ThreadingExtensions
- {
- static public BackgroundThread on_a_background_thread(this DisposableCommand command)
- {
- return new WorkderBackgroundThread(command);
- }
- }
-}
\ No newline at end of file +using jive.utility; + +namespace jive.infrastructure.threading +{ + static public class ThreadingExtensions + { + static public BackgroundThread on_a_background_thread(this DisposableCommand command) + { + return new WorkderBackgroundThread(command); + } + } +} diff --git a/lib/infrastructure/threading/Timer.cs b/lib/infrastructure/threading/Timer.cs index 3982d9d..56d4d51 100755..100644 --- a/lib/infrastructure/threading/Timer.cs +++ b/lib/infrastructure/threading/Timer.cs @@ -1,10 +1,10 @@ -using System;
-
-namespace gorilla.infrastructure.threading
-{
- public interface Timer : IDisposable
- {
- void start_notifying(TimerClient client_to_be_notified, TimeSpan span);
- void stop_notifying(TimerClient client_to_stop_notifying);
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.threading +{ + public interface Timer : IDisposable + { + void start_notifying(TimerClient client_to_be_notified, TimeSpan span); + void stop_notifying(TimerClient client_to_stop_notifying); + } +} diff --git a/lib/infrastructure/threading/TimerClient.cs b/lib/infrastructure/threading/TimerClient.cs index 6ccc961..b44d460 100755..100644 --- a/lib/infrastructure/threading/TimerClient.cs +++ b/lib/infrastructure/threading/TimerClient.cs @@ -1,7 +1,7 @@ -namespace gorilla.infrastructure.threading
-{
- public interface TimerClient
- {
- void notify();
- }
-}
\ No newline at end of file +namespace jive.infrastructure.threading +{ + public interface TimerClient + { + void notify(); + } +} diff --git a/lib/infrastructure/threading/TimerFactory.cs b/lib/infrastructure/threading/TimerFactory.cs index d663591..b6fc313 100755..100644 --- a/lib/infrastructure/threading/TimerFactory.cs +++ b/lib/infrastructure/threading/TimerFactory.cs @@ -1,17 +1,17 @@ -using System;
-
-namespace gorilla.infrastructure.threading
-{
- public class TimerFactory : ITimerFactory
- {
- public System.Timers.Timer create_for(TimeSpan span)
- {
- if (span.Seconds > 0)
- {
- var milliseconds = span.Seconds*1000;
- return new System.Timers.Timer(milliseconds);
- }
- return new System.Timers.Timer(span.Ticks);
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.infrastructure.threading +{ + public class TimerFactory : ITimerFactory + { + public System.Timers.Timer create_for(TimeSpan span) + { + if (span.Seconds > 0) + { + var milliseconds = span.Seconds*1000; + return new System.Timers.Timer(milliseconds); + } + return new System.Timers.Timer(span.Ticks); + } + } +} diff --git a/lib/infrastructure/threading/WorkderBackgroundThread.cs b/lib/infrastructure/threading/WorkderBackgroundThread.cs index 278c61f..6295760 100755..100644 --- a/lib/infrastructure/threading/WorkderBackgroundThread.cs +++ b/lib/infrastructure/threading/WorkderBackgroundThread.cs @@ -1,28 +1,28 @@ -using gorilla.utility;
-
-namespace gorilla.infrastructure.threading -{
- public class WorkderBackgroundThread : BackgroundThread - { - readonly IWorkerThread worker_thread; +using jive.utility; - public WorkderBackgroundThread(DisposableCommand command_to_execute) : this(command_to_execute, new WorkerThread()) {} +namespace jive.infrastructure.threading +{ + public class WorkderBackgroundThread : BackgroundThread + { + readonly IWorkerThread worker_thread; - public WorkderBackgroundThread(DisposableCommand command_to_execute, IWorkerThread worker_thread) - { - this.worker_thread = worker_thread; - worker_thread.DoWork += (sender, e) => command_to_execute.run(); - worker_thread.Disposed += (sender, e) => command_to_execute.Dispose(); - } + public WorkderBackgroundThread(DisposableCommand command_to_execute) : this(command_to_execute, new WorkerThread()) {} - public void run() - { - worker_thread.begin(); - } + public WorkderBackgroundThread(DisposableCommand command_to_execute, IWorkerThread worker_thread) + { + this.worker_thread = worker_thread; + worker_thread.DoWork += (sender, e) => command_to_execute.run(); + worker_thread.Disposed += (sender, e) => command_to_execute.Dispose(); + } - public void Dispose() - { - worker_thread.Dispose(); - } + public void run() + { + worker_thread.begin(); + } + + public void Dispose() + { + worker_thread.Dispose(); } -}
\ No newline at end of file + } +} diff --git a/lib/infrastructure/threading/WorkerThread.cs b/lib/infrastructure/threading/WorkerThread.cs index 4650d96..ca4f08e 100755..100644 --- a/lib/infrastructure/threading/WorkerThread.cs +++ b/lib/infrastructure/threading/WorkerThread.cs @@ -1,50 +1,50 @@ -using System;
-using System.ComponentModel;
-using gorilla.infrastructure.logging;
-
-namespace gorilla.infrastructure.threading +using System; +using System.ComponentModel; +using jive.infrastructure.logging; + +namespace jive.infrastructure.threading { - public class WorkerThread : Component, IWorkerThread - { - static readonly object do_work_key = new object(); - bool is_running; - readonly Action background_thread; + public class WorkerThread : Component, IWorkerThread + { + static readonly object do_work_key = new object(); + bool is_running; + readonly Action background_thread; - public WorkerThread() - { - background_thread = worker_thread_start; - } + public WorkerThread() + { + background_thread = worker_thread_start; + } - public event DoWorkEventHandler DoWork - { - add { Events.AddHandler(do_work_key, value); } - remove { Events.RemoveHandler(do_work_key, value); } - } + public event DoWorkEventHandler DoWork + { + add { Events.AddHandler(do_work_key, value); } + remove { Events.RemoveHandler(do_work_key, value); } + } - public void begin() - { - if (is_running) - { - throw new InvalidOperationException("Worker Thread Is Already Running"); - } - is_running = true; - background_thread.BeginInvoke(null, null); - } + public void begin() + { + if (is_running) + { + throw new InvalidOperationException("Worker Thread Is Already Running"); + } + is_running = true; + background_thread.BeginInvoke(null, null); + } - void worker_thread_start() + void worker_thread_start() + { + try + { + var handler = (DoWorkEventHandler) Events[do_work_key]; + if (handler != null) { - try - { - var handler = (DoWorkEventHandler) Events[do_work_key]; - if (handler != null) - { - handler(this, new DoWorkEventArgs(null)); - } - } - catch (Exception e) - { - this.log().error(e); - } + handler(this, new DoWorkEventArgs(null)); } + } + catch (Exception e) + { + this.log().error(e); + } } -}
\ No newline at end of file + } +} diff --git a/lib/utility/AndSpecification.cs b/lib/utility/AndSpecification.cs index 56c6a24..410f441 100644 --- a/lib/utility/AndSpecification.cs +++ b/lib/utility/AndSpecification.cs @@ -1,19 +1,19 @@ -namespace gorilla.utility
-{
- public class AndSpecification<T> : Specification<T>
- {
- readonly Specification<T> left;
- readonly Specification<T> right;
-
- public AndSpecification(Specification<T> left, Specification<T> right)
- {
- this.left = left;
- this.right = right;
- }
-
- public bool is_satisfied_by(T item)
- {
- return left.is_satisfied_by(item) && right.is_satisfied_by(item);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class AndSpecification<T> : Specification<T> + { + readonly Specification<T> left; + readonly Specification<T> right; + + public AndSpecification(Specification<T> left, Specification<T> right) + { + this.left = left; + this.right = right; + } + + public bool is_satisfied_by(T item) + { + return left.is_satisfied_by(item) && right.is_satisfied_by(item); + } + } +} diff --git a/lib/utility/AnonymousCommand.cs b/lib/utility/AnonymousCommand.cs index 0e110dc..b4c4dc2 100644 --- a/lib/utility/AnonymousCommand.cs +++ b/lib/utility/AnonymousCommand.cs @@ -1,22 +1,22 @@ -using System;
-using System.Linq.Expressions;
-
-namespace gorilla.utility
-{
- public class AnonymousCommand : Command
- {
- readonly Action action;
-
- public AnonymousCommand(Expression<Action> action) : this(action.Compile()) {}
-
- public AnonymousCommand(Action action)
- {
- this.action = action;
- }
-
- public void run()
- {
- action();
- }
- }
-}
\ No newline at end of file +using System; +using System.Linq.Expressions; + +namespace jive.utility +{ + public class AnonymousCommand : Command + { + readonly Action action; + + public AnonymousCommand(Expression<Action> action) : this(action.Compile()) {} + + public AnonymousCommand(Action action) + { + this.action = action; + } + + public void run() + { + action(); + } + } +} diff --git a/lib/utility/AnonymousDisposable.cs b/lib/utility/AnonymousDisposable.cs index f6b134c..b8732be 100644 --- a/lib/utility/AnonymousDisposable.cs +++ b/lib/utility/AnonymousDisposable.cs @@ -1,19 +1,19 @@ -using System;
-
-namespace gorilla.utility
-{
- public class AnonymousDisposable : IDisposable
- {
- readonly Action action;
-
- public AnonymousDisposable(Action action)
- {
- this.action = action;
- }
-
- public void Dispose()
- {
- action();
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public class AnonymousDisposable : IDisposable + { + readonly Action action; + + public AnonymousDisposable(Action action) + { + this.action = action; + } + + public void Dispose() + { + action(); + } + } +} diff --git a/lib/utility/AnonymousMapper.cs b/lib/utility/AnonymousMapper.cs index a17ffc6..9b7d7fb 100644 --- a/lib/utility/AnonymousMapper.cs +++ b/lib/utility/AnonymousMapper.cs @@ -1,19 +1,19 @@ -using System;
-
-namespace gorilla.utility
-{
- public class AnonymousMapper<Input, Output> : Mapper<Input, Output>
- {
- readonly Converter<Input, Output> converter;
-
- public AnonymousMapper(Converter<Input, Output> converter)
- {
- this.converter = converter;
- }
-
- public Output map_from(Input item)
- {
- return converter(item);
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public class AnonymousMapper<Input, Output> : Mapper<Input, Output> + { + readonly Converter<Input, Output> converter; + + public AnonymousMapper(Converter<Input, Output> converter) + { + this.converter = converter; + } + + public Output map_from(Input item) + { + return converter(item); + } + } +} diff --git a/lib/utility/Builder.cs b/lib/utility/Builder.cs index e7f880f..86fba53 100644 --- a/lib/utility/Builder.cs +++ b/lib/utility/Builder.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Builder<out T>
- {
- T build();
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Builder<out T> + { + T build(); + } +} diff --git a/lib/utility/Callback.cs b/lib/utility/Callback.cs index c4364bb..10b32c5 100644 --- a/lib/utility/Callback.cs +++ b/lib/utility/Callback.cs @@ -1,10 +1,10 @@ -namespace gorilla.utility
-{
- public interface Callback : Command
- {
- }
-
- public interface Callback<in T> : Command<T>
- {
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Callback : Command + { + } + + public interface Callback<in T> : Command<T> + { + } +} diff --git a/lib/utility/CallbackCommand.cs b/lib/utility/CallbackCommand.cs index fb19b73..091040e 100644 --- a/lib/utility/CallbackCommand.cs +++ b/lib/utility/CallbackCommand.cs @@ -1,6 +1,6 @@ -namespace gorilla.utility
-{
- public interface CallbackCommand<out T> : Command<Callback<T>>
- {
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface CallbackCommand<out T> : Command<Callback<T>> + { + } +} diff --git a/lib/utility/ChainedCommand.cs b/lib/utility/ChainedCommand.cs index b3302ab..094e96d 100644 --- a/lib/utility/ChainedCommand.cs +++ b/lib/utility/ChainedCommand.cs @@ -1,20 +1,20 @@ -namespace gorilla.utility
-{
- public class ChainedCommand : Command
- {
- readonly Command left;
- readonly Command right;
-
- public ChainedCommand(Command left, Command right)
- {
- this.left = left;
- this.right = right;
- }
-
- public void run()
- {
- left.run();
- right.run();
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class ChainedCommand : Command + { + readonly Command left; + readonly Command right; + + public ChainedCommand(Command left, Command right) + { + this.left = left; + this.right = right; + } + + public void run() + { + left.run(); + right.run(); + } + } +} diff --git a/lib/utility/ChainedConfiguration.cs b/lib/utility/ChainedConfiguration.cs index 3208f74..deedc3b 100644 --- a/lib/utility/ChainedConfiguration.cs +++ b/lib/utility/ChainedConfiguration.cs @@ -1,20 +1,20 @@ -namespace gorilla.utility
-{
- public class ChainedConfiguration<T> : Configuration<T>
- {
- readonly Configuration<T> first;
- readonly Configuration<T> second;
-
- public ChainedConfiguration(Configuration<T> first, Configuration<T> second)
- {
- this.first = first;
- this.second = second;
- }
-
- public void configure(T item)
- {
- first.configure(item);
- second.configure(item);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class ChainedConfiguration<T> : Configuration<T> + { + readonly Configuration<T> first; + readonly Configuration<T> second; + + public ChainedConfiguration(Configuration<T> first, Configuration<T> second) + { + this.first = first; + this.second = second; + } + + public void configure(T item) + { + first.configure(item); + second.configure(item); + } + } +} diff --git a/lib/utility/ChainedMapper.cs b/lib/utility/ChainedMapper.cs index 9be8ea0..80be738 100644 --- a/lib/utility/ChainedMapper.cs +++ b/lib/utility/ChainedMapper.cs @@ -1,19 +1,19 @@ -namespace gorilla.utility
-{
- public class ChainedMapper<Left, Middle, Right> : Mapper<Left, Right>
- {
- readonly Mapper<Left, Middle> left;
- readonly Mapper<Middle, Right> right;
-
- public ChainedMapper(Mapper<Left, Middle> left, Mapper<Middle, Right> right)
- {
- this.left = left;
- this.right = right;
- }
-
- public Right map_from(Left item)
- {
- return right.map_from(left.map_from(item));
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class ChainedMapper<Left, Middle, Right> : Mapper<Left, Right> + { + readonly Mapper<Left, Middle> left; + readonly Mapper<Middle, Right> right; + + public ChainedMapper(Mapper<Left, Middle> left, Mapper<Middle, Right> right) + { + this.left = left; + this.right = right; + } + + public Right map_from(Left item) + { + return right.map_from(left.map_from(item)); + } + } +} diff --git a/lib/utility/Clock.cs b/lib/utility/Clock.cs index 522a0bd..1caaff5 100644 --- a/lib/utility/Clock.cs +++ b/lib/utility/Clock.cs @@ -1,36 +1,36 @@ -using System;
-
-namespace gorilla.utility
-{
- public static class Clock
- {
- private static Func<DateTime> time_provider;
-
- static Clock()
- {
- reset();
- }
-
- public static Date today()
- {
- return time_provider();
- }
-
- public static DateTime now()
- {
- return time_provider();
- }
-
-#if DEBUG
- public static void change_time_provider_to(Func<DateTime> new_time_provider)
- {
- if (new_time_provider != null) time_provider = new_time_provider;
- }
-#endif
-
- public static void reset()
- {
- time_provider = () => DateTime.Now;
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public static class Clock + { + private static Func<DateTime> time_provider; + + static Clock() + { + reset(); + } + + public static Date today() + { + return time_provider(); + } + + public static DateTime now() + { + return time_provider(); + } + +#if DEBUG + public static void change_time_provider_to(Func<DateTime> new_time_provider) + { + if (new_time_provider != null) time_provider = new_time_provider; + } +#endif + + public static void reset() + { + time_provider = () => DateTime.Now; + } + } +} diff --git a/lib/utility/Command.cs b/lib/utility/Command.cs index c24064f..206df4b 100644 --- a/lib/utility/Command.cs +++ b/lib/utility/Command.cs @@ -1,12 +1,12 @@ -namespace gorilla.utility
-{
- public interface Command
- {
- void run();
- }
-
- public interface Command<in T>
- {
- void run(T item);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Command + { + void run(); + } + + public interface Command<in T> + { + void run(T item); + } +} diff --git a/lib/utility/CommandExtensions.cs b/lib/utility/CommandExtensions.cs index 6396261..c49f469 100644 --- a/lib/utility/CommandExtensions.cs +++ b/lib/utility/CommandExtensions.cs @@ -1,22 +1,22 @@ -using System;
-
-namespace gorilla.utility
-{
- static public class CommandExtensions
- {
- static public utility.Command then<Command>(this utility.Command left) where Command : utility.Command, new()
- {
- return then(left, new Command());
- }
-
- static public Command then(this Command left, Command right)
- {
- return new ChainedCommand(left, right);
- }
-
- static public Command then(this Command left, Action right)
- {
- return new ChainedCommand(left, new AnonymousCommand(right));
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + static public class CommandExtensions + { + static public utility.Command then<Command>(this utility.Command left) where Command : utility.Command, new() + { + return then(left, new Command()); + } + + static public Command then(this Command left, Command right) + { + return new ChainedCommand(left, right); + } + + static public Command then(this Command left, Action right) + { + return new ChainedCommand(left, new AnonymousCommand(right)); + } + } +} diff --git a/lib/utility/ComponentFactory.cs b/lib/utility/ComponentFactory.cs index 66d2a62..930f684 100644 --- a/lib/utility/ComponentFactory.cs +++ b/lib/utility/ComponentFactory.cs @@ -1,4 +1,4 @@ -namespace gorilla.utility
-{
- public interface ComponentFactory<T> : Factory<T> where T : new() {}
-}
\ No newline at end of file +namespace jive.utility +{ + public interface ComponentFactory<T> : Factory<T> where T : new() {} +} diff --git a/lib/utility/Configuration.cs b/lib/utility/Configuration.cs index 8931975..3fee84a 100644 --- a/lib/utility/Configuration.cs +++ b/lib/utility/Configuration.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Configuration<in T>
- {
- void configure(T item);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Configuration<in T> + { + void configure(T item); + } +} diff --git a/lib/utility/ConfigurationExtensions.cs b/lib/utility/ConfigurationExtensions.cs index b33a50c..ea13a44 100644 --- a/lib/utility/ConfigurationExtensions.cs +++ b/lib/utility/ConfigurationExtensions.cs @@ -1,16 +1,16 @@ -namespace gorilla.utility
-{
- static public class ConfigurationExtensions
- {
- static public Configuration<T> then<T>(this Configuration<T> first, Configuration<T> second)
- {
- return new ChainedConfiguration<T>(first, second);
- }
-
- static public T and_configure_with<T>(this T item, Configuration<T> configuration)
- {
- configuration.configure(item);
- return item;
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + static public class ConfigurationExtensions + { + static public Configuration<T> then<T>(this Configuration<T> first, Configuration<T> second) + { + return new ChainedConfiguration<T>(first, second); + } + + static public T and_configure_with<T>(this T item, Configuration<T> configuration) + { + configuration.configure(item); + return item; + } + } +} diff --git a/lib/utility/Context.cs b/lib/utility/Context.cs index 4827181..da0396e 100755..100644 --- a/lib/utility/Context.cs +++ b/lib/utility/Context.cs @@ -1,10 +1,10 @@ -namespace gorilla.utility
-{
- public interface Context
- {
- bool contains<T>(Key<T> key);
- void add<T>(Key<T> key, T value);
- T value_for<T>(Key<T> key);
- void remove<T>(Key<T> key);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Context + { + bool contains<T>(Key<T> key); + void add<T>(Key<T> key, T value); + T value_for<T>(Key<T> key); + void remove<T>(Key<T> key); + } +} diff --git a/lib/utility/ConversionExtensions.cs b/lib/utility/ConversionExtensions.cs index b75de40..e2d17ad 100644 --- a/lib/utility/ConversionExtensions.cs +++ b/lib/utility/ConversionExtensions.cs @@ -1,35 +1,35 @@ -using System;
-using System.Collections;
-
-namespace gorilla.utility
-{
- public static class ConversionExtensions
- {
- public static T downcast_to<T>(this object object_to_cast)
- {
- return (T) object_to_cast;
- }
-
- public static T converted_to<T>(this object item_to_convert)
- {
- if (item_to_convert.is_an_implementation_of<IConvertible>())
- return (T) Convert.ChangeType(item_to_convert, typeof (T));
- return item_to_convert.downcast_to<T>();
- }
-
- public static bool is_an_implementation_of<T>(this object item)
- {
- return item is T;
- }
-
- public static void call_on<T>(this object target, Action<T> action) where T : class
- {
- if (target as T != null) action(target as T);
- }
-
- public static void call_on_each<T>(this IEnumerable items, Action<T> action) where T : class
- {
- foreach (var item in items) item.call_on(action);
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections; + +namespace jive.utility +{ + public static class ConversionExtensions + { + public static T downcast_to<T>(this object object_to_cast) + { + return (T) object_to_cast; + } + + public static T converted_to<T>(this object item_to_convert) + { + if (item_to_convert.is_an_implementation_of<IConvertible>()) + return (T) Convert.ChangeType(item_to_convert, typeof (T)); + return item_to_convert.downcast_to<T>(); + } + + public static bool is_an_implementation_of<T>(this object item) + { + return item is T; + } + + public static void call_on<T>(this object target, Action<T> action) where T : class + { + if (target as T != null) action(target as T); + } + + public static void call_on_each<T>(this IEnumerable items, Action<T> action) where T : class + { + foreach (var item in items) item.call_on(action); + } + } +} diff --git a/lib/utility/Date.cs b/lib/utility/Date.cs index 6cf4580..c62e5c2 100644 --- a/lib/utility/Date.cs +++ b/lib/utility/Date.cs @@ -1,88 +1,88 @@ -using System;
-using System.Globalization;
-
-namespace gorilla.utility
-{
- [Serializable]
- public class Date : IComparable<Date>, IComparable, IEquatable<Date>
- {
- readonly long ticks;
-
- public Date(int year, int month, int day)
- {
- ticks = new DateTime(year, month, day).Ticks;
- }
-
- public bool is_in(Year the_year)
- {
- return the_year.represents(to_date_time());
- }
-
- public DateTime to_date_time()
- {
- return new DateTime(ticks);
- }
-
- static public implicit operator Date(DateTime date)
- {
- return new Date(date.Year, date.Month, date.Day);
- }
-
- static public implicit operator DateTime(Date date)
- {
- return date.to_date_time();
- }
-
- public int CompareTo(Date other)
- {
- var the_other_date = other.downcast_to<Date>();
- if (ticks.Equals(the_other_date.ticks))
- {
- return 0;
- }
- return ticks > the_other_date.ticks ? 1 : -1;
- }
-
- public bool Equals(Date other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return other.ticks == ticks;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Date)) return false;
- return Equals((Date) obj);
- }
-
- public override int GetHashCode()
- {
- return ticks.GetHashCode();
- }
-
- public static bool operator ==(Date left, Date right)
- {
- return Equals(left, right);
- }
-
- public static bool operator !=(Date left, Date right)
- {
- return !Equals(left, right);
- }
-
- public override string ToString()
- {
- return new DateTime(ticks, DateTimeKind.Local).ToString("MMM dd yyyy", CultureInfo.InvariantCulture);
- }
-
- int IComparable.CompareTo(object obj)
- {
- if (obj.is_an_implementation_of<Date>())
- return CompareTo(obj.downcast_to<Date>());
- throw new InvalidOperationException();
- }
- }
-}
\ No newline at end of file +using System; +using System.Globalization; + +namespace jive.utility +{ + [Serializable] + public class Date : IComparable<Date>, IComparable, IEquatable<Date> + { + readonly long ticks; + + public Date(int year, int month, int day) + { + ticks = new DateTime(year, month, day).Ticks; + } + + public bool is_in(Year the_year) + { + return the_year.represents(to_date_time()); + } + + public DateTime to_date_time() + { + return new DateTime(ticks); + } + + static public implicit operator Date(DateTime date) + { + return new Date(date.Year, date.Month, date.Day); + } + + static public implicit operator DateTime(Date date) + { + return date.to_date_time(); + } + + public int CompareTo(Date other) + { + var the_other_date = other.downcast_to<Date>(); + if (ticks.Equals(the_other_date.ticks)) + { + return 0; + } + return ticks > the_other_date.ticks ? 1 : -1; + } + + public bool Equals(Date other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other.ticks == ticks; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Date)) return false; + return Equals((Date) obj); + } + + public override int GetHashCode() + { + return ticks.GetHashCode(); + } + + public static bool operator ==(Date left, Date right) + { + return Equals(left, right); + } + + public static bool operator !=(Date left, Date right) + { + return !Equals(left, right); + } + + public override string ToString() + { + return new DateTime(ticks, DateTimeKind.Local).ToString("MMM dd yyyy", CultureInfo.InvariantCulture); + } + + int IComparable.CompareTo(object obj) + { + if (obj.is_an_implementation_of<Date>()) + return CompareTo(obj.downcast_to<Date>()); + throw new InvalidOperationException(); + } + } +} diff --git a/lib/utility/DefaultConstructorFactory.cs b/lib/utility/DefaultConstructorFactory.cs index 56d1a76..84bcef4 100644 --- a/lib/utility/DefaultConstructorFactory.cs +++ b/lib/utility/DefaultConstructorFactory.cs @@ -1,10 +1,10 @@ -namespace gorilla.utility
-{
- public class DefaultConstructorFactory<T> : ComponentFactory<T> where T : new()
- {
- public T create()
- {
- return new T();
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class DefaultConstructorFactory<T> : ComponentFactory<T> where T : new() + { + public T create() + { + return new T(); + } + } +} diff --git a/lib/utility/DisposableCommand.cs b/lib/utility/DisposableCommand.cs index 0e4320e..35532d2 100644 --- a/lib/utility/DisposableCommand.cs +++ b/lib/utility/DisposableCommand.cs @@ -1,6 +1,6 @@ -using System;
-
-namespace gorilla.utility
-{
- public interface DisposableCommand : Command, IDisposable {}
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public interface DisposableCommand : Command, IDisposable {} +} diff --git a/lib/utility/EmptyCallback.cs b/lib/utility/EmptyCallback.cs index e33a99b..03aebc6 100644 --- a/lib/utility/EmptyCallback.cs +++ b/lib/utility/EmptyCallback.cs @@ -1,9 +1,9 @@ -namespace gorilla.utility
-{
- public class EmptyCallback<T> : Callback<T>, Callback
- {
- public void run(T item) {}
-
- public void run() {}
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class EmptyCallback<T> : Callback<T>, Callback + { + public void run(T item) {} + + public void run() {} + } +} diff --git a/lib/utility/EmptyCommand.cs b/lib/utility/EmptyCommand.cs index ca47568..83fbf8f 100644 --- a/lib/utility/EmptyCommand.cs +++ b/lib/utility/EmptyCommand.cs @@ -1,9 +1,9 @@ -namespace gorilla.utility
-{
- public class EmptyCommand : Command
- {
- public void run()
- {
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class EmptyCommand : Command + { + public void run() + { + } + } +} diff --git a/lib/utility/EnumerableExtensions.cs b/lib/utility/EnumerableExtensions.cs index 148e423..20a54d5 100644 --- a/lib/utility/EnumerableExtensions.cs +++ b/lib/utility/EnumerableExtensions.cs @@ -1,46 +1,46 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace gorilla.utility
-{
- static public class EnumerableExtensions
- {
- static public IEnumerable<T> where<T>(this IEnumerable<T> items, Func<T, bool> condition_is_met)
- {
- return null == items ? Enumerable.Empty<T>() : items.Where(condition_is_met);
- }
-
- static public IList<T> databind<T>(this IEnumerable<T> items_to_bind_to)
- {
- return null == items_to_bind_to ? new List<T>() : items_to_bind_to.ToList();
- }
-
- static public IEnumerable<T> sorted_using<T>(this IEnumerable<T> items_to_sort, IComparer<T> sorting_algorithm)
- {
- var sorted_items = new List<T>(items_to_sort);
- sorted_items.Sort(sorting_algorithm);
- return sorted_items;
- }
-
- static public IEnumerable<T> all<T>(this IEnumerable<T> items)
- {
- foreach (var item in items ?? Enumerable.Empty<T>()) yield return item;
- }
-
- static public void each<T>(this IEnumerable<T> items, Action<T> action)
- {
- foreach (var item in items ?? Enumerable.Empty<T>()) action(item);
- }
-
- static public IEnumerable<T> join_with<T>(this IEnumerable<T> left, IEnumerable<T> right)
- {
- if (null == right) return left;
-
- var list = new List<T>();
- list.AddRange(left);
- list.AddRange(right);
- return list;
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using System.Linq; + +namespace jive.utility +{ + static public class EnumerableExtensions + { + static public IEnumerable<T> where<T>(this IEnumerable<T> items, Func<T, bool> condition_is_met) + { + return null == items ? Enumerable.Empty<T>() : items.Where(condition_is_met); + } + + static public IList<T> databind<T>(this IEnumerable<T> items_to_bind_to) + { + return null == items_to_bind_to ? new List<T>() : items_to_bind_to.ToList(); + } + + static public IEnumerable<T> sorted_using<T>(this IEnumerable<T> items_to_sort, IComparer<T> sorting_algorithm) + { + var sorted_items = new List<T>(items_to_sort); + sorted_items.Sort(sorting_algorithm); + return sorted_items; + } + + static public IEnumerable<T> all<T>(this IEnumerable<T> items) + { + foreach (var item in items ?? Enumerable.Empty<T>()) yield return item; + } + + static public void each<T>(this IEnumerable<T> items, Action<T> action) + { + foreach (var item in items ?? Enumerable.Empty<T>()) action(item); + } + + static public IEnumerable<T> join_with<T>(this IEnumerable<T> left, IEnumerable<T> right) + { + if (null == right) return left; + + var list = new List<T>(); + list.AddRange(left); + list.AddRange(right); + return list; + } + } +} diff --git a/lib/utility/ExpressionExtensions.cs b/lib/utility/ExpressionExtensions.cs index 65a08de..ebf5d85 100755..100644 --- a/lib/utility/ExpressionExtensions.cs +++ b/lib/utility/ExpressionExtensions.cs @@ -1,23 +1,23 @@ -using System;
-using System.Linq.Expressions;
-using System.Reflection;
-
-namespace gorilla.utility
-{
- static public class ExpressionExtensions
- {
- static public PropertyInfo pick_property<T>(this Expression<Func<T, object>> expression)
- {
- return (PropertyInfo) member_expression(expression).Member;
- }
-
- static MemberExpression member_expression<T>(Expression<Func<T, object>> expression)
- {
- if (expression.Body.NodeType == ExpressionType.Convert)
- return ((UnaryExpression) expression.Body).Operand as MemberExpression;
- if (expression.Body.NodeType == ExpressionType.MemberAccess)
- return expression.Body as MemberExpression;
- throw new NotImplementedException();
- }
- }
-}
\ No newline at end of file +using System; +using System.Linq.Expressions; +using System.Reflection; + +namespace jive.utility +{ + static public class ExpressionExtensions + { + static public PropertyInfo pick_property<T>(this Expression<Func<T, object>> expression) + { + return (PropertyInfo) member_expression(expression).Member; + } + + static MemberExpression member_expression<T>(Expression<Func<T, object>> expression) + { + if (expression.Body.NodeType == ExpressionType.Convert) + return ((UnaryExpression) expression.Body).Operand as MemberExpression; + if (expression.Body.NodeType == ExpressionType.MemberAccess) + return expression.Body as MemberExpression; + throw new NotImplementedException(); + } + } +} diff --git a/lib/utility/Factory.cs b/lib/utility/Factory.cs index 1463efb..50c1de7 100644 --- a/lib/utility/Factory.cs +++ b/lib/utility/Factory.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Factory<out T>
- {
- T create();
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Factory<out T> + { + T create(); + } +} diff --git a/lib/utility/FactoryDelegate.cs b/lib/utility/FactoryDelegate.cs index 7574541..95246c9 100644 --- a/lib/utility/FactoryDelegate.cs +++ b/lib/utility/FactoryDelegate.cs @@ -1,6 +1,6 @@ -namespace gorilla.utility
-{
- public delegate Out FactoryDelegate<in In, out Out>(In input);
-
- public delegate Out FactoryDelegate<out Out>();
-}
\ No newline at end of file +namespace jive.utility +{ + public delegate Out FactoryDelegate<in In, out Out>(In input); + + public delegate Out FactoryDelegate<out Out>(); +} diff --git a/lib/utility/FilteredVisitor.cs b/lib/utility/FilteredVisitor.cs index ce9417e..0f3cbf5 100644 --- a/lib/utility/FilteredVisitor.cs +++ b/lib/utility/FilteredVisitor.cs @@ -1,19 +1,19 @@ -namespace gorilla.utility
-{
- public class FilteredVisitor<T> : Visitor<T>
- {
- readonly Specification<T> condition;
- readonly Visitor<T> visitor;
-
- public FilteredVisitor(Specification<T> condition, Visitor<T> visitor)
- {
- this.condition = condition;
- this.visitor = visitor;
- }
-
- public void visit(T item_to_visit)
- {
- if (condition.is_satisfied_by(item_to_visit)) visitor.visit(item_to_visit);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class FilteredVisitor<T> : Visitor<T> + { + readonly Specification<T> condition; + readonly Visitor<T> visitor; + + public FilteredVisitor(Specification<T> condition, Visitor<T> visitor) + { + this.condition = condition; + this.visitor = visitor; + } + + public void visit(T item_to_visit) + { + if (condition.is_satisfied_by(item_to_visit)) visitor.visit(item_to_visit); + } + } +} diff --git a/lib/utility/FuncExtensions.cs b/lib/utility/FuncExtensions.cs index d02e9d8..d4be702 100644 --- a/lib/utility/FuncExtensions.cs +++ b/lib/utility/FuncExtensions.cs @@ -1,28 +1,28 @@ -using System;
-
-namespace gorilla.utility
-{
- static public class FuncExtensions
- {
- static public readonly object mutex = new object();
-
- static public Func<T> memorize<T>(this Func<T> item) where T : class
- {
- T the_implementation = null;
- return () =>
- {
- if (null == the_implementation)
- {
- lock (mutex)
- {
- if (null == the_implementation)
- {
- the_implementation = item();
- }
- }
- }
- return the_implementation;
- };
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + static public class FuncExtensions + { + static public readonly object mutex = new object(); + + static public Func<T> memorize<T>(this Func<T> item) where T : class + { + T the_implementation = null; + return () => + { + if (null == the_implementation) + { + lock (mutex) + { + if (null == the_implementation) + { + the_implementation = item(); + } + } + } + return the_implementation; + }; + } + } +} diff --git a/lib/utility/FuncSpecification.cs b/lib/utility/FuncSpecification.cs index 6a3bb67..203dcda 100644 --- a/lib/utility/FuncSpecification.cs +++ b/lib/utility/FuncSpecification.cs @@ -1,19 +1,19 @@ -using System;
-
-namespace gorilla.utility
-{
- public class FuncSpecification<T> : Specification<T>
- {
- Func<T, bool> condition;
-
- public FuncSpecification(Func<T, bool> condition)
- {
- this.condition = condition;
- }
-
- public bool is_satisfied_by(T item)
- {
- return condition(item);
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public class FuncSpecification<T> : Specification<T> + { + Func<T, bool> condition; + + public FuncSpecification(Func<T, bool> condition) + { + this.condition = condition; + } + + public bool is_satisfied_by(T item) + { + return condition(item); + } + } +} diff --git a/lib/utility/Id.cs b/lib/utility/Id.cs index aea61de..fa6ce1d 100644 --- a/lib/utility/Id.cs +++ b/lib/utility/Id.cs @@ -1,46 +1,46 @@ -using System;
-
-namespace gorilla.utility
-{
- [Serializable]
- public class Id<T>
- {
- static public readonly Id<T> Default = new Id<T>(default(T));
- readonly T id;
-
- public Id(T id)
- {
- this.id = id;
- }
-
- static public implicit operator Id<T>(T id)
- {
- return new Id<T>(id);
- }
-
- static public implicit operator T(Id<T> id)
- {
- return id.id;
- }
-
- public bool Equals(Id<T> other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return Equals(other.id, id);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Id<T>)) return false;
- return Equals((Id<T>) obj);
- }
-
- public override int GetHashCode()
- {
- return id.GetHashCode();
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + [Serializable] + public class Id<T> + { + static public readonly Id<T> Default = new Id<T>(default(T)); + readonly T id; + + public Id(T id) + { + this.id = id; + } + + static public implicit operator Id<T>(T id) + { + return new Id<T>(id); + } + + static public implicit operator T(Id<T> id) + { + return id.id; + } + + public bool Equals(Id<T> other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Equals(other.id, id); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Id<T>)) return false; + return Equals((Id<T>) obj); + } + + public override int GetHashCode() + { + return id.GetHashCode(); + } + } +} diff --git a/lib/utility/Identifiable.cs b/lib/utility/Identifiable.cs index 1273547..14a63dc 100644 --- a/lib/utility/Identifiable.cs +++ b/lib/utility/Identifiable.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Identifiable<T>
- {
- Id<T> id { get; }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Identifiable<T> + { + Id<T> id { get; } + } +} diff --git a/lib/utility/Import.cs b/lib/utility/Import.cs index 15de43f..6ca21a8 100644 --- a/lib/utility/Import.cs +++ b/lib/utility/Import.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Import<in T>
- {
- void import(T item);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Import<in T> + { + void import(T item); + } +} diff --git a/lib/utility/Key.cs b/lib/utility/Key.cs index 4c01741..0a72198 100755..100644 --- a/lib/utility/Key.cs +++ b/lib/utility/Key.cs @@ -1,12 +1,12 @@ -using System.Collections;
-
-namespace gorilla.utility
-{
- public interface Key<T>
- {
- bool is_found_in(IDictionary items);
- T parse_from(IDictionary items);
- void remove_from(IDictionary items);
- void add_value_to(IDictionary items, T value);
- }
-}
\ No newline at end of file +using System.Collections; + +namespace jive.utility +{ + public interface Key<T> + { + bool is_found_in(IDictionary items); + T parse_from(IDictionary items); + void remove_from(IDictionary items); + void add_value_to(IDictionary items, T value); + } +} diff --git a/lib/utility/ListExtensions.cs b/lib/utility/ListExtensions.cs index 9d30611..2508618 100644 --- a/lib/utility/ListExtensions.cs +++ b/lib/utility/ListExtensions.cs @@ -1,42 +1,42 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace gorilla.utility
-{
- static public class ListExtensions
- {
- static public IListConstraint<T> add<T>(this ICollection<T> items, T item)
- {
- return new ListConstraint<T>(items, item);
- }
-
- static public IListConstraint<T> add_range<T>(this ICollection<T> items, IEnumerable<T> item)
- {
- return new ListConstraint<T>(items, item.ToArray());
- }
- }
-
- public class ListConstraint<T> : IListConstraint<T>
- {
- readonly ICollection<T> items;
- readonly T[] items_to_add;
-
- public ListConstraint(ICollection<T> list_to_constrain, params T[] items_to_add)
- {
- items = list_to_constrain;
- this.items_to_add = items_to_add;
- items_to_add.each(list_to_constrain.Add);
- }
-
- public void unless(Func<T, bool> predicate)
- {
- items_to_add.where(predicate).each(x => items.Remove(x));
- }
- }
-
- public interface IListConstraint<T>
- {
- void unless(Func<T, bool> predicate);
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using System.Linq; + +namespace jive.utility +{ + static public class ListExtensions + { + static public IListConstraint<T> add<T>(this ICollection<T> items, T item) + { + return new ListConstraint<T>(items, item); + } + + static public IListConstraint<T> add_range<T>(this ICollection<T> items, IEnumerable<T> item) + { + return new ListConstraint<T>(items, item.ToArray()); + } + } + + public class ListConstraint<T> : IListConstraint<T> + { + readonly ICollection<T> items; + readonly T[] items_to_add; + + public ListConstraint(ICollection<T> list_to_constrain, params T[] items_to_add) + { + items = list_to_constrain; + this.items_to_add = items_to_add; + items_to_add.each(list_to_constrain.Add); + } + + public void unless(Func<T, bool> predicate) + { + items_to_add.where(predicate).each(x => items.Remove(x)); + } + } + + public interface IListConstraint<T> + { + void unless(Func<T, bool> predicate); + } +} diff --git a/lib/utility/Mapper.cs b/lib/utility/Mapper.cs index 5fd6cae..6515204 100644 --- a/lib/utility/Mapper.cs +++ b/lib/utility/Mapper.cs @@ -1,12 +1,12 @@ -namespace gorilla.utility
-{
- public interface Mapper<in Input, out Output>
- {
- Output map_from(Input item);
- }
-
- public interface Mapper
- {
- Output map_from<Input, Output>(Input item);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Mapper<in Input, out Output> + { + Output map_from(Input item); + } + + public interface Mapper + { + Output map_from<Input, Output>(Input item); + } +} diff --git a/lib/utility/MappingExtensions.cs b/lib/utility/MappingExtensions.cs index f177796..10bbcae 100644 --- a/lib/utility/MappingExtensions.cs +++ b/lib/utility/MappingExtensions.cs @@ -1,48 +1,48 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace gorilla.utility
-{
- static public class MappingExtensions
- {
- static public Output map_using<Input, Output>(this Input item, Converter<Input, Output> conversion)
- {
- return conversion(item);
- }
-
- static public Output map_using<Input, Output>(this Input item, Mapper<Input, Output> mapper)
- {
- return map_using(item, x => mapper.map_from(x));
- }
-
- static public Output map_using<Input, Output>(this Input item, Mapper mapper)
- {
- return map_using(item, x => mapper.map_from<Input, Output>(x));
- }
-
- static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
- Converter<Input, Output> mapper)
- {
- return null == items ? Enumerable.Empty<Output>() : items.Select(x => mapper(x));
- }
-
- static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
- Mapper<Input, Output> mapper)
- {
- return map_all_using(items, x => mapper.map_from(x));
- }
-
- static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
- Mapper mapper)
- {
- return map_all_using(items, x => mapper.map_from<Input, Output>(x));
- }
-
- static public Mapper<Left, Right> then<Left, Middle, Right>(this Mapper<Left, Middle> left,
- Mapper<Middle, Right> right)
- {
- return new ChainedMapper<Left, Middle, Right>(left, right);
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using System.Linq; + +namespace jive.utility +{ + static public class MappingExtensions + { + static public Output map_using<Input, Output>(this Input item, Converter<Input, Output> conversion) + { + return conversion(item); + } + + static public Output map_using<Input, Output>(this Input item, Mapper<Input, Output> mapper) + { + return map_using(item, x => mapper.map_from(x)); + } + + static public Output map_using<Input, Output>(this Input item, Mapper mapper) + { + return map_using(item, x => mapper.map_from<Input, Output>(x)); + } + + static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items, + Converter<Input, Output> mapper) + { + return null == items ? Enumerable.Empty<Output>() : items.Select(x => mapper(x)); + } + + static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items, + Mapper<Input, Output> mapper) + { + return map_all_using(items, x => mapper.map_from(x)); + } + + static public IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items, + Mapper mapper) + { + return map_all_using(items, x => mapper.map_from<Input, Output>(x)); + } + + static public Mapper<Left, Right> then<Left, Middle, Right>(this Mapper<Left, Middle> left, + Mapper<Middle, Right> right) + { + return new ChainedMapper<Left, Middle, Right>(left, right); + } + } +} diff --git a/lib/utility/NotSpecification.cs b/lib/utility/NotSpecification.cs index c9c0c49..c6985cf 100644 --- a/lib/utility/NotSpecification.cs +++ b/lib/utility/NotSpecification.cs @@ -1,17 +1,17 @@ -namespace gorilla.utility
-{
- public class NotSpecification<T> : Specification<T>
- {
- readonly Specification<T> item_to_match;
-
- public NotSpecification(Specification<T> item_to_match)
- {
- this.item_to_match = item_to_match;
- }
-
- public bool is_satisfied_by(T item)
- {
- return !item_to_match.is_satisfied_by(item);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class NotSpecification<T> : Specification<T> + { + readonly Specification<T> item_to_match; + + public NotSpecification(Specification<T> item_to_match) + { + this.item_to_match = item_to_match; + } + + public bool is_satisfied_by(T item) + { + return !item_to_match.is_satisfied_by(item); + } + } +} diff --git a/lib/utility/Notification.cs b/lib/utility/Notification.cs index 1e13e03..79e4012 100644 --- a/lib/utility/Notification.cs +++ b/lib/utility/Notification.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Notification
- {
- void notify(params NotificationMessage[] messages);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Notification + { + void notify(params NotificationMessage[] messages); + } +} diff --git a/lib/utility/NotificationMessage.cs b/lib/utility/NotificationMessage.cs index 8407d5a..aff41d5 100644 --- a/lib/utility/NotificationMessage.cs +++ b/lib/utility/NotificationMessage.cs @@ -1,42 +1,42 @@ -namespace gorilla.utility
-{
- public class NotificationMessage
- {
- public virtual string message { get; set; }
-
- static public implicit operator string(NotificationMessage message)
- {
- return message.ToString();
- }
-
- static public implicit operator NotificationMessage(string message)
- {
- return new NotificationMessage {message = message};
- }
-
- public override string ToString()
- {
- return message;
- }
-
- public bool Equals(NotificationMessage obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- return Equals(obj.message, message);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (NotificationMessage)) return false;
- return Equals((NotificationMessage) obj);
- }
-
- public override int GetHashCode()
- {
- return (message != null ? message.GetHashCode() : 0);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class NotificationMessage + { + public virtual string message { get; set; } + + static public implicit operator string(NotificationMessage message) + { + return message.ToString(); + } + + static public implicit operator NotificationMessage(string message) + { + return new NotificationMessage {message = message}; + } + + public override string ToString() + { + return message; + } + + public bool Equals(NotificationMessage obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return Equals(obj.message, message); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (NotificationMessage)) return false; + return Equals((NotificationMessage) obj); + } + + public override int GetHashCode() + { + return (message != null ? message.GetHashCode() : 0); + } + } +} diff --git a/lib/utility/NumericConversions.cs b/lib/utility/NumericConversions.cs index d95386c..7858ef5 100644 --- a/lib/utility/NumericConversions.cs +++ b/lib/utility/NumericConversions.cs @@ -1,22 +1,22 @@ -using System;
-
-namespace gorilla.utility
-{
- public static class NumericConversions
- {
- public static int to_int<T>(this T item) where T : IConvertible
- {
- return Convert.ChangeType(item, typeof (int)).downcast_to<int>();
- }
-
- public static long to_long<T>(this T item) where T : IConvertible
- {
- return Convert.ChangeType(item, typeof (long)).downcast_to<long>();
- }
-
- public static double to_double<T>(this T item) where T : IConvertible
- {
- return Convert.ChangeType(item, typeof (double)).downcast_to<double>();
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public static class NumericConversions + { + public static int to_int<T>(this T item) where T : IConvertible + { + return Convert.ChangeType(item, typeof (int)).downcast_to<int>(); + } + + public static long to_long<T>(this T item) where T : IConvertible + { + return Convert.ChangeType(item, typeof (long)).downcast_to<long>(); + } + + public static double to_double<T>(this T item) where T : IConvertible + { + return Convert.ChangeType(item, typeof (double)).downcast_to<double>(); + } + } +} diff --git a/lib/utility/OrSpecification.cs b/lib/utility/OrSpecification.cs index d002a65..95d9bac 100644 --- a/lib/utility/OrSpecification.cs +++ b/lib/utility/OrSpecification.cs @@ -1,19 +1,19 @@ -namespace gorilla.utility
-{
- public class OrSpecification<T> : Specification<T>
- {
- readonly Specification<T> left;
- readonly Specification<T> right;
-
- public OrSpecification(Specification<T> left, Specification<T> right)
- {
- this.left = left;
- this.right = right;
- }
-
- public bool is_satisfied_by(T item)
- {
- return left.is_satisfied_by(item) || right.is_satisfied_by(item);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class OrSpecification<T> : Specification<T> + { + readonly Specification<T> left; + readonly Specification<T> right; + + public OrSpecification(Specification<T> left, Specification<T> right) + { + this.left = left; + this.right = right; + } + + public bool is_satisfied_by(T item) + { + return left.is_satisfied_by(item) || right.is_satisfied_by(item); + } + } +} diff --git a/lib/utility/Parser.cs b/lib/utility/Parser.cs index 7e0d861..fbe3837 100644 --- a/lib/utility/Parser.cs +++ b/lib/utility/Parser.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Parser<out T>
- {
- T parse();
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Parser<out T> + { + T parse(); + } +} diff --git a/lib/utility/Percent.cs b/lib/utility/Percent.cs index e654209..0937da9 100644 --- a/lib/utility/Percent.cs +++ b/lib/utility/Percent.cs @@ -1,62 +1,62 @@ -using System;
-using System.Globalization;
-
-namespace gorilla.utility
-{
- public class Percent
- {
- readonly double percentage;
-
- public Percent(double percentage)
- {
- this.percentage = percentage;
- }
-
- public Percent(double portion_of_total, double total)
- {
- percentage = portion_of_total/total;
- percentage *= 100;
- percentage = Math.Round(percentage, 1);
- }
-
- public bool represents(Percent other_percent)
- {
- return Equals(other_percent);
- }
-
- public bool is_less_than(Percent other_percent)
- {
- return percentage.CompareTo(other_percent.percentage) < 0;
- }
-
- public static implicit operator Percent(double percentage)
- {
- return new Percent(percentage);
- }
-
- public bool Equals(Percent other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return other.percentage == percentage;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Percent)) return false;
- return Equals((Percent) obj);
- }
-
- public override int GetHashCode()
- {
- return percentage.GetHashCode();
- }
-
- public override string ToString()
- {
- return percentage.ToString(CultureInfo.InvariantCulture);
- }
- }
-}
\ No newline at end of file +using System; +using System.Globalization; + +namespace jive.utility +{ + public class Percent + { + readonly decimal percentage; + + public Percent(decimal percentage) + { + this.percentage = percentage; + } + + public Percent(decimal portion_of_total, decimal total) + { + percentage = portion_of_total/total; + percentage *= 100; + percentage = Math.Round(percentage, 1); + } + + public bool represents(Percent other_percent) + { + return Equals(other_percent); + } + + public bool is_less_than(Percent other_percent) + { + return percentage.CompareTo(other_percent.percentage) < 0; + } + + public static implicit operator Percent(decimal percentage) + { + return new Percent(percentage); + } + + public bool Equals(Percent other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return other.percentage == percentage; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Percent)) return false; + return Equals((Percent) obj); + } + + public override int GetHashCode() + { + return percentage.GetHashCode(); + } + + public override string ToString() + { + return percentage.ToString(CultureInfo.InvariantCulture); + } + } +} diff --git a/lib/utility/PredicateSpecification.cs b/lib/utility/PredicateSpecification.cs index e455546..b728979 100644 --- a/lib/utility/PredicateSpecification.cs +++ b/lib/utility/PredicateSpecification.cs @@ -1,19 +1,19 @@ -using System;
-
-namespace gorilla.utility
-{
- public class PredicateSpecification<T> : Specification<T>
- {
- readonly Predicate<T> criteria;
-
- public PredicateSpecification(Predicate<T> criteria)
- {
- this.criteria = criteria;
- }
-
- public bool is_satisfied_by(T item)
- {
- return criteria(item);
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public class PredicateSpecification<T> : Specification<T> + { + readonly Predicate<T> criteria; + + public PredicateSpecification(Predicate<T> criteria) + { + this.criteria = criteria; + } + + public bool is_satisfied_by(T item) + { + return criteria(item); + } + } +} diff --git a/lib/utility/Query.cs b/lib/utility/Query.cs index 48754a2..069c7a3 100644 --- a/lib/utility/Query.cs +++ b/lib/utility/Query.cs @@ -1,12 +1,12 @@ -namespace gorilla.utility
-{
- public interface Query<out TOutput>
- {
- TOutput fetch();
- }
-
- public interface Query<in TInput, out TOutput>
- {
- TOutput fetch(TInput item);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Query<out TOutput> + { + TOutput fetch(); + } + + public interface Query<in TInput, out TOutput> + { + TOutput fetch(TInput item); + } +} diff --git a/lib/utility/Registry.cs b/lib/utility/Registry.cs index 368a707..62aef0a 100644 --- a/lib/utility/Registry.cs +++ b/lib/utility/Registry.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic;
-
-namespace gorilla.utility
-{
- public interface Registry<out T> : IEnumerable<T>
- {
- IEnumerable<T> all();
- }
-}
\ No newline at end of file +using System.Collections.Generic; + +namespace jive.utility +{ + public interface Registry<out T> : IEnumerable<T> + { + IEnumerable<T> all(); + } +} diff --git a/lib/utility/RegistryExtensions.cs b/lib/utility/RegistryExtensions.cs index d995427..1ea20d0 100644 --- a/lib/utility/RegistryExtensions.cs +++ b/lib/utility/RegistryExtensions.cs @@ -1,29 +1,29 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace gorilla.utility
-{
- public static class RegistryExtensions
- {
- public static K find_an_implementation_of<T, K>(this Registry<T> registry) where K : T
- {
- try
- {
- return registry
- .all()
- .Single(p => p.is_an_implementation_of<K>())
- .downcast_to<K>();
- }
- catch (Exception exception)
- {
- throw new Exception("Could Not Find an implementation of".format(typeof (K)), exception);
- }
- }
-
- public static IEnumerable<T> sort_all_using<T>(this Registry<T> registry, IComparer<T> comparer)
- {
- return registry.all().sorted_using(comparer);
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using System.Linq; + +namespace jive.utility +{ + public static class RegistryExtensions + { + public static K find_an_implementation_of<T, K>(this Registry<T> registry) where K : T + { + try + { + return registry + .all() + .Single(p => p.is_an_implementation_of<K>()) + .downcast_to<K>(); + } + catch (Exception exception) + { + throw new Exception("Could Not Find an implementation of".format(typeof (K)), exception); + } + } + + public static IEnumerable<T> sort_all_using<T>(this Registry<T> registry, IComparer<T> comparer) + { + return registry.all().sorted_using(comparer); + } + } +} diff --git a/lib/utility/ScopedContext.cs b/lib/utility/ScopedContext.cs index 83e9003..bff0035 100755..100644 --- a/lib/utility/ScopedContext.cs +++ b/lib/utility/ScopedContext.cs @@ -1,32 +1,32 @@ -namespace gorilla.utility
-{
- public class ScopedContext : Context
- {
- ScopedStorage storage;
-
- public ScopedContext(ScopedStorage storage)
- {
- this.storage = storage;
- }
-
- public bool contains<T>(Key<T> key)
- {
- return key.is_found_in(storage.provide_storage());
- }
-
- public void add<T>(Key<T> key, T value)
- {
- key.add_value_to(storage.provide_storage(), value);
- }
-
- public T value_for<T>(Key<T> key)
- {
- return key.parse_from(storage.provide_storage());
- }
-
- public void remove<T>(Key<T> key)
- {
- key.remove_from(storage.provide_storage());
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public class ScopedContext : Context + { + ScopedStorage storage; + + public ScopedContext(ScopedStorage storage) + { + this.storage = storage; + } + + public bool contains<T>(Key<T> key) + { + return key.is_found_in(storage.provide_storage()); + } + + public void add<T>(Key<T> key, T value) + { + key.add_value_to(storage.provide_storage(), value); + } + + public T value_for<T>(Key<T> key) + { + return key.parse_from(storage.provide_storage()); + } + + public void remove<T>(Key<T> key) + { + key.remove_from(storage.provide_storage()); + } + } +} diff --git a/lib/utility/ScopedStorage.cs b/lib/utility/ScopedStorage.cs index b3394d4..18e1b29 100755..100644 --- a/lib/utility/ScopedStorage.cs +++ b/lib/utility/ScopedStorage.cs @@ -1,9 +1,9 @@ -using System.Collections;
-
-namespace gorilla.utility
-{
- public interface ScopedStorage
- {
- IDictionary provide_storage();
- }
-}
\ No newline at end of file +using System.Collections; + +namespace jive.utility +{ + public interface ScopedStorage + { + IDictionary provide_storage(); + } +} diff --git a/lib/utility/Settings.cs b/lib/utility/Settings.cs index 9d1f244..af7d50b 100755..100644 --- a/lib/utility/Settings.cs +++ b/lib/utility/Settings.cs @@ -1,19 +1,19 @@ -using System.Collections.Specialized;
-
-namespace gorilla.utility
-{
- public class Settings
- {
- NameValueCollection settings;
-
- public Settings(NameValueCollection settings)
- {
- this.settings = settings;
- }
-
- public T named<T>(string key)
- {
- return settings[key].converted_to<T>();
- }
- }
-}
\ No newline at end of file +using System.Collections.Specialized; + +namespace jive.utility +{ + public class Settings + { + NameValueCollection settings; + + public Settings(NameValueCollection settings) + { + this.settings = settings; + } + + public T named<T>(string key) + { + return settings[key].converted_to<T>(); + } + } +} diff --git a/lib/utility/SimpleContext.cs b/lib/utility/SimpleContext.cs index 884c2e8..491ca65 100755..100644 --- a/lib/utility/SimpleContext.cs +++ b/lib/utility/SimpleContext.cs @@ -1,34 +1,34 @@ -using System.Collections;
-
-namespace gorilla.utility
-{
- public class SimpleContext : Context
- {
- Hashtable items;
-
- public SimpleContext(Hashtable items)
- {
- this.items = items;
- }
-
- public bool contains<T>(Key<T> key)
- {
- return key.is_found_in(items);
- }
-
- public void add<T>(Key<T> key, T value)
- {
- key.add_value_to(items, value);
- }
-
- public T value_for<T>(Key<T> key)
- {
- return key.parse_from(items);
- }
-
- public void remove<T>(Key<T> key)
- {
- key.remove_from(items);
- }
- }
-}
\ No newline at end of file +using System.Collections; + +namespace jive.utility +{ + public class SimpleContext : Context + { + Hashtable items; + + public SimpleContext(Hashtable items) + { + this.items = items; + } + + public bool contains<T>(Key<T> key) + { + return key.is_found_in(items); + } + + public void add<T>(Key<T> key, T value) + { + key.add_value_to(items, value); + } + + public T value_for<T>(Key<T> key) + { + return key.parse_from(items); + } + + public void remove<T>(Key<T> key) + { + key.remove_from(items); + } + } +} diff --git a/lib/utility/Specification.cs b/lib/utility/Specification.cs index 81091a0..a5beeff 100644 --- a/lib/utility/Specification.cs +++ b/lib/utility/Specification.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Specification<in T>
- {
- bool is_satisfied_by(T item);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Specification<in T> + { + bool is_satisfied_by(T item); + } +} diff --git a/lib/utility/SpecificationExtensions.cs b/lib/utility/SpecificationExtensions.cs index a30dfe4..4138178 100644 --- a/lib/utility/SpecificationExtensions.cs +++ b/lib/utility/SpecificationExtensions.cs @@ -1,41 +1,41 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace gorilla.utility
-{
- static public class SpecificationExtensions
- {
- static public IEnumerable<T> that_satisfy<T>(this IEnumerable<T> items_to_peek_in_to,
- Predicate<T> criteria_to_satisfy)
- {
- foreach (var item in items_to_peek_in_to ?? Enumerable.Empty<T>())
- if (item.satisfies(criteria_to_satisfy)) yield return item;
- }
-
- static public bool satisfies<T>(this T item_to_interrogate, Predicate<T> criteria_to_satisfy)
- {
- return criteria_to_satisfy(item_to_interrogate);
- }
-
- static public bool satisfies<T>(this T item_to_validate, Specification<T> criteria_to_satisfy)
- {
- return item_to_validate.satisfies(criteria_to_satisfy.is_satisfied_by);
- }
-
- static public Specification<T> and<T>(this Specification<T> left, Specification<T> right)
- {
- return new PredicateSpecification<T>(x => left.is_satisfied_by(x) && right.is_satisfied_by(x));
- }
-
- static public Specification<T> or<T>(this Specification<T> left, Specification<T> right)
- {
- return new PredicateSpecification<T>(x => left.is_satisfied_by(x) || right.is_satisfied_by(x));
- }
-
- static public Specification<T> not<T>(this Specification<T> original)
- {
- return new PredicateSpecification<T>(x => !original.is_satisfied_by(x));
- }
- }
-}
\ No newline at end of file +using System; +using System.Collections.Generic; +using System.Linq; + +namespace jive.utility +{ + static public class SpecificationExtensions + { + static public IEnumerable<T> that_satisfy<T>(this IEnumerable<T> items_to_peek_in_to, + Predicate<T> criteria_to_satisfy) + { + foreach (var item in items_to_peek_in_to ?? Enumerable.Empty<T>()) + if (item.satisfies(criteria_to_satisfy)) yield return item; + } + + static public bool satisfies<T>(this T item_to_interrogate, Predicate<T> criteria_to_satisfy) + { + return criteria_to_satisfy(item_to_interrogate); + } + + static public bool satisfies<T>(this T item_to_validate, Specification<T> criteria_to_satisfy) + { + return item_to_validate.satisfies(criteria_to_satisfy.is_satisfied_by); + } + + static public Specification<T> and<T>(this Specification<T> left, Specification<T> right) + { + return new PredicateSpecification<T>(x => left.is_satisfied_by(x) && right.is_satisfied_by(x)); + } + + static public Specification<T> or<T>(this Specification<T> left, Specification<T> right) + { + return new PredicateSpecification<T>(x => left.is_satisfied_by(x) || right.is_satisfied_by(x)); + } + + static public Specification<T> not<T>(this Specification<T> original) + { + return new PredicateSpecification<T>(x => !original.is_satisfied_by(x)); + } + } +} diff --git a/lib/utility/State.cs b/lib/utility/State.cs index a904216..1d5bc48 100644 --- a/lib/utility/State.cs +++ b/lib/utility/State.cs @@ -1,6 +1,6 @@ -namespace gorilla.utility
-{
- public interface State
- {
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface State + { + } +} diff --git a/lib/utility/StringExtensions.cs b/lib/utility/StringExtensions.cs index 7e499b7..f015226 100644 --- a/lib/utility/StringExtensions.cs +++ b/lib/utility/StringExtensions.cs @@ -1,25 +1,25 @@ -namespace gorilla.utility
-{
- static public class StringExtensions
- {
- static public string format(this string formatted_string, params object[] arguments)
- {
- return string.Format(formatted_string, arguments);
- }
-
- static public bool is_equal_to_ignoring_case(this string left, string right)
- {
- return string.Compare(left, right, true) == 0;
- }
-
- static public bool is_blank(this string message)
- {
- return string.IsNullOrEmpty(message);
- }
-
- static public string to_string<T>(this T item)
- {
- return "{0}".format(item);
- }
- }
-}
\ No newline at end of file +namespace jive.utility +{ + static public class StringExtensions + { + static public string format(this string formatted_string, params object[] arguments) + { + return string.Format(formatted_string, arguments); + } + + static public bool is_equal_to_ignoring_case(this string left, string right) + { + return string.Compare(left, right, true) == 0; + } + + static public bool is_blank(this string message) + { + return string.IsNullOrEmpty(message); + } + + static public string to_string<T>(this T item) + { + return "{0}".format(item); + } + } +} diff --git a/lib/utility/SubjectOf.cs b/lib/utility/SubjectOf.cs index 4942750..957744e 100644 --- a/lib/utility/SubjectOf.cs +++ b/lib/utility/SubjectOf.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface SubjectOf<in State> where State : utility.State
- {
- void change_state_to(State new_state);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface SubjectOf<in State> where State : utility.State + { + void change_state_to(State new_state); + } +} diff --git a/lib/utility/TypeExtensions.cs b/lib/utility/TypeExtensions.cs index 0b2b625..3849287 100644 --- a/lib/utility/TypeExtensions.cs +++ b/lib/utility/TypeExtensions.cs @@ -1,40 +1,40 @@ -using System;
-using System.Linq;
-using System.Reflection;
-
-namespace gorilla.utility
-{
- public static class TypeExtensions
- {
- public static Type last_interface(this Type type)
- {
- return type.GetInterfaces()[type.GetInterfaces().Length - 1];
- }
-
- public static Type first_interface(this Type type)
- {
- return type.GetInterfaces()[0];
- }
-
- public static bool is_a_generic_type(this Type type)
- {
- //return type.IsGenericType;
- return type.IsGenericTypeDefinition;
- }
-
- public static object default_value(this Type type)
- {
- return (type.IsValueType ? Activator.CreateInstance(type) : null);
- }
-
- public static Attribute get_attribute<Attribute>(this ICustomAttributeProvider provider)
- where Attribute : System.Attribute
- {
- return
- provider
- .GetCustomAttributes(typeof (Attribute), false)
- .Select(x => x.downcast_to<Attribute>())
- .First();
- }
- }
-}
\ No newline at end of file +using System; +using System.Linq; +using System.Reflection; + +namespace jive.utility +{ + public static class TypeExtensions + { + public static Type last_interface(this Type type) + { + return type.GetInterfaces()[type.GetInterfaces().Length - 1]; + } + + public static Type first_interface(this Type type) + { + return type.GetInterfaces()[0]; + } + + public static bool is_a_generic_type(this Type type) + { + //return type.IsGenericType; + return type.IsGenericTypeDefinition; + } + + public static object default_value(this Type type) + { + return (type.IsValueType ? Activator.CreateInstance(type) : null); + } + + public static Attribute get_attribute<Attribute>(this ICustomAttributeProvider provider) + where Attribute : System.Attribute + { + return + provider + .GetCustomAttributes(typeof (Attribute), false) + .Select(x => x.downcast_to<Attribute>()) + .First(); + } + } +} diff --git a/lib/utility/ValueReturningVisitor.cs b/lib/utility/ValueReturningVisitor.cs index 9c5c37a..8ed3550 100644 --- a/lib/utility/ValueReturningVisitor.cs +++ b/lib/utility/ValueReturningVisitor.cs @@ -1,8 +1,8 @@ -namespace gorilla.utility
-{
- public interface ValueReturningVisitor<out Value, in T> : Visitor<T>
- {
- Value value { get; }
- void reset();
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface ValueReturningVisitor<out Value, in T> : Visitor<T> + { + Value value { get; } + void reset(); + } +} diff --git a/lib/utility/ValueType.cs b/lib/utility/ValueType.cs index 88d8872..b72af9c 100644 --- a/lib/utility/ValueType.cs +++ b/lib/utility/ValueType.cs @@ -1,37 +1,37 @@ -using System.Linq;
-
-namespace gorilla.utility
-{
- public class ValueType<T>
- {
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (!(obj is ValueType<T>)) return false;
- return Equals((ValueType<T>) obj);
- }
-
- public bool Equals(ValueType<T> other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return PropertiesMatch(other);
- }
-
- bool PropertiesMatch(ValueType<T> other)
- {
- return !GetType().GetProperties().Any(x =>
- {
- var thisValue = x.GetValue(this, null);
- var otherValue = x.GetValue(other, null);
- return !thisValue.Equals(otherValue);
- });
- }
-
- public override int GetHashCode()
- {
- return GetType().GetProperties().Aggregate(0, (prev, prop) => (prev*397) ^ prop.GetHashCode());
- }
- }
-}
\ No newline at end of file +using System.Linq; + +namespace jive.utility +{ + public class ValueType<T> + { + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (!(obj is ValueType<T>)) return false; + return Equals((ValueType<T>) obj); + } + + public bool Equals(ValueType<T> other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return PropertiesMatch(other); + } + + bool PropertiesMatch(ValueType<T> other) + { + return !GetType().GetProperties().Any(x => + { + var thisValue = x.GetValue(this, null); + var otherValue = x.GetValue(other, null); + return !thisValue.Equals(otherValue); + }); + } + + public override int GetHashCode() + { + return GetType().GetProperties().Aggregate(0, (prev, prop) => (prev*397) ^ prop.GetHashCode()); + } + } +} diff --git a/lib/utility/Visitable.cs b/lib/utility/Visitable.cs index 7fb8a5f..7427e8a 100644 --- a/lib/utility/Visitable.cs +++ b/lib/utility/Visitable.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Visitable<out T>
- {
- void accept(Visitor<T> visitor);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Visitable<out T> + { + void accept(Visitor<T> visitor); + } +} diff --git a/lib/utility/Visitor.cs b/lib/utility/Visitor.cs index 328e2ff..c04cb75 100644 --- a/lib/utility/Visitor.cs +++ b/lib/utility/Visitor.cs @@ -1,7 +1,7 @@ -namespace gorilla.utility
-{
- public interface Visitor<in T>
- {
- void visit(T item_to_visit);
- }
-}
\ No newline at end of file +namespace jive.utility +{ + public interface Visitor<in T> + { + void visit(T item_to_visit); + } +} diff --git a/lib/utility/Year.cs b/lib/utility/Year.cs index 6a1712e..c24c88b 100644 --- a/lib/utility/Year.cs +++ b/lib/utility/Year.cs @@ -1,53 +1,53 @@ -using System;
-
-namespace gorilla.utility
-{
- public class Year
- {
- readonly int the_underlying_year;
-
- public Year(int year) : this(new DateTime(year, 01, 01))
- {
- }
-
- public Year(DateTime date)
- {
- the_underlying_year = date.Year;
- }
-
- static public implicit operator Year(int year)
- {
- return new Year(year);
- }
-
- public bool Equals(Year obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- return obj.the_underlying_year == the_underlying_year;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Year)) return false;
- return Equals((Year) obj);
- }
-
- public override int GetHashCode()
- {
- return the_underlying_year;
- }
-
- public bool represents(DateTime time)
- {
- return time.Year.Equals(the_underlying_year);
- }
-
- public override string ToString()
- {
- return the_underlying_year.ToString();
- }
- }
-}
\ No newline at end of file +using System; + +namespace jive.utility +{ + public class Year + { + readonly int the_underlying_year; + + public Year(int year) : this(new DateTime(year, 01, 01)) + { + } + + public Year(DateTime date) + { + the_underlying_year = date.Year; + } + + static public implicit operator Year(int year) + { + return new Year(year); + } + + public bool Equals(Year obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return obj.the_underlying_year == the_underlying_year; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof (Year)) return false; + return Equals((Year) obj); + } + + public override int GetHashCode() + { + return the_underlying_year; + } + + public bool represents(DateTime time) + { + return time.Year.Equals(the_underlying_year); + } + + public override string ToString() + { + return the_underlying_year.ToString(); + } + } +} diff --git a/lib/utility/utility.csproj b/lib/utility/utility.csproj deleted file mode 100644 index 7a19f0b..0000000 --- a/lib/utility/utility.csproj +++ /dev/null @@ -1,154 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>gorilla.utility</RootNamespace>
- <AssemblyName>gorilla.utility</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- <FileUpgradeFlags>
- </FileUpgradeFlags>
- <OldToolsVersion>3.5</OldToolsVersion>
- <UpgradeBackupLocation />
- <PublishUrl>publish\</PublishUrl>
- <Install>true</Install>
- <InstallFrom>Disk</InstallFrom>
- <UpdateEnabled>false</UpdateEnabled>
- <UpdateMode>Foreground</UpdateMode>
- <UpdateInterval>7</UpdateInterval>
- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
- <UpdatePeriodically>false</UpdatePeriodically>
- <UpdateRequired>false</UpdateRequired>
- <MapFileExtensions>true</MapFileExtensions>
- <ApplicationRevision>0</ApplicationRevision>
- <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
- <IsWebBootstrapper>false</IsWebBootstrapper>
- <UseApplicationTrust>false</UseApplicationTrust>
- <BootstrapperEnabled>true</BootstrapperEnabled>
- <TargetFrameworkProfile />
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Clock.cs" />
- <Compile Include="AnonymousCommand.cs" />
- <Compile Include="AndSpecification.cs" />
- <Compile Include="AnonymousDisposable.cs" />
- <Compile Include="ChainedCommand.cs" />
- <Compile Include="ChainedConfiguration.cs" />
- <Compile Include="ChainedMapper.cs" />
- <Compile Include="EmptyCallback.cs" />
- <Compile Include="EmptyCommand.cs" />
- <Compile Include="DefaultConstructorFactory.cs" />
- <Compile Include="ExpressionExtensions.cs" />
- <Compile Include="FactoryDelegate.cs" />
- <Compile Include="FilteredVisitor.cs" />
- <Compile Include="FuncSpecification.cs" />
- <Compile Include="Builder.cs" />
- <Compile Include="Callback.cs" />
- <Compile Include="CallbackCommand.cs" />
- <Compile Include="Command.cs" />
- <Compile Include="Configuration.cs" />
- <Compile Include="ComponentFactory.cs" />
- <Compile Include="Context.cs" />
- <Compile Include="Id.cs" />
- <Compile Include="DisposableCommand.cs" />
- <Compile Include="Factory.cs" />
- <Compile Include="Identifiable.cs" />
- <Compile Include="Import.cs" />
- <Compile Include="ScopedStorage.cs" />
- <Compile Include="Key.cs" />
- <Compile Include="Mapper.cs" />
- <Compile Include="Notification.cs" />
- <Compile Include="Parser.cs" />
- <Compile Include="Query.cs" />
- <Compile Include="Registry.cs" />
- <Compile Include="ScopedContext.cs" />
- <Compile Include="Settings.cs" />
- <Compile Include="SimpleContext.cs" />
- <Compile Include="Specification.cs" />
- <Compile Include="State.cs" />
- <Compile Include="SubjectOf.cs" />
- <Compile Include="ValueReturningVisitor.cs" />
- <Compile Include="ValueType.cs" />
- <Compile Include="Visitable.cs" />
- <Compile Include="Visitor.cs" />
- <Compile Include="AnonymousMapper.cs" />
- <Compile Include="NotificationMessage.cs" />
- <Compile Include="NotSpecification.cs" />
- <Compile Include="OrSpecification.cs" />
- <Compile Include="PredicateSpecification.cs" />
- <Compile Include="Date.cs" />
- <Compile Include="CommandExtensions.cs" />
- <Compile Include="ConfigurationExtensions.cs" />
- <Compile Include="ConversionExtensions.cs" />
- <Compile Include="EnumerableExtensions.cs" />
- <Compile Include="FuncExtensions.cs" />
- <Compile Include="ListExtensions.cs" />
- <Compile Include="MappingExtensions.cs" />
- <Compile Include="NumericConversions.cs" />
- <Compile Include="RegistryExtensions.cs" />
- <Compile Include="SpecificationExtensions.cs" />
- <Compile Include="StringExtensions.cs" />
- <Compile Include="TypeExtensions.cs" />
- <Compile Include="Percent.cs" />
- <Compile Include="Year.cs" />
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <ItemGroup>
- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
- <Install>false</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
- <Visible>False</Visible>
- <ProductName>.NET Framework 3.5 SP1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- <BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
- <Visible>False</Visible>
- <ProductName>Windows Installer 3.1</ProductName>
- <Install>true</Install>
- </BootstrapperPackage>
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - -->
-</Project>
\ No newline at end of file diff --git a/spec/Call.cs b/spec/Call.cs index 74b3573..104ea1c 100644 --- a/spec/Call.cs +++ b/spec/Call.cs @@ -1,12 +1,12 @@ -using System;
-
-namespace specs
-{
- static public class call
- {
- static public Action to(Action action)
- {
- return action;
- }
- }
-}
\ No newline at end of file +using System; + +namespace specs +{ + static public class call + { + static public Action to(Action action) + { + return action; + } + } +} diff --git a/spec/Create.cs b/spec/Create.cs index 1717ba3..e3cf47c 100644 --- a/spec/Create.cs +++ b/spec/Create.cs @@ -1,21 +1,21 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Moq;
-
-namespace specs
-{
- static public class Create
- {
- static public Mock<Stub> an<Stub>() where Stub : class
- {
- return An<Stub>();
- }
-
- static public Mock<ItemToStub> An<ItemToStub>() where ItemToStub : class
- {
- return new Mock<ItemToStub>();
- }
- }
-}
+using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Moq; + +namespace specs +{ + static public class Create + { + static public Mock<Stub> an<Stub>() where Stub : class + { + return An<Stub>(); + } + + static public Mock<ItemToStub> An<ItemToStub>() where ItemToStub : class + { + return new Mock<ItemToStub>(); + } + } +} diff --git a/spec/assertions.cs b/spec/assertions.cs index 8c71ad6..dd887ef 100644 --- a/spec/assertions.cs +++ b/spec/assertions.cs @@ -1,94 +1,94 @@ -using System;
-using System.Collections.Generic;
-using System.Linq;
-using Machine.Specifications;
-
-namespace specs
-{
- static public class Assertions
- {
- static public void should_be_equal_to<T>(this T item_to_validate, T expected_value)
- {
- item_to_validate.ShouldEqual(expected_value);
- }
-
- static public void should_be_the_same_instance_as<T>(this T left, T right)
- {
- ReferenceEquals(left, right).ShouldBeTrue();
- }
-
- static public void should_be_null<T>(this T item)
- {
- item.ShouldBeNull();
- }
-
- static public void should_not_be_null<T>(this T item) where T : class
- {
- item.ShouldNotBeNull();
- }
-
- static public void should_be_greater_than<T>(this T actual, T expected) where T : IComparable
- {
- actual.ShouldBeGreaterThan(expected);
- }
-
- static public void should_be_less_than(this int actual, int expected)
- {
- actual.ShouldBeLessThan(expected);
- }
-
- static public void should_contain<T>(this IEnumerable<T> items_to_peek_in_to, T items_to_look_for)
- {
- items_to_peek_in_to.Contains(items_to_look_for).should_be_true();
- }
-
- static public void should_not_contain<T>(this IEnumerable<T> items_to_peek_into, T item_to_look_for)
- {
- items_to_peek_into.Contains(item_to_look_for).should_be_false();
- }
-
- //static public void should_be_an_instance_of<T>(this object item)
- //{
- //item.should_be_an_instance_of(typeof (T));
- //}
-
- //static public void should_be_an_instance_of(this object item, Type type)
- //{
- //item.ShouldBe(type);
- //}
-
- static public void should_have_thrown<TheException>(this Action action) where TheException : Exception
- {
- typeof (TheException).ShouldBeThrownBy(action);
- }
-
- static public void should_be_true(this bool item)
- {
- item.ShouldBeTrue();
- }
-
- static public void should_be_false(this bool item)
- {
- item.ShouldBeFalse();
- }
-
- static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find)
- {
- foreach (var item_to_find in items_to_find)
- {
- items.should_contain(item_to_find);
- }
- }
-
- static public void should_only_contain<T>(this IEnumerable<T> items, params T[] itemsToFind)
- {
- items.Count().should_be_equal_to(itemsToFind.Length);
- items.should_contain(itemsToFind);
- }
-
- static public void should_be_equal_ignoring_case(this string item, string other)
- {
- item.ShouldBeEqualIgnoringCase(other);
- }
- }
-}
+using System; +using System.Collections.Generic; +using System.Linq; +using Machine.Specifications; + +namespace specs +{ + static public class Assertions + { + static public void should_be_equal_to<T>(this T item_to_validate, T expected_value) + { + item_to_validate.ShouldEqual(expected_value); + } + + static public void should_be_the_same_instance_as<T>(this T left, T right) + { + ReferenceEquals(left, right).ShouldBeTrue(); + } + + static public void should_be_null<T>(this T item) + { + item.ShouldBeNull(); + } + + static public void should_not_be_null<T>(this T item) where T : class + { + item.ShouldNotBeNull(); + } + + static public void should_be_greater_than<T>(this T actual, T expected) where T : IComparable + { + actual.ShouldBeGreaterThan(expected); + } + + static public void should_be_less_than(this int actual, int expected) + { + actual.ShouldBeLessThan(expected); + } + + static public void should_contain<T>(this IEnumerable<T> items_to_peek_in_to, T items_to_look_for) + { + items_to_peek_in_to.Contains(items_to_look_for).should_be_true(); + } + + static public void should_not_contain<T>(this IEnumerable<T> items_to_peek_into, T item_to_look_for) + { + items_to_peek_into.Contains(item_to_look_for).should_be_false(); + } + + //static public void should_be_an_instance_of<T>(this object item) + //{ + //item.should_be_an_instance_of(typeof (T)); + //} + + //static public void should_be_an_instance_of(this object item, Type type) + //{ + //item.ShouldBe(type); + //} + + static public void should_have_thrown<TheException>(this Action action) where TheException : Exception + { + typeof (TheException).ShouldBeThrownBy(action); + } + + static public void should_be_true(this bool item) + { + item.ShouldBeTrue(); + } + + static public void should_be_false(this bool item) + { + item.ShouldBeFalse(); + } + + static public void should_contain<T>(this IEnumerable<T> items, params T[] items_to_find) + { + foreach (var item_to_find in items_to_find) + { + items.should_contain(item_to_find); + } + } + + static public void should_only_contain<T>(this IEnumerable<T> items, params T[] itemsToFind) + { + items.Count().should_be_equal_to(itemsToFind.Length); + items.should_contain(itemsToFind); + } + + static public void should_be_equal_ignoring_case(this string item, string other) + { + item.ShouldBeEqualIgnoringCase(other); + } + } +} diff --git a/spec/unit/infrastructure/cloning/BinarySerializerSpecs.cs b/spec/unit/infrastructure/cloning/BinarySerializerSpecs.cs index 448236e..7a98d93 100644 --- a/spec/unit/infrastructure/cloning/BinarySerializerSpecs.cs +++ b/spec/unit/infrastructure/cloning/BinarySerializerSpecs.cs @@ -1,85 +1,85 @@ -using System;
-using System.IO;
-using gorilla.infrastructure.cloning;
-using Machine.Specifications;
-
-namespace specs.unit.infrastructure.cloning
-{
- [Subject(typeof (BinarySerializer<TestItem>))]
- public abstract class when_a_file_is_specified_to_serialize_an_item_to
- {
- static Serializer<TestItem> create_sut()
- {
- return new BinarySerializer<TestItem>(file_name);
- }
-
- Establish c = () =>
- {
- file_name = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "serialized.dat");
-
- sut = create_sut();
- };
-
- Cleanup aeo = () =>
- {
- if (File.Exists(file_name)) File.Delete(file_name);
- };
-
- static protected string file_name;
- static protected Serializer<TestItem> sut;
- }
-
- [Subject(typeof (BinarySerializer<TestItem>))]
- public class when_serializing_an_item : when_a_file_is_specified_to_serialize_an_item_to
- {
- It should_serialize_the_item_to_a_file = () => File.Exists(file_name).should_be_true();
-
- Because b = () => sut.serialize(new TestItem(string.Empty));
- }
-
- [Subject(typeof (BinarySerializer<TestItem>))]
- public class when_deserializing_an_item : when_a_file_is_specified_to_serialize_an_item_to
- {
- It should_be_able_to_deserialize_from_a_serialized_file = () => result.should_be_equal_to(original);
-
- Establish c = () =>
- {
- original = new TestItem("hello world");
- };
-
- Because b = () =>
- {
- sut.serialize(original);
- result = sut.deserialize();
- };
-
- static TestItem original;
- static TestItem result;
- }
-
- [Serializable]
- public class TestItem : IEquatable<TestItem>
- {
- public TestItem(string text)
- {
- Text = text;
- }
-
- public string Text { get; set; }
-
- public bool Equals(TestItem testItem)
- {
- return testItem != null;
- }
-
- public override bool Equals(object obj)
- {
- return ReferenceEquals(this, obj) || Equals(obj as TestItem);
- }
-
- public override int GetHashCode()
- {
- return 0;
- }
- }
-}
\ No newline at end of file +using System; +using System.IO; +using jive.infrastructure.cloning; +using Machine.Specifications; + +namespace specs.unit.infrastructure.cloning +{ + [Subject(typeof (BinarySerializer<TestItem>))] + public abstract class when_a_file_is_specified_to_serialize_an_item_to + { + static Serializer<TestItem> create_sut() + { + return new BinarySerializer<TestItem>(file_name); + } + + Establish c = () => + { + file_name = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "serialized.dat"); + + sut = create_sut(); + }; + + Cleanup aeo = () => + { + if (File.Exists(file_name)) File.Delete(file_name); + }; + + static protected string file_name; + static protected Serializer<TestItem> sut; + } + + [Subject(typeof (BinarySerializer<TestItem>))] + public class when_serializing_an_item : when_a_file_is_specified_to_serialize_an_item_to + { + It should_serialize_the_item_to_a_file = () => File.Exists(file_name).should_be_true(); + + Because b = () => sut.serialize(new TestItem(string.Empty)); + } + + [Subject(typeof (BinarySerializer<TestItem>))] + public class when_deserializing_an_item : when_a_file_is_specified_to_serialize_an_item_to + { + It should_be_able_to_deserialize_from_a_serialized_file = () => result.should_be_equal_to(original); + + Establish c = () => + { + original = new TestItem("hello world"); + }; + + Because b = () => + { + sut.serialize(original); + result = sut.deserialize(); + }; + + static TestItem original; + static TestItem result; + } + + [Serializable] + public class TestItem : IEquatable<TestItem> + { + public TestItem(string text) + { + Text = text; + } + + public string Text { get; set; } + + public bool Equals(TestItem testItem) + { + return testItem != null; + } + + public override bool Equals(object obj) + { + return ReferenceEquals(this, obj) || Equals(obj as TestItem); + } + + public override int GetHashCode() + { + return 0; + } + } +} diff --git a/spec/unit/infrastructure/container/ResolveSpecs.cs b/spec/unit/infrastructure/container/ResolveSpecs.cs index f1128cd..09248ce 100644 --- a/spec/unit/infrastructure/container/ResolveSpecs.cs +++ b/spec/unit/infrastructure/container/ResolveSpecs.cs @@ -1,62 +1,62 @@ -using System;
-using gorilla.infrastructure.container;
-using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.infrastructure.container
-{
- [Subject(typeof (Resolve))]
- public abstract class behaves_like_a_inversion_of_control_container
- {
- [Subject(typeof (Resolve))]
- public class when_resolving_a_dependency_using_the_container : behaves_like_a_inversion_of_control_container
- {
- Establish c = () =>
- {
- registry = Create.an<DependencyRegistry>();
- presenter = Create.an<Command>();
- registry.Setup(x => x.get_a<Command>()).Returns(presenter.Object);
- Resolve.initialize_with(registry.Object);
- };
-
- Because b = () =>
- {
- result = Resolve.the<Command>();
- };
-
- It should_leverage_the_underlying_container_it_was_initialized_with =
- () => registry.Verify(x => x.get_a<Command>());
-
- It should_return_the_resolved_dependency = () => result.should_be_equal_to(presenter.Object);
-
- Cleanup a = () => Resolve.initialize_with(null);
-
- static Moq.Mock<DependencyRegistry> registry;
- static Command result;
- static Moq.Mock<Command> presenter;
- }
-
- [Subject(typeof (Resolve))]
- public class when_resolving_a_dependency_that_is_not_registered_ : behaves_like_a_inversion_of_control_container
- {
- Establish c = () =>
- {
- registry = Create.an<DependencyRegistry>();
- registry.Setup(x => x.get_a<Command>()).Throws(new Exception());
- Resolve.initialize_with(registry.Object);
- };
-
- Because b = () =>
- {
- the_call = call.to(() => Resolve.the<Command>());
- };
-
- Cleanup a = () => Resolve.initialize_with(null);
-
- It should_throw_a_dependency_resolution_exception = () => the_call.should_have_thrown<DependencyResolutionException<Command>>();
-
- static Moq.Mock<DependencyRegistry> registry;
- static Action the_call;
- }
- }
-}
+using System; +using jive.infrastructure.container; +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.infrastructure.container +{ + [Subject(typeof (Resolve))] + public abstract class behaves_like_a_inversion_of_control_container + { + [Subject(typeof (Resolve))] + public class when_resolving_a_dependency_using_the_container : behaves_like_a_inversion_of_control_container + { + Establish c = () => + { + registry = Create.an<DependencyRegistry>(); + presenter = Create.an<Command>(); + registry.Setup(x => x.get_a<Command>()).Returns(presenter.Object); + Resolve.initialize_with(registry.Object); + }; + + Because b = () => + { + result = Resolve.the<Command>(); + }; + + It should_leverage_the_underlying_container_it_was_initialized_with = + () => registry.Verify(x => x.get_a<Command>()); + + It should_return_the_resolved_dependency = () => result.should_be_equal_to(presenter.Object); + + Cleanup a = () => Resolve.initialize_with(null); + + static Moq.Mock<DependencyRegistry> registry; + static Command result; + static Moq.Mock<Command> presenter; + } + + [Subject(typeof (Resolve))] + public class when_resolving_a_dependency_that_is_not_registered_ : behaves_like_a_inversion_of_control_container + { + Establish c = () => + { + registry = Create.an<DependencyRegistry>(); + registry.Setup(x => x.get_a<Command>()).Throws(new Exception()); + Resolve.initialize_with(registry.Object); + }; + + Because b = () => + { + the_call = call.to(() => Resolve.the<Command>()); + }; + + Cleanup a = () => Resolve.initialize_with(null); + + It should_throw_a_dependency_resolution_exception = () => the_call.should_have_thrown<DependencyResolutionException<Command>>(); + + static Moq.Mock<DependencyRegistry> registry; + static Action the_call; + } + } +} diff --git a/spec/unit/infrastructure/logging/LogSpecs.cs b/spec/unit/infrastructure/logging/LogSpecs.cs index 26b6b7c..2262bea 100644 --- a/spec/unit/infrastructure/logging/LogSpecs.cs +++ b/spec/unit/infrastructure/logging/LogSpecs.cs @@ -1,34 +1,34 @@ -using gorilla.infrastructure.container;
-using gorilla.infrastructure.logging;
-using Machine.Specifications;
-
-namespace specs.unit.infrastructure.logging
-{
- [Subject(typeof (Log))]
- public class when_creating_a_logger_for_a_particular_type
- {
- It should_return_the_logger_created_for_that_type = () => result.should_be_equal_to(logger.Object);
-
- Establish c =
- () =>
- {
- var factory = Create.an<LogFactory>();
- var registry = Create.an<DependencyRegistry>();
- logger = Create.an<Logger>();
- registry.Setup(x => x.get_a<LogFactory>()).Returns(factory.Object);
- factory.Setup(x => x.create_for(typeof (string))).Returns(logger.Object);
-
- Resolve.initialize_with(registry.Object);
- };
-
- Because b = () =>
- {
- result = Log.For("mo");
- };
-
- Cleanup a = () => Resolve.initialize_with(null);
-
- static Logger result;
- static Moq.Mock<Logger> logger;
- }
-}
+using jive.infrastructure.container; +using jive.infrastructure.logging; +using Machine.Specifications; + +namespace specs.unit.infrastructure.logging +{ + [Subject(typeof (Log))] + public class when_creating_a_logger_for_a_particular_type + { + It should_return_the_logger_created_for_that_type = () => result.should_be_equal_to(logger.Object); + + Establish c = + () => + { + var factory = Create.an<LogFactory>(); + var registry = Create.an<DependencyRegistry>(); + logger = Create.an<Logger>(); + registry.Setup(x => x.get_a<LogFactory>()).Returns(factory.Object); + factory.Setup(x => x.create_for(typeof (string))).Returns(logger.Object); + + Resolve.initialize_with(registry.Object); + }; + + Because b = () => + { + result = Log.For("mo"); + }; + + Cleanup a = () => Resolve.initialize_with(null); + + static Logger result; + static Moq.Mock<Logger> logger; + } +} diff --git a/spec/unit/infrastructure/proxies/ProxyFactorySpecs.cs b/spec/unit/infrastructure/proxies/ProxyFactorySpecs.cs index 4422d1e..481ba07 100644 --- a/spec/unit/infrastructure/proxies/ProxyFactorySpecs.cs +++ b/spec/unit/infrastructure/proxies/ProxyFactorySpecs.cs @@ -1,60 +1,60 @@ -//using gorilla.infrastructure.proxies;
-//using Machine.Specifications;
-
-//namespace specs.unit.infrastructure.proxies
-//{
- //public class ProxyFactorySpecs
- //{
- //[Subject(typeof (ProxyFactory))]
- //public class when_proxying_a_class_with_interceptors_applied
- //{
- //Establish c = () =>
- //{
- //interceptors = new MyNameIsSlimShadyInterceptor();
- //marshal_mathers = new Person("marshall mathers");
- //};
-
- //Because b =
- //() =>
- //{
- //some_celebrity = ProxyFactory.create<IPerson>(marshal_mathers, interceptors);
- //};
-
- //It should_all_each_interceptor_to_intercept_the_invocation =
- //() => some_celebrity.what_is_your_name().should_be_equal_to("slim shady");
-
- //static Person marshal_mathers;
- //static IPerson some_celebrity;
- //static Interceptor interceptors;
- //}
-
- //public interface IPerson
- //{
- //string what_is_your_name();
- //}
-
- //public class Person : IPerson
- //{
- //readonly string my_name;
-
- //public Person(string my_name)
- //{
- //this.my_name = my_name;
- //}
-
- //public string what_is_your_name()
- //{
- //return my_name;
- //}
- //}
-
- //public class MyNameIsSlimShadyInterceptor : Interceptor
- //{
- //public void intercept(Invocation invocation)
- //{
- //invocation.proceed();
- //invocation.return_value = "slim shady";
- //}
- //}
- //}
-//}
+//using jive.infrastructure.proxies; +//using Machine.Specifications; + +//namespace specs.unit.infrastructure.proxies +//{ + //public class ProxyFactorySpecs + //{ + //[Subject(typeof (ProxyFactory))] + //public class when_proxying_a_class_with_interceptors_applied + //{ + //Establish c = () => + //{ + //interceptors = new MyNameIsSlimShadyInterceptor(); + //marshal_mathers = new Person("marshall mathers"); + //}; + + //Because b = + //() => + //{ + //some_celebrity = ProxyFactory.create<IPerson>(marshal_mathers, interceptors); + //}; + + //It should_all_each_interceptor_to_intercept_the_invocation = + //() => some_celebrity.what_is_your_name().should_be_equal_to("slim shady"); + + //static Person marshal_mathers; + //static IPerson some_celebrity; + //static Interceptor interceptors; + //} + + //public interface IPerson + //{ + //string what_is_your_name(); + //} + + //public class Person : IPerson + //{ + //readonly string my_name; + + //public Person(string my_name) + //{ + //this.my_name = my_name; + //} + + //public string what_is_your_name() + //{ + //return my_name; + //} + //} + + //public class MyNameIsSlimShadyInterceptor : Interceptor + //{ + //public void intercept(Invocation invocation) + //{ + //invocation.proceed(); + //invocation.return_value = "slim shady"; + //} + //} + //} +//} diff --git a/spec/unit/infrastructure/registries/DefaultRegistrySpecs.cs b/spec/unit/infrastructure/registries/DefaultRegistrySpecs.cs index 743eaaa..02fefb0 100644 --- a/spec/unit/infrastructure/registries/DefaultRegistrySpecs.cs +++ b/spec/unit/infrastructure/registries/DefaultRegistrySpecs.cs @@ -1,39 +1,39 @@ -using System.Collections.Generic;
-using gorilla.infrastructure.container;
-using gorilla.infrastructure.registries;
-using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.infrastructure.registries
-{
- [Subject(typeof (DefaultRegistry<int>))]
- public class when_retrieving_all_the_items_from_the_default_repository
- {
- It should_leverage_the_resolver_to_retrieve_all_the_implementations =
- () => registry.Verify(r => r.get_all<int>());
-
- It should_return_the_items_resolved_by_the_registry = () => result.should_contain(24);
-
- Establish c = () =>
- {
- var items_to_return = new List<int> {24};
- registry = Create.an<DependencyRegistry>();
- registry.Setup(r => r.get_all<int>()).Returns(items_to_return);
- sut = create_sut();
- };
-
- static Registry<int> create_sut()
- {
- return new DefaultRegistry<int>(registry.Object);
- }
-
- Because b = () =>
- {
- result = sut.all();
- };
-
- static Moq.Mock<DependencyRegistry> registry;
- static IEnumerable<int> result;
- static Registry<int> sut;
- }
-}
+using System.Collections.Generic; +using jive.infrastructure.container; +using jive.infrastructure.registries; +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.infrastructure.registries +{ + [Subject(typeof (DefaultRegistry<int>))] + public class when_retrieving_all_the_items_from_the_default_repository + { + It should_leverage_the_resolver_to_retrieve_all_the_implementations = + () => registry.Verify(r => r.get_all<int>()); + + It should_return_the_items_resolved_by_the_registry = () => result.should_contain(24); + + Establish c = () => + { + var items_to_return = new List<int> {24}; + registry = Create.an<DependencyRegistry>(); + registry.Setup(r => r.get_all<int>()).Returns(items_to_return); + sut = create_sut(); + }; + + static Registry<int> create_sut() + { + return new DefaultRegistry<int>(registry.Object); + } + + Because b = () => + { + result = sut.all(); + }; + + static Moq.Mock<DependencyRegistry> registry; + static IEnumerable<int> result; + static Registry<int> sut; + } +} diff --git a/spec/unit/utility/ConfigurationExtensionsSpecs.cs b/spec/unit/utility/ConfigurationExtensionsSpecs.cs index 8ab43c6..85b8e4d 100644 --- a/spec/unit/utility/ConfigurationExtensionsSpecs.cs +++ b/spec/unit/utility/ConfigurationExtensionsSpecs.cs @@ -1,32 +1,32 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class ConfigurationExtensionsSpecs
- {
- public interface IDbCommand {
- void Execute();
- }
-
- public class when_configuring_an_item
- {
- It should_return_the_item_that_was_configured_when_completed = () => result.should_be_equal_to(item.Object);
-
- Establish context = () =>
- {
- configuration = Create.an<Configuration<IDbCommand>>();
- item = Create.an<IDbCommand>();
- };
-
- Because of = () =>
- {
- result = item.Object.and_configure_with(configuration.Object);
- };
-
- static Moq.Mock<Configuration<IDbCommand>> configuration;
- static Moq.Mock<IDbCommand> item;
- static IDbCommand result;
- }
- }
-}
+using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class ConfigurationExtensionsSpecs + { + public interface IDbCommand { + void Execute(); + } + + public class when_configuring_an_item + { + It should_return_the_item_that_was_configured_when_completed = () => result.should_be_equal_to(item.Object); + + Establish context = () => + { + configuration = Create.an<Configuration<IDbCommand>>(); + item = Create.an<IDbCommand>(); + }; + + Because of = () => + { + result = item.Object.and_configure_with(configuration.Object); + }; + + static Moq.Mock<Configuration<IDbCommand>> configuration; + static Moq.Mock<IDbCommand> item; + static IDbCommand result; + } + } +} diff --git a/spec/unit/utility/DateSpecs.cs b/spec/unit/utility/DateSpecs.cs index 8bc1bb8..728df13 100644 --- a/spec/unit/utility/DateSpecs.cs +++ b/spec/unit/utility/DateSpecs.cs @@ -1,34 +1,34 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class DateSpecs
- {
- [Subject(typeof (Date))]
- public class when_two_dates_that_represent_the_same_day_are_asked_if_they_are_equal
- {
- It should_return_true = () => result.should_be_equal_to(true);
-
- Because b = () =>
- {
- result = new Date(2008, 09, 25).Equals(new Date(2008, 09, 25));
- };
-
- static bool result;
- }
-
- [Subject(typeof (Date))]
- public class when_an_older_date_is_compared_to_a_younger_date
- {
- It should_return_a_positive_number = () => result.should_be_greater_than(0);
-
- Because b = () =>
- {
- result = new Date(2008, 09, 25).CompareTo(new Date(2007, 01, 01));
- };
-
- static int result;
- }
- }
-}
\ No newline at end of file +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class DateSpecs + { + [Subject(typeof (Date))] + public class when_two_dates_that_represent_the_same_day_are_asked_if_they_are_equal + { + It should_return_true = () => result.should_be_equal_to(true); + + Because b = () => + { + result = new Date(2008, 09, 25).Equals(new Date(2008, 09, 25)); + }; + + static bool result; + } + + [Subject(typeof (Date))] + public class when_an_older_date_is_compared_to_a_younger_date + { + It should_return_a_positive_number = () => result.should_be_greater_than(0); + + Because b = () => + { + result = new Date(2008, 09, 25).CompareTo(new Date(2007, 01, 01)); + }; + + static int result; + } + } +} diff --git a/spec/unit/utility/EnumerableExtensionsSpecs.cs b/spec/unit/utility/EnumerableExtensionsSpecs.cs index c1ec4db..57636c3 100644 --- a/spec/unit/utility/EnumerableExtensionsSpecs.cs +++ b/spec/unit/utility/EnumerableExtensionsSpecs.cs @@ -1,32 +1,32 @@ -using System.Collections.Generic;
-using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class EnumerableExtensionsSpecs
- {
- [Subject(typeof (EnumerableExtensions))]
- public class when_joining_one_collection_with_another
- {
- It should_return_the_items_from_both = () =>
- {
- results.should_contain(1);
- results.should_contain(2);
- };
-
- Because b = () =>
- {
- results = new List<int> {1}.join_with(new List<int> {2});
- };
-
- static IEnumerable<int> results;
- }
-
- [Subject(typeof (EnumerableExtensions))]
- public class when_attemping_to_join_a_list_with_a_null_value
- {
- It should_return_the_original_list = () => new List<int> {1}.join_with(null).should_contain(1);
- }
- }
-}
\ No newline at end of file +using System.Collections.Generic; +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class EnumerableExtensionsSpecs + { + [Subject(typeof (EnumerableExtensions))] + public class when_joining_one_collection_with_another + { + It should_return_the_items_from_both = () => + { + results.should_contain(1); + results.should_contain(2); + }; + + Because b = () => + { + results = new List<int> {1}.join_with(new List<int> {2}); + }; + + static IEnumerable<int> results; + } + + [Subject(typeof (EnumerableExtensions))] + public class when_attemping_to_join_a_list_with_a_null_value + { + It should_return_the_original_list = () => new List<int> {1}.join_with(null).should_contain(1); + } + } +} diff --git a/spec/unit/utility/ListExtensionsSpecs.cs b/spec/unit/utility/ListExtensionsSpecs.cs index 902e260..b1c694e 100644 --- a/spec/unit/utility/ListExtensionsSpecs.cs +++ b/spec/unit/utility/ListExtensionsSpecs.cs @@ -1,67 +1,67 @@ -using System.Collections.Generic;
-using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class ListExtensionsSpecs
- {
- [Subject(typeof (ListExtensions))]
- public class when_adding_an_item_to_a_list
- {
- Because b = () =>
- {
- list = new List<string>();
- list.add("mo");
- };
-
- It should_add_the_item_to_the_list = () => list.should_contain("mo");
-
- static List<string> list;
- }
-
- [Subject(typeof (ListExtensions))]
- public abstract class when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- Establish c = () =>
- {
- list = new List<string>();
- };
-
- static protected List<string> list;
- }
-
- [Subject(typeof (ListExtensions))]
- public class when_the_condition_is_not_met : when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- Because b = () => list.add("mo").unless(x => false);
-
- It should_add_the_item_to_the_list = () => list.should_contain("mo");
- }
-
- [Subject(typeof (ListExtensions))]
- public class when_the_condition_is_met : when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- Because b = () => list.add("mo").unless(x => true);
-
- It should_not_add_the_item_to_the_list = () => list.should_not_contain("mo");
- }
-
- [Subject(typeof (ListExtensions))]
- public class when_some_of_the_items_meet_the_conditions_and_some_do_not :
- when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- Because b = () => list
- .add_range(new List<string> {"mo", "khan"})
- .unless(x => x.Equals("mo"));
-
- It should_add_the_items_that_do_not_meet_the_condition = () =>
- {
- list.Count.should_be_equal_to(1);
- list.should_contain("khan");
- };
-
- It should_not_add_the_items_that_do_meet_the_condition = () => list.should_not_contain("mo");
- }
- }
-}
\ No newline at end of file +using System.Collections.Generic; +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class ListExtensionsSpecs + { + [Subject(typeof (ListExtensions))] + public class when_adding_an_item_to_a_list + { + Because b = () => + { + list = new List<string>(); + list.add("mo"); + }; + + It should_add_the_item_to_the_list = () => list.should_contain("mo"); + + static List<string> list; + } + + [Subject(typeof (ListExtensions))] + public abstract class when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met + { + Establish c = () => + { + list = new List<string>(); + }; + + static protected List<string> list; + } + + [Subject(typeof (ListExtensions))] + public class when_the_condition_is_not_met : when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met + { + Because b = () => list.add("mo").unless(x => false); + + It should_add_the_item_to_the_list = () => list.should_contain("mo"); + } + + [Subject(typeof (ListExtensions))] + public class when_the_condition_is_met : when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met + { + Because b = () => list.add("mo").unless(x => true); + + It should_not_add_the_item_to_the_list = () => list.should_not_contain("mo"); + } + + [Subject(typeof (ListExtensions))] + public class when_some_of_the_items_meet_the_conditions_and_some_do_not : + when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met + { + Because b = () => list + .add_range(new List<string> {"mo", "khan"}) + .unless(x => x.Equals("mo")); + + It should_add_the_items_that_do_not_meet_the_condition = () => + { + list.Count.should_be_equal_to(1); + list.should_contain("khan"); + }; + + It should_not_add_the_items_that_do_meet_the_condition = () => list.should_not_contain("mo"); + } + } +} diff --git a/spec/unit/utility/MappingExtensionsSpecs.cs b/spec/unit/utility/MappingExtensionsSpecs.cs index 8257726..152af1f 100644 --- a/spec/unit/utility/MappingExtensionsSpecs.cs +++ b/spec/unit/utility/MappingExtensionsSpecs.cs @@ -1,32 +1,32 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- [Subject(typeof (MappingExtensions))]
- public class when_transforming_type_A_to_type_B_then_C
- {
- It should_return_the_correct_result = () => result.should_be_equal_to(1);
-
- Establish c = () =>
- {
- first_mapper = Create.an<Mapper<object, string>>();
- second_mapper = Create.an<Mapper<string, int>>();
- a = 1;
-
- first_mapper.Setup(x => x.map_from(a)).Returns("1");
- second_mapper.Setup(x => x.map_from("1")).Returns(1);
- };
-
- Because b = () =>
- {
- result = first_mapper.Object.then(second_mapper.Object).map_from(a);
- };
-
-
- static int result;
- static Moq.Mock<Mapper<object, string>> first_mapper;
- static Moq.Mock<Mapper<string, int>> second_mapper;
- static object a;
- }
-}
+using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + [Subject(typeof (MappingExtensions))] + public class when_transforming_type_A_to_type_B_then_C + { + It should_return_the_correct_result = () => result.should_be_equal_to(1); + + Establish c = () => + { + first_mapper = Create.an<Mapper<object, string>>(); + second_mapper = Create.an<Mapper<string, int>>(); + a = 1; + + first_mapper.Setup(x => x.map_from(a)).Returns("1"); + second_mapper.Setup(x => x.map_from("1")).Returns(1); + }; + + Because b = () => + { + result = first_mapper.Object.then(second_mapper.Object).map_from(a); + }; + + + static int result; + static Moq.Mock<Mapper<object, string>> first_mapper; + static Moq.Mock<Mapper<string, int>> second_mapper; + static object a; + } +} diff --git a/spec/unit/utility/NotSpecificationSpecs.cs b/spec/unit/utility/NotSpecificationSpecs.cs index 6481df8..f3f6ce4 100644 --- a/spec/unit/utility/NotSpecificationSpecs.cs +++ b/spec/unit/utility/NotSpecificationSpecs.cs @@ -1,57 +1,57 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class NotSpecificationSpecs
- {
- [Subject(typeof (NotSpecification<>))]
- public class when_checking_if_a_condition_is_not_met
- {
- static protected Moq.Mock<Specification<int>> criteria;
-
- Establish c = () =>
- {
- criteria = Create.An<Specification<int>>();
- sut = create_sut();
- };
-
- static protected Specification<int> sut;
-
- static Specification<int> create_sut()
- {
- return new NotSpecification<int>(criteria.Object);
- }
- }
-
- [Subject(typeof (NotSpecification<>))]
- public class when_a_condition_is_not_met : when_checking_if_a_condition_is_not_met
- {
- Establish c = () => criteria.Setup(x => x.is_satisfied_by(1)).Returns(false);
-
- Because b = () =>
- {
- result = sut.is_satisfied_by(1);
- };
-
- It should_return_true = () => result.should_be_true();
-
- static bool result;
- }
-
- [Subject(typeof (NotSpecification<>))]
- public class when_a_condition_is_met : when_checking_if_a_condition_is_not_met
- {
- Establish c = () => criteria.Setup(x => x.is_satisfied_by(1)).Returns(true);
-
- Because b = () =>
- {
- result = sut.is_satisfied_by(1);
- };
-
- It should_return_false = () => result.should_be_false();
-
- static bool result;
- }
- }
-}
+using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class NotSpecificationSpecs + { + [Subject(typeof (NotSpecification<>))] + public class when_checking_if_a_condition_is_not_met + { + static protected Moq.Mock<Specification<int>> criteria; + + Establish c = () => + { + criteria = Create.An<Specification<int>>(); + sut = create_sut(); + }; + + static protected Specification<int> sut; + + static Specification<int> create_sut() + { + return new NotSpecification<int>(criteria.Object); + } + } + + [Subject(typeof (NotSpecification<>))] + public class when_a_condition_is_not_met : when_checking_if_a_condition_is_not_met + { + Establish c = () => criteria.Setup(x => x.is_satisfied_by(1)).Returns(false); + + Because b = () => + { + result = sut.is_satisfied_by(1); + }; + + It should_return_true = () => result.should_be_true(); + + static bool result; + } + + [Subject(typeof (NotSpecification<>))] + public class when_a_condition_is_met : when_checking_if_a_condition_is_not_met + { + Establish c = () => criteria.Setup(x => x.is_satisfied_by(1)).Returns(true); + + Because b = () => + { + result = sut.is_satisfied_by(1); + }; + + It should_return_false = () => result.should_be_false(); + + static bool result; + } + } +} diff --git a/spec/unit/utility/NumericConversionsSpecs.cs b/spec/unit/utility/NumericConversionsSpecs.cs index dccefc4..0f80a68 100644 --- a/spec/unit/utility/NumericConversionsSpecs.cs +++ b/spec/unit/utility/NumericConversionsSpecs.cs @@ -1,31 +1,31 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- [Subject(typeof (NumericConversions))]
- public class when_converting_a_valid_string_to_a_long
- {
- It should_return_the_correct_result = () => result.should_be_equal_to(88L);
-
- Establish c = () => { valid_numeric_string = "88"; };
-
- Because b = () => { result = valid_numeric_string.to_long(); };
-
- static long result;
- static string valid_numeric_string;
- }
-
- [Subject(typeof (NumericConversions))]
- public class when_converting_a_valid_string_to_an_int
- {
- It should_return_the_correct_result = () => result.should_be_equal_to(66);
-
- Establish c = () => { valid_numeric_string = "66"; };
-
- Because b = () => { result = valid_numeric_string.to_int(); };
-
- static int result;
- static string valid_numeric_string;
- }
-}
\ No newline at end of file +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + [Subject(typeof (NumericConversions))] + public class when_converting_a_valid_string_to_a_long + { + It should_return_the_correct_result = () => result.should_be_equal_to(88L); + + Establish c = () => { valid_numeric_string = "88"; }; + + Because b = () => { result = valid_numeric_string.to_long(); }; + + static long result; + static string valid_numeric_string; + } + + [Subject(typeof (NumericConversions))] + public class when_converting_a_valid_string_to_an_int + { + It should_return_the_correct_result = () => result.should_be_equal_to(66); + + Establish c = () => { valid_numeric_string = "66"; }; + + Because b = () => { result = valid_numeric_string.to_int(); }; + + static int result; + static string valid_numeric_string; + } +} diff --git a/spec/unit/utility/OrSpecificationSpecs.cs b/spec/unit/utility/OrSpecificationSpecs.cs index 54bc418..9843d91 100644 --- a/spec/unit/utility/OrSpecificationSpecs.cs +++ b/spec/unit/utility/OrSpecificationSpecs.cs @@ -1,71 +1,71 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class OrSpecificationSpecs
- {
- [Subject(typeof (OrSpecification<>))]
- public abstract class when_checking_if_one_of_two_conditions_are_met
- {
- static Specification<int> create_sut()
- {
- return new OrSpecification<int>(left.Object, right.Object);
- }
-
- Establish c = () =>
- {
- left = Create.an<Specification<int>>();
- right = Create.an<Specification<int>>();
- sut = create_sut();
- };
-
- static protected Moq.Mock<Specification<int>> left;
- static protected Moq.Mock<Specification<int>> right;
- static protected Specification<int> sut;
- }
-
- [Subject(typeof (OrSpecification<>))]
- public class when_one_of_the_conditions_is_met : when_checking_if_one_of_two_conditions_are_met
- {
- It should_return_true = () => result.should_be_true();
-
- Establish c = () => left.Setup(x => x.is_satisfied_by(1)).Returns(true);
-
- Because b = () =>
- {
- result = sut.is_satisfied_by(1);
- };
-
- static bool result;
- }
-
- [Subject(typeof (OrSpecification<>))]
- public class when_the_second_condition_is_met : when_checking_if_one_of_two_conditions_are_met
- {
- It should_return_true = () => result.should_be_true();
-
- Establish c = () => right.Setup(x => x.is_satisfied_by(1)).Returns(true);
-
- Because b = () =>
- {
- result = sut.is_satisfied_by(1);
- };
-
- static bool result;
- }
-
- [Subject(typeof (OrSpecification<>))]
- public class when_neither_conditions_are_met : when_checking_if_one_of_two_conditions_are_met
- {
- It should_return_false = () => result.should_be_false();
-
- Because b = () =>
- {
- result = sut.is_satisfied_by(1);
- };
-
- static bool result;
- }
- }
-}
+using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class OrSpecificationSpecs + { + [Subject(typeof (OrSpecification<>))] + public abstract class when_checking_if_one_of_two_conditions_are_met + { + static Specification<int> create_sut() + { + return new OrSpecification<int>(left.Object, right.Object); + } + + Establish c = () => + { + left = Create.an<Specification<int>>(); + right = Create.an<Specification<int>>(); + sut = create_sut(); + }; + + static protected Moq.Mock<Specification<int>> left; + static protected Moq.Mock<Specification<int>> right; + static protected Specification<int> sut; + } + + [Subject(typeof (OrSpecification<>))] + public class when_one_of_the_conditions_is_met : when_checking_if_one_of_two_conditions_are_met + { + It should_return_true = () => result.should_be_true(); + + Establish c = () => left.Setup(x => x.is_satisfied_by(1)).Returns(true); + + Because b = () => + { + result = sut.is_satisfied_by(1); + }; + + static bool result; + } + + [Subject(typeof (OrSpecification<>))] + public class when_the_second_condition_is_met : when_checking_if_one_of_two_conditions_are_met + { + It should_return_true = () => result.should_be_true(); + + Establish c = () => right.Setup(x => x.is_satisfied_by(1)).Returns(true); + + Because b = () => + { + result = sut.is_satisfied_by(1); + }; + + static bool result; + } + + [Subject(typeof (OrSpecification<>))] + public class when_neither_conditions_are_met : when_checking_if_one_of_two_conditions_are_met + { + It should_return_false = () => result.should_be_false(); + + Because b = () => + { + result = sut.is_satisfied_by(1); + }; + + static bool result; + } + } +} diff --git a/spec/unit/utility/PercentSpecs.cs b/spec/unit/utility/PercentSpecs.cs index 287144e..bfe58dc 100644 --- a/spec/unit/utility/PercentSpecs.cs +++ b/spec/unit/utility/PercentSpecs.cs @@ -1,35 +1,35 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- [Subject(typeof (Percent))]
- public class when_comparing_fifty_divided_by_one_hundred_to_fifty_percent
- {
- It they_should_be_equal = () => new Percent(50, 100).should_be_equal_to<Percent>(50);
- }
-
- [Subject(typeof (Percent))]
- public class when_calculating_a_fractional_percentage
- {
- It should_return_the_correct_percentage = () => new Percent(30, 90).should_be_equal_to<Percent>(33.3);
- }
-
- [Subject(typeof (Percent))]
- public class when_checking_if_50_percent_is_less_than_51_percent
- {
- It should_return_true = () => new Percent(50).is_less_than(new Percent(51)).should_be_true();
- }
-
- [Subject(typeof (Percent))]
- public class when_checking_if_51_percent_is_less_than_50_percent
- {
- It should_return_false = () => new Percent(51).is_less_than(new Percent(50)).should_be_false();
- }
-
- [Subject(typeof (Percent))]
- public class when_checking_if_50_percent_is_less_than_50_percent
- {
- It should_return_false = () => new Percent(50).is_less_than(new Percent(50)).should_be_false();
- }
-}
\ No newline at end of file +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + [Subject(typeof (Percent))] + public class when_comparing_fifty_divided_by_one_hundred_to_fifty_percent + { + It they_should_be_equal = () => new Percent(50, 100).should_be_equal_to<Percent>(50); + } + + [Subject(typeof (Percent))] + public class when_calculating_a_fractional_percentage + { + It should_return_the_correct_percentage = () => new Percent(30, 90).should_be_equal_to<Percent>(33.3m); + } + + [Subject(typeof (Percent))] + public class when_checking_if_50_percent_is_less_than_51_percent + { + It should_return_true = () => new Percent(50).is_less_than(new Percent(51)).should_be_true(); + } + + [Subject(typeof (Percent))] + public class when_checking_if_51_percent_is_less_than_50_percent + { + It should_return_false = () => new Percent(51).is_less_than(new Percent(50)).should_be_false(); + } + + [Subject(typeof (Percent))] + public class when_checking_if_50_percent_is_less_than_50_percent + { + It should_return_false = () => new Percent(50).is_less_than(new Percent(50)).should_be_false(); + } +} diff --git a/spec/unit/utility/PredicateSpecificationSpecs.cs b/spec/unit/utility/PredicateSpecificationSpecs.cs index 2f2726e..94505b2 100644 --- a/spec/unit/utility/PredicateSpecificationSpecs.cs +++ b/spec/unit/utility/PredicateSpecificationSpecs.cs @@ -1,20 +1,20 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class PredicateSpecificationSpecs
- {
- [Subject(typeof (PredicateSpecification<>))]
- public class when_checking_if_a_criteria_is_met_and_it_is
- {
- It should_return_true = () => new PredicateSpecification<int>(x => true).is_satisfied_by(1).should_be_true();
- }
-
- [Subject(typeof (PredicateSpecification<>))]
- public class when_checking_if_a_criteria_is_met_and_it_is_not
- {
- It should_return_true = () => new PredicateSpecification<int>(x => false).is_satisfied_by(1).should_be_false();
- }
- }
-}
\ No newline at end of file +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class PredicateSpecificationSpecs + { + [Subject(typeof (PredicateSpecification<>))] + public class when_checking_if_a_criteria_is_met_and_it_is + { + It should_return_true = () => new PredicateSpecification<int>(x => true).is_satisfied_by(1).should_be_true(); + } + + [Subject(typeof (PredicateSpecification<>))] + public class when_checking_if_a_criteria_is_met_and_it_is_not + { + It should_return_true = () => new PredicateSpecification<int>(x => false).is_satisfied_by(1).should_be_false(); + } + } +} diff --git a/spec/unit/utility/SettingsSpecs.cs b/spec/unit/utility/SettingsSpecs.cs index ab4c4f5..0af30a0 100755 --- a/spec/unit/utility/SettingsSpecs.cs +++ b/spec/unit/utility/SettingsSpecs.cs @@ -1,32 +1,32 @@ -using System.Collections.Specialized;
-using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class SettingsSpecs
- {
- public abstract class concern
- {
- Establish context = () =>
- {
- settings = new NameValueCollection();
- sut = new Settings(settings);
- };
-
- static protected Settings sut;
- static protected NameValueCollection settings;
- }
-
- public class when_pulling_out_a_setting : concern
- {
- It should_return_the_correct_value = () => result.should_be_true();
-
- Establish context = () => { settings["the.key"] = "true"; };
-
- Because of = () => { result = sut.named<bool>("the.key"); };
-
- static bool result;
- }
- }
-}
\ No newline at end of file +using System.Collections.Specialized; +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class SettingsSpecs + { + public abstract class concern + { + Establish context = () => + { + settings = new NameValueCollection(); + sut = new Settings(settings); + }; + + static protected Settings sut; + static protected NameValueCollection settings; + } + + public class when_pulling_out_a_setting : concern + { + It should_return_the_correct_value = () => result.should_be_true(); + + Establish context = () => { settings["the.key"] = "true"; }; + + Because of = () => { result = sut.named<bool>("the.key"); }; + + static bool result; + } + } +} diff --git a/spec/unit/utility/SpecificationExtensionsSpecs.cs b/spec/unit/utility/SpecificationExtensionsSpecs.cs index 195c55f..aa3262e 100644 --- a/spec/unit/utility/SpecificationExtensionsSpecs.cs +++ b/spec/unit/utility/SpecificationExtensionsSpecs.cs @@ -1,78 +1,78 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class SpecificationExtensionsSpecs
- {
- public abstract class when_evaluating_two_conditions
- {
- Establish c = () =>
- {
- left = Create.an<Specification<int>>();
- right = Create.an<Specification<int>>();
- };
-
- static protected Moq.Mock<Specification<int>> left;
- static protected Moq.Mock<Specification<int>> right;
- }
-
- [Subject(typeof (SpecificationExtensions))]
- public class when_checking_if_two_conditions_are_met_and_they_are : when_evaluating_two_conditions
- {
- It should_return_true = () => result.should_be_true();
-
- Establish c = () =>
- {
- right.Setup(x => x.is_satisfied_by(1)).Returns(true);
- left.Setup(x => x.is_satisfied_by(1)).Returns(true);
- };
-
- Because b = () =>
- {
- result = left.Object.or(right.Object).is_satisfied_by(1);
- };
-
- static bool result;
- }
-
- [Subject(typeof (SpecificationExtensions))]
- public class when_checking_if_one_of_two_conditions_are_met_and_the_left_one_is_not : when_evaluating_two_conditions
- {
- It should_return_true = () => result.should_be_true();
-
- Establish c = () =>
- {
- right.Setup(x => x.is_satisfied_by(1)).Returns(true);
- left.Setup(x => x.is_satisfied_by(1)).Returns(false);
- };
-
- Because b = () =>
- {
- result = left.Object.or(right.Object).is_satisfied_by(1);
- };
-
- static bool result;
- }
-
- [Subject(typeof (SpecificationExtensions))]
- public class when_checking_if_one_of_two_conditions_are_met_and_the_right_one_is_not :
- when_evaluating_two_conditions
- {
- It should_return_true = () => result.should_be_true();
-
- Establish c = () =>
- {
- right.Setup(x => x.is_satisfied_by(1)).Returns(false);
- left.Setup(x => x.is_satisfied_by(1)).Returns(true);
- };
-
- Because b = () =>
- {
- result = left.Object.or(right.Object).is_satisfied_by(1);
- };
-
- static bool result;
- }
- }
-}
+using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class SpecificationExtensionsSpecs + { + public abstract class when_evaluating_two_conditions + { + Establish c = () => + { + left = Create.an<Specification<int>>(); + right = Create.an<Specification<int>>(); + }; + + static protected Moq.Mock<Specification<int>> left; + static protected Moq.Mock<Specification<int>> right; + } + + [Subject(typeof (SpecificationExtensions))] + public class when_checking_if_two_conditions_are_met_and_they_are : when_evaluating_two_conditions + { + It should_return_true = () => result.should_be_true(); + + Establish c = () => + { + right.Setup(x => x.is_satisfied_by(1)).Returns(true); + left.Setup(x => x.is_satisfied_by(1)).Returns(true); + }; + + Because b = () => + { + result = left.Object.or(right.Object).is_satisfied_by(1); + }; + + static bool result; + } + + [Subject(typeof (SpecificationExtensions))] + public class when_checking_if_one_of_two_conditions_are_met_and_the_left_one_is_not : when_evaluating_two_conditions + { + It should_return_true = () => result.should_be_true(); + + Establish c = () => + { + right.Setup(x => x.is_satisfied_by(1)).Returns(true); + left.Setup(x => x.is_satisfied_by(1)).Returns(false); + }; + + Because b = () => + { + result = left.Object.or(right.Object).is_satisfied_by(1); + }; + + static bool result; + } + + [Subject(typeof (SpecificationExtensions))] + public class when_checking_if_one_of_two_conditions_are_met_and_the_right_one_is_not : + when_evaluating_two_conditions + { + It should_return_true = () => result.should_be_true(); + + Establish c = () => + { + right.Setup(x => x.is_satisfied_by(1)).Returns(false); + left.Setup(x => x.is_satisfied_by(1)).Returns(true); + }; + + Because b = () => + { + result = left.Object.or(right.Object).is_satisfied_by(1); + }; + + static bool result; + } + } +} diff --git a/spec/unit/utility/TypeExtensionsSpecs.cs b/spec/unit/utility/TypeExtensionsSpecs.cs index 54bac16..54592a7 100644 --- a/spec/unit/utility/TypeExtensionsSpecs.cs +++ b/spec/unit/utility/TypeExtensionsSpecs.cs @@ -1,39 +1,39 @@ -using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class TypeExtensionsSpecs
- {
- [Subject(typeof (TypeExtensions))]
- public class when_getting_the_last_interface_for_a_type
- {
- It should_return_the_correct_one =
- () => typeof (TestType).last_interface().should_be_equal_to(typeof (ITestType));
- }
-
- [Subject(typeof (TypeExtensions))]
- public class when_getting_the_first_interface_for_a_type
- {
- It should_return_the_correct_one = () => typeof (TestType).first_interface().should_be_equal_to(typeof (IBase));
- }
-
- [Subject(typeof (TypeExtensions))]
- public class when_checking_if_a_type_represents_a_generic_type_definition
- {
- It should_tell_the_truth = () =>
- {
- typeof (Registry<>).is_a_generic_type().should_be_true();
- typeof (Registry<int>).is_a_generic_type().should_be_false();
- };
- }
-
- public interface IBase {}
-
- public class BaseType : IBase {}
-
- public interface ITestType {}
-
- public class TestType : BaseType, ITestType {}
- }
-}
\ No newline at end of file +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class TypeExtensionsSpecs + { + [Subject(typeof (TypeExtensions))] + public class when_getting_the_last_interface_for_a_type + { + It should_return_the_correct_one = + () => typeof (TestType).last_interface().should_be_equal_to(typeof (ITestType)); + } + + [Subject(typeof (TypeExtensions))] + public class when_getting_the_first_interface_for_a_type + { + It should_return_the_correct_one = () => typeof (TestType).first_interface().should_be_equal_to(typeof (IBase)); + } + + [Subject(typeof (TypeExtensions))] + public class when_checking_if_a_type_represents_a_generic_type_definition + { + It should_tell_the_truth = () => + { + typeof (Registry<>).is_a_generic_type().should_be_true(); + typeof (Registry<int>).is_a_generic_type().should_be_false(); + }; + } + + public interface IBase {} + + public class BaseType : IBase {} + + public interface ITestType {} + + public class TestType : BaseType, ITestType {} + } +} diff --git a/spec/unit/utility/ValueTypeSpecs.cs b/spec/unit/utility/ValueTypeSpecs.cs index 7c713bd..c079882 100644 --- a/spec/unit/utility/ValueTypeSpecs.cs +++ b/spec/unit/utility/ValueTypeSpecs.cs @@ -1,43 +1,43 @@ -using System;
-using gorilla.utility;
-using Machine.Specifications;
-
-namespace specs.unit.utility
-{
- public class ValueTypeSpecs
- {
- public class when_two_different_instances_of_the_same_type_have_the_same_values
- {
- It should_consider_them_equal = () =>
- {
- var birthDate = DateTime.Today;
- new TestType {first = "mo", BirthDate = birthDate}
- .ShouldEqual(new TestType {first = "mo", BirthDate = birthDate});
- };
- }
-
- public class when_comparing_a_single_instance
- {
- It should_consider_them_equal = () =>
- {
- var instance = new TestType {first = "mo", BirthDate = DateTime.Today};
- instance.ShouldEqual(instance);
- };
- }
-
- public class when_two_different_instances_of_the_same_type_have_different_values
- {
- It should_consider_them_equal = () =>
- {
- new TestType {first = "mo", BirthDate = DateTime.Today}
- .ShouldNotEqual(new TestType {first = "mo", BirthDate = DateTime.Today.AddDays(-1)});
- };
- }
-
- class TestType : ValueType<TestType>
- {
- public string first { get; set; }
- public DateTime BirthDate { get; set; }
- }
- }
-}
\ No newline at end of file +using System; +using jive.utility; +using Machine.Specifications; + +namespace specs.unit.utility +{ + public class ValueTypeSpecs + { + public class when_two_different_instances_of_the_same_type_have_the_same_values + { + It should_consider_them_equal = () => + { + var birthDate = DateTime.Today; + new TestType {first = "mo", BirthDate = birthDate} + .ShouldEqual(new TestType {first = "mo", BirthDate = birthDate}); + }; + } + + public class when_comparing_a_single_instance + { + It should_consider_them_equal = () => + { + var instance = new TestType {first = "mo", BirthDate = DateTime.Today}; + instance.ShouldEqual(instance); + }; + } + + public class when_two_different_instances_of_the_same_type_have_different_values + { + It should_consider_them_equal = () => + { + new TestType {first = "mo", BirthDate = DateTime.Today} + .ShouldNotEqual(new TestType {first = "mo", BirthDate = DateTime.Today.AddDays(-1)}); + }; + } + + class TestType : ValueType<TestType> + { + public string first { get; set; } + public DateTime BirthDate { get; set; } + } + } +} diff --git a/spec/unit/utility/VisitorExtensions.cs b/spec/unit/utility/VisitorExtensions.cs index b5fc4dd..cc9305e 100644 --- a/spec/unit/utility/VisitorExtensions.cs +++ b/spec/unit/utility/VisitorExtensions.cs @@ -1,20 +1,20 @@ -using System.Collections.Generic;
-using gorilla.utility;
-
-namespace specs.unit.utility
-{
- static public class VisitorExtensions
- {
- static public Result return_value_from_visiting_all_with<Result, T>(this IEnumerable<T> items, ValueReturningVisitor<Result, T> visitor)
- {
- visitor.reset();
- items.vist_all_with(visitor);
- return visitor.value;
- }
-
- static public void vist_all_with<T>(this IEnumerable<T> items, Visitor<T> visitor)
- {
- items.each(visitor.visit);
- }
- }
-}
\ No newline at end of file +using System.Collections.Generic; +using jive.utility; + +namespace specs.unit.utility +{ + static public class VisitorExtensions + { + static public Result return_value_from_visiting_all_with<Result, T>(this IEnumerable<T> items, ValueReturningVisitor<Result, T> visitor) + { + visitor.reset(); + items.vist_all_with(visitor); + return visitor.value; + } + + static public void vist_all_with<T>(this IEnumerable<T> items, Visitor<T> visitor) + { + items.each(visitor.visit); + } + } +} |
