Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed Mar 18, 2017
2 parents f5a505a + 287360e commit c753930
Show file tree
Hide file tree
Showing 15 changed files with 275 additions and 95 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.0
build_version: 2.3.1
COVERALLS_REPO_TOKEN:
secure: Q9gcbZnzJ5a0YYF6mkr4QoQylIzeQmVytMnIe4WL7aPtb30SdNes7brLkvnXOirt

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

environment:
build_version: 2.3.0
build_version: 2.3.1
COVERALLS_REPO_TOKEN:
secure: Q9gcbZnzJ5a0YYF6mkr4QoQylIzeQmVytMnIe4WL7aPtb30SdNes7brLkvnXOirt

Expand Down
31 changes: 1 addition & 30 deletions src/stashbox.tests/ContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ContainerTests
[TestMethod]
public void ContainerTests_ChildContainer()
{
var container = new StashboxContainer(config => config.WithParentContainerResolution());
var container = new StashboxContainer();
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest2, Test2>();

Expand All @@ -33,47 +33,18 @@ public void ContainerTests_ChildContainer()

[TestMethod]
public void ContainerTests_ChildContainer_ResolveFromParent()
{
var container = new StashboxContainer(config => config.WithParentContainerResolution());
container.RegisterType<ITest1, Test1>();

var child = container.BeginScope();

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

Assert.IsNotNull(test1);
Assert.IsInstanceOfType(test1, typeof(Test1));
}

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

var child = container.BeginScope();

container.Configure(config => config.WithParentContainerResolution());
var test1 = child.Resolve<ITest1>();

Assert.IsNotNull(test1);
Assert.IsInstanceOfType(test1, typeof(Test1));
}

[TestMethod]
[ExpectedException(typeof(ResolutionFailedException))]
public void ContainerTests_ChildContainer_WithoutResolveFromParent()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();

var child = container.BeginScope();

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

[TestMethod]
[ExpectedException(typeof(ResolutionFailedException))]
public void ContainerTests_Validate_MissingDependency()
Expand Down
188 changes: 187 additions & 1 deletion src/stashbox.tests/DecoratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Stashbox.Attributes;
using Stashbox.Configuration;
using Stashbox.Entity;
Expand Down Expand Up @@ -59,6 +62,120 @@ public void DecoratorTests_Simple3()
}
}

[TestMethod]
public void DecoratorTests_Simple_Lazy()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterDecorator<ITest1, TestDecorator1>();
var test = container.Resolve<Lazy<ITest1>>();

Assert.IsNotNull(test.Value);
Assert.IsInstanceOfType(test.Value, typeof(TestDecorator1));

Assert.IsNotNull(test.Value.Test);
Assert.IsInstanceOfType(test.Value.Test, typeof(Test1));
}
}

[TestMethod]
public void DecoratorTests_Simple_Func()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterDecorator<ITest1, TestDecorator1>();
var test = container.Resolve<Func<ITest1>>();

Assert.IsNotNull(test());
Assert.IsInstanceOfType(test(), typeof(TestDecorator1));

Assert.IsNotNull(test().Test);
Assert.IsInstanceOfType(test().Test, typeof(Test1));
}
}

[TestMethod]
public void DecoratorTests_Simple_Enumerable()
{
using (var container = new StashboxContainer(config => config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder)))
{
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
container.RegisterDecorator<ITest1, TestDecorator1>();
var test = container.Resolve<IEnumerable<ITest1>>();

Assert.IsNotNull(test);
Assert.IsInstanceOfType(test, typeof(IEnumerable<ITest1>));

var arr = test.ToArray();

Assert.IsNotNull(arr[0]);
Assert.IsInstanceOfType(arr[0], typeof(TestDecorator1));

Assert.IsNotNull(arr[1]);
Assert.IsInstanceOfType(arr[1], typeof(TestDecorator1));

Assert.IsNotNull(arr[0].Test);
Assert.IsInstanceOfType(arr[0].Test, typeof(Test1));

Assert.IsNotNull(arr[1].Test);
Assert.IsInstanceOfType(arr[1].Test, typeof(Test11));
}
}

[TestMethod]
public void DecoratorTests_Decorator_Holds_Lazy()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterDecorator<ITest1, TestDecorator6>();
var test = container.Resolve<ITest1>();

Assert.IsNotNull(test);
Assert.IsInstanceOfType(test, typeof(TestDecorator6));

Assert.IsNotNull(test.Test);
Assert.IsInstanceOfType(test.Test, typeof(Test1));
}
}

[TestMethod]
public void DecoratorTests_Decorator_Holds_Func()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterDecorator<ITest1, TestDecorator7>();
var test = container.Resolve<ITest1>();

Assert.IsNotNull(test);
Assert.IsInstanceOfType(test, typeof(TestDecorator7));

Assert.IsNotNull(test.Test);
Assert.IsInstanceOfType(test.Test, typeof(Test1));
}
}

[TestMethod]
public void DecoratorTests_Decorator_Holds_Enumerable()
{
using (var container = new StashboxContainer())
{
container.RegisterType<ITest1, Test1>();
container.RegisterDecorator<ITest1, TestDecorator8>();
var test = container.Resolve<ITest1>();

Assert.IsNotNull(test);
Assert.IsInstanceOfType(test, typeof(TestDecorator8));

Assert.IsNotNull(test.Test);
Assert.IsInstanceOfType(test.Test, typeof(Test1));
}
}

[TestMethod]
public void DecoratorTests_Dependency()
{
Expand Down Expand Up @@ -199,13 +316,52 @@ public void DecoratorTests_Multiple_Scoped()
}
}

[TestMethod]
public void DecoratorTests_OpenGeneric()
{
using (var container = new StashboxContainer())
{
container.RegisterType(typeof(ITest1<>), typeof(Test1<>));
container.RegisterDecorator(typeof(ITest1<>), typeof(TestDecorator1<>));
var test = container.Resolve<ITest1<int>>();

Assert.IsNotNull(test);
Assert.IsInstanceOfType(test, typeof(TestDecorator1<int>));

Assert.IsNotNull(test.Test);
Assert.IsInstanceOfType(test.Test, typeof(Test1<int>));
}
}

public interface ITest1 { ITest1 Test { get; } }

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

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

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

public class Test1<T> : ITest1<T>
{
public ITest1<T> Test { get; }
}

public class TestDecorator1<T> : ITest1<T>
{
public ITest1<T> Test { get; }

public TestDecorator1(ITest1<T> test1)
{
this.Test = test1;
}
}

public class TestDecorator1 : ITest1
{
public ITest1 Test { get; }
Expand Down Expand Up @@ -251,5 +407,35 @@ public TestDecorator5(ITest1 test1)
this.Test = test1;
}
}

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

public TestDecorator6(Lazy<ITest1> test1)
{
this.Test = test1.Value;
}
}

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

public TestDecorator7(Func<ITest1> test1)
{
this.Test = test1();
}
}

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

public TestDecorator8(IEnumerable<ITest1> test1)
{
this.Test = test1.First();
}
}
}
}
6 changes: 3 additions & 3 deletions src/stashbox.tests/DisposeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void DisposeTests_TrackTransientDisposal_Scoped_Transient()
ITest1 test;
ITest2 test2;
Test3 test3;
using (IStashboxContainer container = new StashboxContainer(config => config.WithDisposableTransientTracking().WithParentContainerResolution()))
using (IStashboxContainer container = new StashboxContainer(config => config.WithDisposableTransientTracking()))
{
ITest1 test4;
ITest2 test5;
Expand Down Expand Up @@ -167,7 +167,7 @@ public void DisposeTests_TrackTransientDisposal_Scoped_Transient()
[TestMethod]
public void DisposeTests_TrackTransientDisposal_Scoped_Transient_ChildContainer()
{
IStashboxContainer container = new StashboxContainer(config => config.WithDisposableTransientTracking().WithParentContainerResolution());
IStashboxContainer container = new StashboxContainer(config => config.WithDisposableTransientTracking());
ITest1 test4;
ITest2 test5;
Test3 test6;
Expand All @@ -191,7 +191,7 @@ public void DisposeTests_TrackTransientDisposal_Scoped_Transient_ChildContainer(
[TestMethod]
public void DisposeTests_TrackTransientDisposal_Scoped_Transient_Singleton()
{
var container = new StashboxContainer(config => config.WithDisposableTransientTracking().WithParentContainerResolution());
var container = new StashboxContainer(config => config.WithDisposableTransientTracking());


container.RegisterType<ITest2, Test2>();
Expand Down
15 changes: 6 additions & 9 deletions src/stashbox.tests/EnumerableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void EnumerableTests_Resolve()
[TestMethod]
public void EnumerableTests_Resolve_Parent()
{
IStashboxContainer container = new StashboxContainer(config => config.WithParentContainerResolution());
IStashboxContainer container = new StashboxContainer();
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
container.RegisterType<ITest1, Test12>();
Expand All @@ -115,7 +115,7 @@ public void EnumerableTests_Resolve_Parent()
[TestMethod]
public void EnumerableTests_Resolve_Parent_Lazy()
{
IStashboxContainer container = new StashboxContainer(config => config.WithParentContainerResolution());
IStashboxContainer container = new StashboxContainer();
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
container.RegisterType<ITest1, Test12>();
Expand All @@ -130,7 +130,7 @@ public void EnumerableTests_Resolve_Parent_Lazy()
[TestMethod]
public void EnumerableTests_Resolve_Parent_Func()
{
IStashboxContainer container = new StashboxContainer(config => config.WithParentContainerResolution());
IStashboxContainer container = new StashboxContainer();
container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
container.RegisterType<ITest1, Test12>();
Expand Down Expand Up @@ -267,8 +267,7 @@ public void EnumerableTests_ResolveAll_PreserveOrder()
public void EnumerableTests_Resolve_PreserveOrder_Parent()
{
IStashboxContainer container = new StashboxContainer(config =>
config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder)
.WithParentContainerResolution());
config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder));

container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
Expand All @@ -287,8 +286,7 @@ public void EnumerableTests_Resolve_PreserveOrder_Parent()
public void EnumerableTests_Resolve_PreserveOrder_Parent_Lazy()
{
IStashboxContainer container = new StashboxContainer(config =>
config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder)
.WithParentContainerResolution());
config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder));

container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
Expand All @@ -307,8 +305,7 @@ public void EnumerableTests_Resolve_PreserveOrder_Parent_Lazy()
public void EnumerableTests_Resolve_PreserveOrder_Parent_Func()
{
IStashboxContainer container = new StashboxContainer(config =>
config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder)
.WithParentContainerResolution());
config.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder));

container.RegisterType<ITest1, Test1>();
container.RegisterType<ITest1, Test11>();
Expand Down
Loading

0 comments on commit c753930

Please sign in to comment.