Rework tests from 1-to-1 mapping into specifications (#46)

This commit is contained in:
Alexey Golub
2020-03-16 01:03:03 +02:00
committed by GitHub
parent 79e1a2e3d7
commit 57f168723b
80 changed files with 3235 additions and 2718 deletions

View File

@@ -0,0 +1,58 @@
using CliFx.Exceptions;
using FluentAssertions;
using Xunit;
namespace CliFx.Tests
{
public partial class DependencyInjectionSpecs
{
[Fact]
public void Default_type_activator_can_initialize_a_command_if_it_has_a_parameterless_constructor()
{
// Arrange
var activator = new DefaultTypeActivator();
// Act
var obj = activator.CreateInstance(typeof(WithoutDependenciesCommand));
// Assert
obj.Should().BeOfType<WithoutDependenciesCommand>();
}
[Fact]
public void Default_type_activator_cannot_initialize_a_command_if_it_does_not_have_a_parameterless_constructor()
{
// Arrange
var activator = new DefaultTypeActivator();
// Act & assert
Assert.Throws<CliFxException>(() =>
activator.CreateInstance(typeof(WithDependenciesCommand)));
}
[Fact]
public void Delegate_type_activator_can_initialize_a_command_using_a_custom_function()
{
// Arrange
var activator = new DelegateTypeActivator(_ =>
new WithDependenciesCommand(new DependencyA(), new DependencyB()));
// Act
var obj = activator.CreateInstance(typeof(WithDependenciesCommand));
// Assert
obj.Should().BeOfType<WithDependenciesCommand>();
}
[Fact]
public void Delegate_type_activator_throws_if_the_underlying_function_returns_null()
{
// Arrange
var activator = new DelegateTypeActivator(_ => null);
// Act & assert
Assert.Throws<CliFxException>(() =>
activator.CreateInstance(typeof(WithDependenciesCommand)));
}
}
}