Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Finished off some tests and logic for Cache saving and also looked at…

… loading Cache config into the Glass context.
  • Loading branch information...
commit d7389aa683f2166f37b36b2785afe4b52a058613 1 parent f115c06
@gravypower gravypower authored
Showing with 417 additions and 14 deletions.
  1. +9 −6 Source/Glass.Mapper/{ → Caching}/Configuration/AbstractObjectCacheConfiguration.cs
  2. +15 −0 Source/Glass.Mapper/Caching/Exceptions/DuplicatedKeyObjectCacheException.cs
  3. +15 −0 Source/Glass.Mapper/Caching/Exceptions/ObjectCacheException.cs
  4. +16 −2 Source/Glass.Mapper/Caching/ObjectCaching/AbstractObjectCache.cs
  5. +6 −0 Source/Glass.Mapper/Caching/ObjectCaching/IAbstractObjectCache.cs
  6. +21 −0 Source/Glass.Mapper/Context.cs
  7. +7 −1 Source/Glass.Mapper/Glass.Mapper.csproj
  8. +18 −0 Source/Glass.Mapper/Pipelines/ObjectConstruction/Tasks/ObjectCachingSaver/ObjectCachingSaverTask.cs
  9. +6 −0 Tests/Unit Tests/Glass.Mapper.Tests/Caching/CacheKeyFixture.cs
  10. +58 −0 Tests/Unit Tests/Glass.Mapper.Tests/Caching/Configuration/AbstractObjectCacheConfigurationFixture.cs
  11. +69 −0 Tests/Unit Tests/Glass.Mapper.Tests/Caching/Configuration/ContextFixture.cs
  12. +74 −2 Tests/Unit Tests/Glass.Mapper.Tests/Caching/ObjectCaching/AbstractObjectCacheFixture.cs
  13. +4 −0 Tests/Unit Tests/Glass.Mapper.Tests/Caching/ObjectCachingArgsFixture.cs
  14. +6 −0 Tests/Unit Tests/Glass.Mapper.Tests/Glass.Mapper.Tests.csproj
  15. +2 −3 ...s.Mapper.Tests/Pipelines/ObjectConstruction/Tasks/ObjectCachingResolver/ObjectCachingResolverTaskFixture.cs
  16. +91 −0 ...s/Glass.Mapper.Tests/Pipelines/ObjectConstruction/Tasks/ObjectCachingSaver/ObjectCachingSaverTaskFixture.cs
View
15 ...ation/AbstractObjectCacheConfiguration.cs → ...ation/AbstractObjectCacheConfiguration.cs
@@ -4,29 +4,32 @@
using System.Text;
using Glass.Mapper.Caching.ObjectCaching;
-namespace Glass.Mapper.Configuration
+namespace Glass.Mapper.Caching.Configuration
{
/// <summary>
- /// The class that holds the information about the Glass Cache configuration
+ ///
/// </summary>
public abstract class AbstractObjectCacheConfiguration
{
+ /// <summary>
+ /// The
+ /// </summary>
public IAbstractObjectCache ObjectCache { get; set; }
protected AbstractObjectCacheConfiguration()
- : this(Context.Default)
+ : this(Context.Default.DependencyResolver)
{
}
protected AbstractObjectCacheConfiguration(string contextName)
- : this(Context.Contexts[contextName])
+ : this(Context.Contexts[contextName].DependencyResolver)
{
}
- protected AbstractObjectCacheConfiguration(Context glassContext)
+ protected AbstractObjectCacheConfiguration(IDependencyResolver resolver)
{
- //ObjectCache = glassContext.DependencyResolver.TryResolve<IAbstractObjectCache>();
+ ObjectCache = resolver.Resolve<IAbstractObjectCache>();
}
}
}
View
15 Source/Glass.Mapper/Caching/Exceptions/DuplicatedKeyObjectCacheException.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Glass.Mapper.Caching.Exceptions
+{
+ public class DuplicatedKeyObjectCacheException : ObjectCacheException
+ {
+ public DuplicatedKeyObjectCacheException(string message)
+ : base(message)
+ {
+ }
+ }
+}
View
15 Source/Glass.Mapper/Caching/Exceptions/ObjectCacheException.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Glass.Mapper.Caching.Exceptions
+{
+ public abstract class ObjectCacheException : Exception
+ {
+ protected ObjectCacheException(string message)
+ : base(message)
+ {
+ }
+ }
+}
View
18 Source/Glass.Mapper/Caching/ObjectCaching/AbstractObjectCache.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Glass.Mapper.Caching.Exceptions;
namespace Glass.Mapper.Caching.ObjectCaching
{
@@ -13,16 +14,29 @@ public abstract class AbstractObjectCache<TIdType> : IAbstractObjectCache
protected AbstractCacheKeyResolver<TIdType> CacheKeyResolver;
protected abstract bool InternalContansObject(string objectKey);
+ protected abstract void InternalAddObject(string objectKey, object objectForCaching);
+ protected abstract object InternalGetObject(string objectKey);
public bool ContansObject(Pipelines.ObjectConstruction.ObjectCachingArgs args)
{
return InternalContansObject(CacheKeyResolver.GetKey(args).ToString());
}
-
public object GetObject(Pipelines.ObjectConstruction.ObjectCachingArgs args)
{
- throw new NotImplementedException();
+ return InternalGetObject(CacheKeyResolver.GetKey(args).ToString());
+ }
+
+ public void AddObject(Pipelines.ObjectConstruction.ObjectCachingArgs args)
+ {
+ var objectKey = CacheKeyResolver.GetKey(args).ToString();
+
+ if (InternalContansObject(objectKey))
+ {
+ throw new DuplicatedKeyObjectCacheException("Key exists in object cache already");
+ }
+
+ InternalAddObject(objectKey, args.Result);
}
/// <summary>
View
6 Source/Glass.Mapper/Caching/ObjectCaching/IAbstractObjectCache.cs
@@ -24,5 +24,11 @@ public interface IAbstractObjectCache
/// <param name="args">The arguments for the request</param>
/// <returns>the object from Cache</returns>
object GetObject(ObjectCachingArgs args);
+
+ /// <summary>
+ /// Adds and object to the Cache
+ /// </summary>
+ /// <param name="args">The arguments for the request</param>
+ void AddObject(ObjectCachingArgs args);
}
}
View
21 Source/Glass.Mapper/Context.cs
@@ -19,6 +19,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using Glass.Mapper.Caching.Configuration;
using Glass.Mapper.Configuration;
using Glass.Mapper.Pipelines.DataMapperResolver;
@@ -118,6 +119,8 @@ public static void Clear()
/// </summary>
public AbstractObjectCacheConfiguration ObjectCacheConfiguration { get; set; }
+
+
/// <summary>
/// Prevents a default instance of the <see cref="Context"/> class from being created.
/// </summary>
@@ -228,6 +231,24 @@ public AbstractTypeConfiguration GetTypeConfiguration(object obj)
return config;
}
+
+ /// <summary>
+ /// Configures the Cache via dependency injection
+ /// </summary>
+ public void ConfigureCache()
+ {
+ ObjectCacheConfiguration =
+ DependencyResolver.Resolve<AbstractObjectCacheConfiguration>();
+ }
+
+ /// <summary>
+ /// Manually sets the the Cache Configuration
+ /// </summary>
+ /// <param name="objectCacheConfiguration"></param>
+ public void ConfigureCache(AbstractObjectCacheConfiguration objectCacheConfiguration)
+ {
+ ObjectCacheConfiguration = objectCacheConfiguration;
+ }
}
}
View
8 Source/Glass.Mapper/Glass.Mapper.csproj
@@ -49,6 +49,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll</HintPath>
</Reference>
+ <Reference Include="nunit.framework">
+ <HintPath>..\..\Tests\Unit Tests\Glass.Mapper.Tests\bin\Debug - Aaron\nunit.framework.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
@@ -64,11 +67,13 @@
<Compile Include="AbstractService.cs" />
<Compile Include="AbstractTypeSavingContext.cs" />
<Compile Include="Caching\CacheKey.cs" />
+ <Compile Include="Caching\Configuration\AbstractObjectCacheConfiguration.cs" />
+ <Compile Include="Caching\Exceptions\DuplicatedKeyObjectCacheException.cs" />
+ <Compile Include="Caching\Exceptions\ObjectCacheException.cs" />
<Compile Include="Caching\ICacheKey.cs" />
<Compile Include="Caching\ObjectCaching\AbstractCacheKeyResolver.cs" />
<Compile Include="Caching\ObjectCaching\AbstractObjectCache.cs" />
<Compile Include="Caching\ObjectCaching\IAbstractObjectCache.cs" />
- <Compile Include="Configuration\AbstractObjectCacheConfiguration.cs" />
<Compile Include="Configuration\AbstractTypeConfiguration.cs" />
<Compile Include="Configuration\AbstractPropertyConfiguration.cs" />
<Compile Include="Configuration\Attributes\AttributeConfigurationLoader.cs" />
@@ -102,6 +107,7 @@
<Compile Include="Pipelines\ConfigurationResolver\Tasks\OnDemandResolver\OnDemandLoader.cs" />
<Compile Include="Pipelines\ObjectConstruction\ObjectCachingArgs.cs" />
<Compile Include="Pipelines\ObjectConstruction\Tasks\ObjectCachingResolver\ObjectCachingResolverTask.cs" />
+ <Compile Include="Pipelines\ObjectConstruction\Tasks\ObjectCachingSaver\ObjectCachingSaverTask.cs" />
<Compile Include="Profilers\ChainedProfiler.cs" />
<Compile Include="Profilers\IPerformanceProfiler.cs" />
<Compile Include="MapperException.cs" />
View
18 ...ss.Mapper/Pipelines/ObjectConstruction/Tasks/ObjectCachingSaver/ObjectCachingSaverTask.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Glass.Mapper.Pipelines.ObjectConstruction.Tasks.ObjectCachingSaver
+{
+ /// <summary>
+ /// Saves the requested object in the cache
+ /// </summary>
+ public class ObjectCachingSaverTask : IPipelineTask<ObjectCachingArgs>
+ {
+ public void Execute(ObjectCachingArgs args)
+ {
+ args.Context.ObjectCacheConfiguration.ObjectCache.AddObject(args);
+ }
+ }
+}
View
6 Tests/Unit Tests/Glass.Mapper.Tests/Caching/CacheKeyFixture.cs
@@ -23,6 +23,7 @@ public void Setup()
[Test]
public void CanCreateCacheKey()
{
+ //Assert
Assert.AreEqual(_key.Database, Database);
Assert.AreEqual(_key.Id, Id);
Assert.AreEqual(_key.GetId(), Id);
@@ -33,7 +34,10 @@ public void CanCreateCacheKey()
[Test]
public void CanGetCacheKeyString()
{
+ //Assign
var keyStrng = "{0},{1},{2},{3}".Formatted(Id, RevisionId, Database, typeof(int));
+
+ //Assert
Assert.AreEqual(keyStrng, _key.ToString());
}
@@ -50,11 +54,13 @@ public void AreKeysEqual()
[Test]
public void AreKeyNotEqual()
{
+ //Assign
var key = Substitute.For<CacheKey<string>>(
Id.ToString(CultureInfo.InvariantCulture),
RevisionId.ToString(CultureInfo.InvariantCulture),
Database);
+ //Assert
// ReSharper disable SuspiciousTypeConversion.Global
Assert.IsFalse(_key.Equals(key));
// ReSharper restore SuspiciousTypeConversion.Global
View
58 ...Tests/Glass.Mapper.Tests/Caching/Configuration/AbstractObjectCacheConfigurationFixture.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Castle.MicroKernel.Registration;
+using Castle.Windsor;
+using Glass.Mapper.Caching.Configuration;
+using NUnit.Framework;
+
+namespace Glass.Mapper.Tests.Caching.Configuration
+{
+ [TestFixture]
+ public class AbstractObjectCacheConfigurationFixture
+ {
+ private StubIDependencyResolver stubIDependencyResolver;
+
+ [SetUp]
+ public void SetUp()
+ {
+ IWindsorContainer container = new WindsorContainer();
+ container.Register(
+ Component.For<AbstractObjectCacheConfiguration>()
+ .ImplementedBy<StubAbstractObjectCacheConfiguration>()
+ .LifestyleTransient());
+
+ stubIDependencyResolver = new StubIDependencyResolver(container);
+ }
+ }
+
+ public class StubAbstractObjectCacheConfiguration:AbstractObjectCacheConfiguration
+ {
+
+ }
+ public class StubIDependencyResolver:IDependencyResolver
+ {
+ public IWindsorContainer Container { get; private set; }
+
+ public StubIDependencyResolver(IWindsorContainer container)
+ {
+ Container = container;
+ }
+
+ public T Resolve<T>(IDictionary<string, object> args = null)
+ {
+ if (args == null)
+ return Container.Resolve<T>();
+
+
+ return Container.Resolve<T>((IDictionary)args);
+ }
+
+ public IEnumerable<T> ResolveAll<T>()
+ {
+ return Container.ResolveAll<T>();
+ }
+ }
+}
View
69 Tests/Unit Tests/Glass.Mapper.Tests/Caching/Configuration/ContextFixture.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Castle.MicroKernel.Registration;
+using Castle.Windsor;
+using Glass.Mapper.Caching.Configuration;
+using Glass.Mapper.Caching.ObjectCaching;
+using NSubstitute;
+using NUnit.Framework;
+
+namespace Glass.Mapper.Tests.Caching.Configuration
+{
+ [TestFixture]
+ public class ContextFixture
+ {
+ [Test]
+ public void CanConfigureCache()
+ {
+ //create the resolver
+ var resolver = new ContextFixtureIDependencyResolver();
+
+ //create a context
+ var context = Context.Create(resolver);
+ context.ConfigureCache();
+
+ Assert.IsNotNull(context.ObjectCacheConfiguration);
+ }
+ }
+
+ public class ContextFixtureIDependencyResolver : IDependencyResolver
+ {
+ private IWindsorContainer container;
+
+ public ContextFixtureIDependencyResolver()
+ {
+ container = new WindsorContainer();
+ container.Register(
+ Component.For<IAbstractObjectCache>().ImplementedBy<IAbstractObjectCache>().LifestyleTransient(),
+ Component.For<AbstractObjectCacheConfiguration>().ImplementedBy<AbstractObjectCacheConfiguration>().LifestyleTransient());
+ }
+
+ /// <summary>
+ /// Resolves the specified args.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="args">The args.</param>
+ /// <returns>``0.</returns>
+ public T Resolve<T>(IDictionary<string, object> args = null)
+ {
+ if (args == null)
+ return container.Resolve<T>();
+
+
+ return container.Resolve<T>((IDictionary)args);
+ }
+
+ /// <summary>
+ /// Resolves all.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns>IEnumerable{``0}.</returns>
+ public IEnumerable<T> ResolveAll<T>()
+ {
+ return container.ResolveAll<T>();
+ }
+ }
+}
View
76 Tests/Unit Tests/Glass.Mapper.Tests/Caching/ObjectCaching/AbstractObjectCacheFixture.cs
@@ -1,8 +1,10 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Glass.Mapper.Caching;
+using Glass.Mapper.Caching.Exceptions;
using Glass.Mapper.Caching.ObjectCaching;
using Glass.Mapper.Pipelines.ObjectConstruction;
using NSubstitute;
@@ -18,6 +20,7 @@ public class AbstractObjectCacheFixture
private const int Id = 42;
private const int RevisionId = 6;
private const string Database = "SomeDatabase";
+ private StubClass _stubObject;
private CacheKey<int> _key;
@@ -25,16 +28,85 @@ public class AbstractObjectCacheFixture
public void SetUp()
{
_args = Substitute.For<ObjectCachingArgs>();
+ _stubObject = new StubClass();
+ _args.Result = _stubObject;
+
_cacheKeyResolver = Substitute.For<AbstractCacheKeyResolver<int>>();
_key = Substitute.For<CacheKey<int>>(42, RevisionId, Database);
+
+ _args.CacheKey = _key;
_cacheKeyResolver.GetKey(_args).Returns(_key);
}
[Test]
public void AbstractObjectCacheContainObject()
{
- var abstractObjectCache = Substitute.For<AbstractObjectCache<int>>(_cacheKeyResolver);
- //abstractObjectCache.ContansObject(_args).Returns();
+ //Assign
+ var abstractObjectCache = new StubAbstractObjectCache(_cacheKeyResolver);
+
+ //Act
+ abstractObjectCache.AddObject(_args);
+
+ //Assert
Assert.IsTrue(abstractObjectCache.ContansObject(_args));
}
+
+ [Test]
+ public void AbstractObjectCacheAddObject()
+ {
+ //Assign
+ var args = Substitute.For<ObjectCachingArgs>();
+ var abstractObjectCache = new StubAbstractObjectCache(_cacheKeyResolver);
+ abstractObjectCache.AddObject(_args);
+ _cacheKeyResolver.GetKey(args).Returns(_key);
+ args.CacheKey = _key;
+
+ //Act
+ abstractObjectCache.GetObject(args).Returns(_key);
+
+ //Assert
+ Assert.AreSame(_stubObject, abstractObjectCache.GetObject(args));
+ }
+
+ [Test]
+ [ExpectedException(typeof(DuplicatedKeyObjectCacheException))]
+ public void ExpectWhenTryToAddObjectAgain()
+ {
+ //Assign
+ var abstractObjectCache = new StubAbstractObjectCache(_cacheKeyResolver);
+
+ //Act
+ abstractObjectCache.AddObject(_args);
+ abstractObjectCache.AddObject(_args);
+ }
+
+ }
+
+ public class StubAbstractObjectCache : AbstractObjectCache<int>
+ {
+ private volatile Hashtable _table = new Hashtable();
+
+ public StubAbstractObjectCache(AbstractCacheKeyResolver<int> cacheKeyResolver)
+ : base(cacheKeyResolver)
+ {
+ }
+ protected override bool InternalContansObject(string objectKey)
+ {
+ return _table.ContainsKey(objectKey);
+ }
+
+ protected override void InternalAddObject(string objectKey, object objectForCaching)
+ {
+ _table.Add(objectKey, objectForCaching);
+ }
+
+ protected override object InternalGetObject(string objectKey)
+ {
+ return _table[objectKey];
+ }
+ }
+
+ public class StubClass
+ {
+
}
}
View
4 Tests/Unit Tests/Glass.Mapper.Tests/Caching/ObjectCachingArgsFixture.cs
@@ -39,13 +39,17 @@ public void SetUp()
[Test]
public void ObjectCachingArgsIsInstanceOfObjectConstructionArgs()
{
+ //Assert
Assert.IsInstanceOf<ObjectConstructionArgs>(new ObjectCachingArgs(_context, _abstractTypeCreationContext, _configuration, _service));
}
[Test]
public void CanSetCacheKeyFromCrounstrocter()
{
+ //Assign
var cacheKey = Substitute.For<CacheKey<int>>();
+ //Act
var args = new ObjectCachingArgs(_context, _abstractTypeCreationContext, _configuration, _service, cacheKey);
+ //Assert
Assert.AreSame(args.CacheKey, cacheKey);
}
}
View
6 Tests/Unit Tests/Glass.Mapper.Tests/Glass.Mapper.Tests.csproj
@@ -45,6 +45,9 @@
<Reference Include="Castle.Core">
<HintPath>..\..\..\packages\Castle.Core.3.2.0\lib\net40-client\Castle.Core.dll</HintPath>
</Reference>
+ <Reference Include="Castle.Windsor">
+ <HintPath>..\..\..\Source\Glass.Mapper.Sc.CastleWindsor\bin\Debug - Aaron\Castle.Windsor.dll</HintPath>
+ </Reference>
<Reference Include="NSubstitute, Version=1.5.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\NSubstitute.1.5.0.0\lib\NET40\NSubstitute.dll</HintPath>
@@ -64,6 +67,8 @@
<ItemGroup>
<Compile Include="AbstractServiceFixture.cs" />
<Compile Include="Caching\CacheKeyFixture.cs" />
+ <Compile Include="Caching\Configuration\AbstractObjectCacheConfigurationFixture.cs" />
+ <Compile Include="Caching\Configuration\ContextFixture.cs" />
<Compile Include="Caching\ObjectCachingArgsFixture.cs" />
<Compile Include="Caching\ObjectCaching\AbstractObjectCacheFixture.cs" />
<Compile Include="Configuration\AbstractTypeConfigurationFixture.cs" />
@@ -85,6 +90,7 @@
<Compile Include="Pipelines\ObjectConstruction\Tasks\CreateConcrete\LazyObjectInterceptorFixture.cs" />
<Compile Include="Pipelines\ObjectConstruction\Tasks\CreateInterface\CreateInterfaceTaskFixture.cs" />
<Compile Include="Pipelines\ObjectConstruction\Tasks\ObjectCachingResolver\ObjectCachingResolverTaskFixture.cs" />
+ <Compile Include="Pipelines\ObjectConstruction\Tasks\ObjectCachingSaver\ObjectCachingSaverTaskFixture.cs" />
<Compile Include="Pipelines\ObjectSaving\Tasks\StandardSavingTaskFixture.cs" />
<Compile Include="UtilitiesFixture.cs" />
<Compile Include="Pipelines\AbstractPipelineRunnerFixture.cs" />
View
5 ...elines/ObjectConstruction/Tasks/ObjectCachingResolver/ObjectCachingResolverTaskFixture.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using Glass.Mapper.Caching.Configuration;
using Glass.Mapper.Caching.ObjectCaching;
using Glass.Mapper.Configuration;
using Glass.Mapper.Pipelines;
@@ -40,13 +41,11 @@ public void Setup()
_configuration = Substitute.For<AbstractTypeConfiguration>();
_configuration.Type = _type;
-
-
}
#region Method - Execute
[Test]
- public void CanTastExecute()
+ public void CanTaskExecute()
{
var args = new ObjectCachingArgs(_context, _abstractTypeCreationContext, _configuration, _service);
_task.Execute(args);
View
91 ...ts/Pipelines/ObjectConstruction/Tasks/ObjectCachingSaver/ObjectCachingSaverTaskFixture.cs
@@ -0,0 +1,91 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Glass.Mapper.Caching.Configuration;
+using Glass.Mapper.Caching.ObjectCaching;
+using Glass.Mapper.Configuration;
+using Glass.Mapper.Pipelines;
+using Glass.Mapper.Pipelines.ObjectConstruction;
+using Glass.Mapper.Pipelines.ObjectConstruction.Tasks.ObjectCachingResolver;
+using Glass.Mapper.Pipelines.ObjectConstruction.Tasks.ObjectCachingSaver;
+using NSubstitute;
+using NUnit.Framework;
+
+namespace Glass.Mapper.Tests.Pipelines.ObjectConstruction.Tasks.ObjectCachingSaver
+{
+ [TestFixture]
+ public class ObjectCachingSaverTaskFixture
+ {
+ private IPipelineTask<ObjectCachingArgs> _task;
+ private Context _context;
+ private AbstractTypeCreationContext _abstractTypeCreationContext;
+ private Type _type;
+ private IAbstractService _service;
+ private AbstractTypeConfiguration _configuration;
+
+ [SetUp]
+ public void Setup()
+ {
+ _task = new ObjectCachingSaverTask();
+
+ //Assign
+ _type = typeof(ObjectCachingResolver.StubClass);
+ _service = Substitute.For<IAbstractService>();
+
+ _context = Context.Create(Substitute.For<IDependencyResolver>());
+ _context.ObjectCacheConfiguration = Substitute.For<AbstractObjectCacheConfiguration>();
+ _context.ObjectCacheConfiguration.ObjectCache = Substitute.For<IAbstractObjectCache>();
+
+ _abstractTypeCreationContext = Substitute.For<AbstractTypeCreationContext>();
+ _abstractTypeCreationContext.RequestedType = _type;
+
+ _configuration = Substitute.For<AbstractTypeConfiguration>();
+ _configuration.Type = _type;
+ }
+
+ [Test]
+ public void CanTaskExecute()
+ {
+ var args = new ObjectCachingArgs(_context, _abstractTypeCreationContext, _configuration, _service);
+ _task.Execute(args);
+ }
+
+ [Test]
+ public void CanTastExecuteAndDoesNotAbortTask()
+ {
+ var args = new ObjectCachingArgs(_context, _abstractTypeCreationContext, _configuration, _service);
+
+ _context.ObjectCacheConfiguration.ObjectCache.ContansObject(args).Returns(true);
+ _task.Execute(args);
+
+ Assert.IsFalse(args.IsAborted);
+ }
+
+ [Test]
+ public void CanTastExecuteAndAddObjectToCache()
+ {
+ var stubClass = new StubClass();
+
+ var args = new ObjectCachingArgs(_context, _abstractTypeCreationContext, _configuration, _service);
+ args.Result = stubClass;
+ _task.Execute(args);
+
+ _context.ObjectCacheConfiguration.ObjectCache.Received().AddObject(args);
+ }
+ }
+
+ #region Stubs
+
+ public class StubClass
+ {
+
+ }
+
+ public interface IStubInterface
+ {
+
+ }
+
+ #endregion
+}
Please sign in to comment.
Something went wrong with that request. Please try again.