-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: change namespace of domain unit tests * chore: removed moq and unneeded resource lines * chore: remove unnecessary resource lines
- Loading branch information
1 parent
7ff023d
commit 0df2cc4
Showing
64 changed files
with
1,455 additions
and
1,996 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
163 changes: 163 additions & 0 deletions
163
Application.Tests/Unit/Interactors/CreateFeatureFlag/InteractorTests.cs
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,163 @@ | ||
using Domain.FeatureFlags; | ||
using Application.Interactors.CreateFeatureFlag; | ||
using Domain.Common; | ||
using NSubstitute; | ||
|
||
namespace Application.Tests.Unit.Interactors.CreateFeatureFlag; | ||
|
||
[Category("Unit")] | ||
public sealed class InteractorTests | ||
{ | ||
[Test] | ||
public void CreateFeatureFlagInteractor_Is_An_InputPort() | ||
{ | ||
var repository = Substitute.For<IRepository>(); | ||
var factory = Substitute.For<IFactory>(); | ||
|
||
var interactor = new Interactor(repository, factory); | ||
|
||
Assert.That(interactor, Is.InstanceOf<IInputPort>()); | ||
} | ||
|
||
[Test] | ||
public async Task CreateFeatureFlagInteractor_Creates_A_Feature_Flag() | ||
{ | ||
var model = Substitute.For<IModel>(); | ||
model.Id.Returns("new_flag"); | ||
model.Enabled.Returns(true); | ||
model.Validate().Returns(Result<bool, IEnumerable<ValidationError>>.Ok(true)); | ||
|
||
var repository = Substitute.For<IRepository>(); | ||
repository.Create(model).Returns(m => m.Arg<IModel>().Id); | ||
|
||
var factory = Substitute.For<IFactory>(); | ||
factory.Create("new_flag", true).Returns(model); | ||
|
||
var interactor = new Interactor(repository, factory); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "new_flag", | ||
Enabled = true | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().Ok(); | ||
} | ||
|
||
[Test] | ||
public async Task CreateFeatureFlagInteractor_Should_Return_Any_Validation_Errors() | ||
{ | ||
var repository = Substitute.For<IRepository>(); | ||
|
||
var validationErrors = new ValidationError[] | ||
{ | ||
new() | ||
{ | ||
Field = "Id", | ||
Message = "Some error" | ||
}, | ||
new() | ||
{ | ||
Field = "Id", | ||
Message = "Some other error" | ||
} | ||
}; | ||
|
||
var model = Substitute.For<IModel>(); | ||
model.Id.Returns("new_flag"); | ||
model.Enabled.Returns(true); | ||
model.Validate().Returns(Result<bool, IEnumerable<ValidationError>>.Err(validationErrors)); | ||
|
||
var factory = Substitute.For<IFactory>(); | ||
factory.Create("new_flag", true).Returns(model); | ||
|
||
var interactor = new Interactor(repository, factory); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = | ||
"new_flag", | ||
Enabled = true | ||
}; | ||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().BadRequest(validationErrors); | ||
} | ||
|
||
[Test] | ||
public async Task | ||
CreateFeatureFlagInteractor_Should_Return_Validation_Error_If_Id_Already_Used() | ||
{ | ||
var validationError = new ValidationError | ||
{ | ||
Field = "Id", | ||
Message = "Id already exists" | ||
}; | ||
|
||
var model = Substitute.For<IModel>(); | ||
model.Id.Returns("new_flag"); | ||
model.Enabled.Returns(true); | ||
model.Validate().Returns(Result<bool, IEnumerable<ValidationError>>.Ok(true)); | ||
|
||
var repository = Substitute.For<IRepository>(); | ||
repository.Create(model).Returns(Result<string, Error>.Err(validationError)); | ||
|
||
var factory = Substitute.For<IFactory>(); | ||
factory.Create("new_flag", true).Returns(model); | ||
|
||
var interactor = new Interactor(repository, factory); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "new_flag", | ||
Enabled = true | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
var validationErrors = new List<ValidationError> { validationError }; | ||
presenter.Received().BadRequest(Arg.Is<List<ValidationError>>(x => x.SequenceEqual(validationErrors))); | ||
} | ||
|
||
[Test] | ||
public async Task CreateFeatureFlagInteractor_Should_Return_Error_If_Repository_Errors() | ||
{ | ||
var error = new Error | ||
{ | ||
Message = "Unknown error" | ||
}; | ||
|
||
var model = Substitute.For<IModel>(); | ||
model.Id.Returns("new_flag"); | ||
model.Enabled.Returns(true); | ||
model.Validate().Returns(Result<bool, IEnumerable<ValidationError>>.Ok(true)); | ||
|
||
var repository = Substitute.For<IRepository>(); | ||
repository.Create(model).Returns(Result<string, Error>.Err(error)); | ||
|
||
var factory = Substitute.For<IFactory>(); | ||
factory.Create("new_flag", true).Returns(model); | ||
|
||
var interactor = new Interactor(repository, factory); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "new_flag", | ||
Enabled = true | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().Error(error); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
Application.Tests/Unit/Interactors/DeleteFeatureFlag/InteractorTests.cs
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,87 @@ | ||
using Application.Interactors.DeleteFeatureFlag; | ||
using Domain.Common; | ||
using Domain.FeatureFlags; | ||
using NSubstitute; | ||
|
||
namespace Application.Tests.Unit.Interactors.DeleteFeatureFlag; | ||
|
||
[Category("Unit")] | ||
public sealed class InteractorTests | ||
{ | ||
[Test] | ||
public void DeleteFeatureFlagInteractor_Is_An_InputPort() | ||
{ | ||
var repository = Substitute.For<IRepository>(); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
Assert.That(interactor, Is.InstanceOf<IInputPort>()); | ||
} | ||
|
||
[Test] | ||
public async Task DeleteFeatureFlagInteractor_Deletes_A_Feature_Flag() | ||
{ | ||
var repository = Substitute.For<IRepository>(); | ||
repository.Delete("some_flag").Returns(Result<bool, Error>.Ok(true)); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "some_flag" | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().Ok(); | ||
} | ||
|
||
[Test] | ||
public async Task DeleteFeatureFlagInteractor_Should_Return_NotFound_If_Flag_Not_Found() | ||
{ | ||
var error = new NotFoundError(); | ||
|
||
var repository = Substitute.For<IRepository>(); | ||
repository.Delete("some_flag").Returns(Result<bool, Error>.Err(error)); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "some_flag" | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().NotFound(); | ||
} | ||
|
||
[Test] | ||
public async Task DeleteFeatureFlagInteractor_Should_Return_Error_If_Repository_Errors() | ||
{ | ||
var error = new Error | ||
{ | ||
Message = "Unknown error" | ||
}; | ||
|
||
var repository = Substitute.For<IRepository>(); | ||
repository.Delete("some_flag").Returns(Result<bool, Error>.Err(error)); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "some_flag" | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().Error(error); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...tFeatureFlag/CodePresenterFactoryTests.cs → ...tFeatureFlag/CodePresenterFactoryTests.cs
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
2 changes: 1 addition & 1 deletion
2
...tors/GetFeatureFlag/CodePresenterTests.cs → ...tors/GetFeatureFlag/CodePresenterTests.cs
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
65 changes: 65 additions & 0 deletions
65
Application.Tests/Unit/Interactors/GetFeatureFlag/InteractorTests.cs
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,65 @@ | ||
using Application.Interactors.GetFeatureFlag; | ||
using Domain.FeatureFlags; | ||
using NSubstitute; | ||
|
||
namespace Application.Tests.Unit.Interactors.GetFeatureFlag; | ||
|
||
[Category("Unit")] | ||
public sealed class InteractorTests | ||
{ | ||
[Test] | ||
public void GetFeatureFlagInteractor_Is_An_InputPort() | ||
{ | ||
var repository = Substitute.For<IRepository>(); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
Assert.That(interactor, Is.InstanceOf<IInputPort>()); | ||
} | ||
|
||
[Test] | ||
public async Task GetFeatureFlagInteractor_Returns_A_Feature_Flag() | ||
{ | ||
var model = new Model | ||
{ | ||
Id = "some_flag", | ||
Enabled = true | ||
}; | ||
|
||
var repository = Substitute.For<IRepository>(); | ||
repository.Get("some_flag").Returns(model); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "some_flag" | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().Ok(model); | ||
} | ||
|
||
[Test] | ||
public async Task GetFeatureFlagInteractor_Returns_NotFound() | ||
{ | ||
var repository = Substitute.For<IRepository>(); | ||
repository.Get("some_flag").Returns(new NullModel()); | ||
|
||
var interactor = new Interactor(repository); | ||
|
||
var request = new RequestModel | ||
{ | ||
Id = "some_flag" | ||
}; | ||
|
||
var presenter = Substitute.For<IOutputPort>(); | ||
|
||
await interactor.Execute(request, presenter); | ||
|
||
presenter.Received().NotFound(); | ||
} | ||
} |
Oops, something went wrong.