Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigojap committed Feb 4, 2021
1 parent e788eb7 commit f43a1ad
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Linq;
using VirtualMind.Application.Commands;
using Xunit;

namespace VirtualMind.Application.Tests.Commands
{
public class CreateOperationCommandTests
{
[Fact(DisplayName = "Add new VALID Operation Command")]
[Trait("Category", "Commands")]
public void CreateOperation_IsValid_ShouldPass()
{
//Arrange
var command = new CreateOperationCommand()
{
CurrencyType = "USD",
RequestedAmount = 100,
UserId = 1
};

//Act
var validation = new CreateOperationCommandValidator().Validate(command).IsValid;

//Assert
Assert.True(validation);
}

[Fact(DisplayName = "Add new INVALID Operation Command")]
[Trait("Category", "Commands")]
public void CreateOperation_IsNotValid_ShouldNotPass()
{
//Arrange
var command = new CreateOperationCommand()
{
CurrencyType = "",
RequestedAmount = 0,
UserId = 0
};

//Act
var validation = new CreateOperationCommandValidator().Validate(command);

//Assert
Assert.False(validation.IsValid);
Assert.Contains("[UserId] must be greater Than 0", validation.Errors.Select(c => c.ErrorMessage));
Assert.Contains("[RequestedAmount] must be greater Than 0", validation.Errors.Select(c => c.ErrorMessage));
Assert.Contains("[CurrencyType] can't be empty", validation.Errors.Select(c => c.ErrorMessage));
Assert.Contains("Invalid [CurrencyType]", validation.Errors.Select(c => c.ErrorMessage));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.Linq;
using VirtualMind.Application.Queries;
using Xunit;

namespace VirtualMind.Application.Tests.Queries
{
public class GetCurrencyExchangeQueryTests
{
[Fact(DisplayName = "Execute VALID Query")]
[Trait("Category", "Queries")]
public void GetExchange_IsValid_ShouldPass()
{
//Arrange
var query = new GetCurrencyExchangeQuery()
{
CurrencyType = "USD"
};

//Act
var validation = new GetCurrencyExchangeValidator().Validate(query);

//Assert
Assert.True(validation.IsValid);
}

[Fact(DisplayName = "Execute INVALID Query")]
[Trait("Category", "Queries")]
public void GetExchange_IsNotValid_ShouldNotPass()
{
//Arrange
var query = new GetCurrencyExchangeQuery()
{
CurrencyType = null
};

var emptyQuery = new GetCurrencyExchangeQuery()
{
CurrencyType = ""
};

//Act
var validation = new GetCurrencyExchangeValidator().Validate(query);
var secondValidation = new GetCurrencyExchangeValidator().Validate(emptyQuery);

//Assert
Assert.False(validation.IsValid);

Assert.Contains("[CurrencyType] can't be null!", validation.Errors.Select(c => c.ErrorMessage));
Assert.Contains("[CurrencyType] field is required!", validation.Errors.Select(c => c.ErrorMessage));
Assert.Contains("Invalid [CurrencyType]!", secondValidation.Errors.Select(c => c.ErrorMessage));
}
}
}
28 changes: 28 additions & 0 deletions VirtualMind.Application.Tests/VirtualMind.Application.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MOQ" Version="4.16.0" />
<PackageReference Include="MOQ.automock" Version="2.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\VirtualMind.Application\VirtualMind.Application.csproj" />
</ItemGroup>

</Project>
3 changes: 2 additions & 1 deletion VirtualMind.Application/Commands/CreateOperationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ public async Task<int> Handle(CreateOperationCommand request, CancellationToken
};

await VirtualMindDbContext.Operations.AddAsync(operation);

return await VirtualMindDbContext.SaveChangesAsync();
}

private async Task<ExchangeRateDTO> GetCurrentQuote(string currencyType)
{
var result = await CurrencyExchangeFactory.GetExchangeRate(currencyType);
var result = await CurrencyExchangeFactory.GetExchangeRate(currencyType);

var currnetQuote = new ExchangeRateDTO
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public CreateOperationCommandValidator()

RuleFor(input => input.RequestedAmount)
.GreaterThan(0).WithMessage("[RequestedAmount] must be greater Than 0")
.NotNull().WithMessage("[RequestedAmount] can't be null!");
.NotNull().WithMessage("[RequestedAmount] can't be null");

RuleFor(input => input.CurrencyType)
.NotNull().WithMessage("[CurrencyType] can't be null!")
.NotEmpty().WithMessage("[CurrencyType] field is required!")
.IsEnumName(typeof(Currency), false).WithMessage("Invalid [CurrencyType]!");
.NotNull().WithMessage("[CurrencyType] can't be null")
.NotEmpty().WithMessage("[CurrencyType] can't be empty")
.IsEnumName(typeof(Currency), false).WithMessage("Invalid [CurrencyType]");
}
}
}
17 changes: 16 additions & 1 deletion VirtualMind.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualMind.Application", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtualMind.Domain", "VirtualMind.Domain\VirtualMind.Domain.csproj", "{4F80DA53-FD10-4CDF-93B5-CA99737CE7D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtuaMind.Infrastructure", "VirtuaMind.Infrastructure\VirtuaMind.Infrastructure.csproj", "{EEF1CC3D-65A5-4AE5-A394-86F294261237}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VirtuaMind.Infrastructure", "VirtuaMind.Infrastructure\VirtuaMind.Infrastructure.csproj", "{EEF1CC3D-65A5-4AE5-A394-86F294261237}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{16892318-E8DF-4B42-A244-55DB5AE667E0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{66227B40-FBD7-4C28-A2C6-322769C33178}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VirtualMind.Application.Tests", "VirtualMind.Application.Tests\VirtualMind.Application.Tests.csproj", "{31104BBC-F583-452F-AAC7-3AE09FFBEFA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -41,15 +47,24 @@ Global
{EEF1CC3D-65A5-4AE5-A394-86F294261237}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEF1CC3D-65A5-4AE5-A394-86F294261237}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEF1CC3D-65A5-4AE5-A394-86F294261237}.Release|Any CPU.Build.0 = Release|Any CPU
{31104BBC-F583-452F-AAC7-3AE09FFBEFA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{31104BBC-F583-452F-AAC7-3AE09FFBEFA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31104BBC-F583-452F-AAC7-3AE09FFBEFA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31104BBC-F583-452F-AAC7-3AE09FFBEFA2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{92605427-E7F4-457F-B8E7-9A31412FD4B7} = {16892318-E8DF-4B42-A244-55DB5AE667E0}
{D72102A2-1750-4B82-B91A-1B132D86B094} = {92605427-E7F4-457F-B8E7-9A31412FD4B7}
{0AEF29E2-7E5A-4012-AEB4-184C1BC44328} = {16892318-E8DF-4B42-A244-55DB5AE667E0}
{F3E702F6-1383-4A90-AE2C-2863A1E1EDD1} = {16892318-E8DF-4B42-A244-55DB5AE667E0}
{7804AEC5-0FE4-4706-A064-F1F4AA9421F1} = {16892318-E8DF-4B42-A244-55DB5AE667E0}
{C7E47AE3-D1C8-4395-88C8-AAE5818D5ACC} = {0AEF29E2-7E5A-4012-AEB4-184C1BC44328}
{4F80DA53-FD10-4CDF-93B5-CA99737CE7D4} = {F3E702F6-1383-4A90-AE2C-2863A1E1EDD1}
{EEF1CC3D-65A5-4AE5-A394-86F294261237} = {7804AEC5-0FE4-4706-A064-F1F4AA9421F1}
{31104BBC-F583-452F-AAC7-3AE09FFBEFA2} = {66227B40-FBD7-4C28-A2C6-322769C33178}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BBFF54F8-17FC-477F-852E-5089020CE7BF}
Expand Down

0 comments on commit f43a1ad

Please sign in to comment.