-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for nested app using IoC
- Loading branch information
Bilal Fazlani
committed
Jan 9, 2018
1 parent
1f65512
commit 5da6d42
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Autofac; | ||
using CommandDotNet.Attributes; | ||
using CommandDotNet.IoC.Autofac; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CommandDotNet.Tests | ||
{ | ||
public class IoCTests | ||
{ | ||
[Fact] | ||
public void CanResolveDependencyInNestedCommand() | ||
{ | ||
ContainerBuilder containerBuilder = new ContainerBuilder(); | ||
containerBuilder.RegisterType<Service>().As<IService>(); | ||
IContainer container = containerBuilder.Build(); | ||
|
||
AppRunner<NestedCommandApp> appRunner = new AppRunner<NestedCommandApp>().UseAutofac(container); | ||
|
||
appRunner.Run("InnerApp", "-a", "3", "Process").Should().Be(7); | ||
} | ||
} | ||
|
||
public class NestedCommandApp | ||
{ | ||
public class InnerApp | ||
{ | ||
private readonly int _additionFactor; | ||
public IService Service { get; set; } | ||
|
||
public InnerApp([Option(ShortName = "a")]int additionFactor) | ||
{ | ||
_additionFactor = additionFactor; | ||
} | ||
|
||
public int Process() | ||
{ | ||
return Service.GetValue() + _additionFactor; | ||
} | ||
} | ||
} | ||
|
||
public interface IService | ||
{ | ||
int GetValue(); | ||
} | ||
|
||
public class Service : IService | ||
{ | ||
public int GetValue() | ||
{ | ||
return 4; | ||
} | ||
} | ||
} |