Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Csajtai committed Mar 24, 2017
2 parents c753930 + 4c6eeca commit 443195c
Show file tree
Hide file tree
Showing 59 changed files with 1,338 additions and 508 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
artifact: /.*\.nupkg/

environment:
build_version: 2.3.1
build_version: 2.3.2
COVERALLS_REPO_TOKEN:
secure: Q9gcbZnzJ5a0YYF6mkr4QoQylIzeQmVytMnIe4WL7aPtb30SdNes7brLkvnXOirt

Expand Down Expand Up @@ -79,7 +79,7 @@
secure: 2bITagXOj2s3bTJaGXh8/iyWtST8OQOFaMM+0GAKgZts9OjCVCiV7C+E/0SYsM6M

environment:
build_version: 2.3.1
build_version: 2.3.2
COVERALLS_REPO_TOKEN:
secure: Q9gcbZnzJ5a0YYF6mkr4QoQylIzeQmVytMnIe4WL7aPtb30SdNes7brLkvnXOirt

Expand Down
29 changes: 1 addition & 28 deletions src/stashbox.tests/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,7 @@ public void AttributeTests_Resolve()
Assert.IsInstanceOfType(test3.test1, typeof(Test11));
Assert.IsInstanceOfType(test3.test2, typeof(Test22));
}

[TestMethod]
public void AttributeTests_Resolve_Activator()
{
var container = new StashboxContainer();
container.RegisterType<ITest1, Test1>("test1");
container.RegisterType<ITest1, Test11>("test11");
container.RegisterType<ITest1, Test12>("test12");

var inst = container.ActivationContext.Activate(ResolutionInfo.New(), typeof(ITest1), "test12");
Assert.IsNotNull(inst);
Assert.IsInstanceOfType(inst, typeof(Test12));
}

[TestMethod]
public void AttributeTests_Resolve_Activator_Resolver()
{
var container = new StashboxContainer();
container.RegisterType<ITest1, Test1>("test1");
container.RegisterType<ITest1, Test11>("test11");
container.RegisterType<ITest1, Test12>("test12");

var inst = container.ActivationContext.Activate(ResolutionInfo.New(), typeof(IEnumerable<ITest1>));
Assert.IsNotNull(inst);
Assert.IsInstanceOfType(inst, typeof(IEnumerable<ITest1>));
Assert.AreEqual(3, ((IEnumerable<ITest1>)inst).Count());
}


[TestMethod]
public void AttributeTests_Named_Resolution()
{
Expand Down
2 changes: 1 addition & 1 deletion src/stashbox.tests/BuildExtensionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void BuildExtensionManagerTests_CreateCopy()

post.Setup(p => p.CreateCopy()).Returns(post2.Object).Verifiable();

using (var child = container.BeginScope())
using (var child = container.CreateChildContainer())
{
child.RegisterInstance(new object());

Expand Down
17 changes: 13 additions & 4 deletions src/stashbox.tests/ContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Linq.Expressions;
using Stashbox.Infrastructure.Resolution;
using System.Linq;
using Stashbox.Lifetime;

namespace Stashbox.Tests
{
Expand All @@ -21,7 +20,7 @@ public void ContainerTests_ChildContainer()
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest2, Test2>();

var child = container.BeginScope();
var child = container.CreateChildContainer();
child.RegisterType<ITest3, Test3>();

var test3 = child.Resolve<ITest3>();
Expand All @@ -37,7 +36,7 @@ public void ContainerTests_ChildContainer_ResolveFromParent()
var container = new StashboxContainer();
container.RegisterType<ITest1, Test1>();

var child = container.BeginScope();
var child = container.CreateChildContainer();

var test1 = child.Resolve<ITest1>();

Expand Down Expand Up @@ -68,6 +67,17 @@ public void ContainerTests_Validate_CircularDependency()
}
}

[TestMethod]
public void ContainerTests_Validate_Ok()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest2, Test2>();
container.Validate();
}
}

[TestMethod]
public void ContainerTests_CheckRegistration()
{
Expand All @@ -82,7 +92,6 @@ public void ContainerTests_CheckRegistration()
reg = container.ContainerContext.RegistrationRepository.GetAllRegistrations().FirstOrDefault(r => r.ImplementationType == typeof(Test1));

Assert.IsNotNull(reg);
Assert.IsInstanceOfType(reg.LifetimeManager, typeof(TransientLifetime));
}
}

Expand Down
52 changes: 52 additions & 0 deletions src/stashbox.tests/DecoratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,40 @@ public void DecoratorTests_OpenGeneric()
}
}

[TestMethod]
public void DecoratorTests_DecoratorDependency_Null()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterDecorator<ITest1, TestDecorator9>();

var inst = container.Resolve<ITest1>(nullResultAllowed: true);

Assert.IsNull(inst);
}
}

[TestMethod]
public void DecoratorTests_DecoreteeDependency_Null()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test12>();
container.RegisterDecorator<ITest1, TestDecorator9>();

var inst = container.Resolve<ITest1>(nullResultAllowed: true);

Assert.IsNull(inst);
}
}

public interface ITest1 { ITest1 Test { get; } }

public interface IDecoratorDep { }

public interface IDep { }

public interface ITest1<T> { ITest1<T> Test { get; } }

public class Test1 : ITest1
Expand All @@ -347,6 +379,16 @@ public class Test11 : ITest1
public ITest1 Test { get; }
}

public class Test12 : ITest1
{
public ITest1 Test { get; }

public Test12(IDep dep)
{

}
}

public class Test1<T> : ITest1<T>
{
public ITest1<T> Test { get; }
Expand Down Expand Up @@ -437,5 +479,15 @@ public TestDecorator8(IEnumerable<ITest1> test1)
this.Test = test1.First();
}
}

public class TestDecorator9 : ITest1
{
public ITest1 Test { get; }

public TestDecorator9(ITest1 test1, IDecoratorDep dep)
{
this.Test = test1;
}
}
}
}
102 changes: 96 additions & 6 deletions src/stashbox.tests/DisposeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,51 @@ public void DisposeTests_TrackTransientDisposal_Scoped_Transient()
Assert.IsTrue(test3.Test1.Disposed);
}

[TestMethod]
public void DisposeTests_TrackTransientDisposal_ScopeOfScope_Transient()
{
using (IStashboxContainer container = new StashboxContainer(config => config.WithDisposableTransientTracking()))
{
container.RegisterType<ITest2, Test2>();
container.RegisterType<Test3>();
container.RegisterType<ITest1, Test1>();

ITest1 test;
ITest2 test2;
Test3 test3;

using (var scope = container.BeginScope())
{
test = scope.Resolve<ITest1>();
test2 = scope.Resolve<ITest2>();
test3 = scope.Resolve<Test3>();

ITest1 test4;
ITest2 test5;
Test3 test6;

using (var scope2 = scope.BeginScope())
{
test4 = scope2.Resolve<ITest1>();
test5 = scope2.Resolve<ITest2>();
test6 = scope2.Resolve<Test3>();
}

Assert.IsTrue(test4.Disposed);
Assert.IsTrue(test5.Test1.Disposed);
Assert.IsTrue(test6.Test1.Disposed);

Assert.IsFalse(test.Disposed);
Assert.IsFalse(test2.Test1.Disposed);
Assert.IsFalse(test3.Test1.Disposed);
}

Assert.IsTrue(test.Disposed);
Assert.IsTrue(test2.Test1.Disposed);
Assert.IsTrue(test3.Test1.Disposed);
}
}

[TestMethod]
public void DisposeTests_TrackTransientDisposal_Scoped_Transient_ChildContainer()
{
Expand All @@ -176,11 +221,12 @@ public void DisposeTests_TrackTransientDisposal_Scoped_Transient_ChildContainer(
container.RegisterType<Test3>();
container.RegisterType<ITest1, Test1>();

using (var child = container.BeginScope())
using (var child = container.CreateChildContainer())
using (var scope = child.BeginScope())
{
test4 = child.Resolve<ITest1>();
test5 = child.Resolve<ITest2>();
test6 = child.Resolve<Test3>();
test4 = scope.Resolve<ITest1>();
test5 = scope.Resolve<ITest2>();
test6 = scope.Resolve<Test3>();
}

Assert.IsTrue(test4.Disposed);
Expand Down Expand Up @@ -224,12 +270,32 @@ public void DisposeTests_TrackTransientDisposal_Scoped_Transient_Singleton()
Assert.IsTrue(test6.Test1.Disposed);
}

[TestMethod]
public void DisposeTests_TrackTransientDisposal_Implementation_Has_Disposable()
{
IStashboxContainer container = new StashboxContainer(config => config.WithDisposableTransientTracking());
ITest11 test1;

container.RegisterType<ITest11, Test4>();

using (var child = container.BeginScope())
{
test1 = (ITest11)child.Resolve(typeof(ITest11));
}

Assert.IsTrue(((Test4)test1).Disposed);
}

[TestMethod]
public void DisposeTests_Instance_TrackTransient()
{
ITest1 test = new Test1();
using (var container = new StashboxContainer(config => config.WithDisposableTransientTracking()))
container.RegisterInstance(test);
{
container.RegisterInstance<ITest1>(test);

Assert.AreSame(test, container.Resolve<ITest1>());
}

Assert.IsTrue(test.Disposed);
}
Expand All @@ -239,7 +305,11 @@ public void DisposeTests_WireUp_TrackTransient()
{
ITest1 test = new Test1();
using (var container = new StashboxContainer(config => config.WithDisposableTransientTracking()))
container.WireUp(test);
{
container.WireUp<ITest1>(test);

Assert.AreSame(test, container.Resolve<ITest1>());
}

Assert.IsTrue(test.Disposed);
}
Expand All @@ -258,6 +328,11 @@ public class Test1 : ITest1

public void Dispose()
{
if (Disposed)
{
throw new ObjectDisposedException(nameof(Test1));
}

this.Disposed = true;
}
}
Expand All @@ -277,5 +352,20 @@ public class Test3
[Dependency]
public ITest1 Test1 { get; set; }
}

public class Test4 : ITest11, IDisposable
{
public bool Disposed { get; private set; }

public void Dispose()
{
if (Disposed)
{
throw new ObjectDisposedException(nameof(Test4));
}

this.Disposed = true;
}
}
}
}
Loading

0 comments on commit 443195c

Please sign in to comment.