Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using TickAPI.Common.Result;
using TickAPI.Common.Results;
using TickAPI.Common.Results.Generic;

namespace TickAPI.Tests.Common.Result;
namespace TickAPI.Tests.Common.Results.Generic;

public class ResultTests
{
Expand Down Expand Up @@ -46,6 +47,21 @@ public void PropagateError_WhenResultWithErrorPassed_ShouldReturnResultWithError
Assert.Equal(errorMsg, result.ErrorMsg);
Assert.Equal(statusCode, result.StatusCode);
}

[Fact]
public void PropagateError_WhenNonGenericResultWithErrorPassed_ShouldReturnResultWithError()
{
const int statusCode = 500;
const string errorMsg = "error message";
var resultWithError = Result.Failure(statusCode, errorMsg);

var result = Result<int>.PropagateError(resultWithError);

Assert.True(result.IsError);
Assert.False(result.IsSuccess);
Assert.Equal(errorMsg, result.ErrorMsg);
Assert.Equal(statusCode, result.StatusCode);
}

[Fact]
public void PropagateError_WhenResultWithSuccessPassed_ShouldThrowArgumentException()
Expand All @@ -56,4 +72,14 @@ public void PropagateError_WhenResultWithSuccessPassed_ShouldThrowArgumentExcept

Assert.Throws<ArgumentException>(act);
}

[Fact]
public void PropagateError_WhenNonGenericResultWithSuccessPassed_ShouldThrowArgumentException()
{
var resultWithSuccess = Result.Success();

var act = () => Result<int>.PropagateError(resultWithSuccess);

Assert.Throws<ArgumentException>(act);
}
}
57 changes: 57 additions & 0 deletions TickAPI/TickAPI.Tests/Common/Results/ResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using TickAPI.Common.Results;
using TickAPI.Common.Results.Generic;

namespace TickAPI.Tests.Common.Results;

public class ResultTests
{
[Fact]
public void Success_ShouldReturnResultWithSuccess()
{
var result = Result.Success();

Assert.True(result.IsSuccess);
Assert.False(result.IsError);
Assert.Equal("", result.ErrorMsg);
Assert.Equal(200, result.StatusCode);
}

[Fact]
public void Failure_ShouldReturnResultWithError()
{
const int statusCode = 500;
const string errorMsg = "example error msg";

var result = Result.Failure(500, errorMsg);

Assert.True(result.IsError);
Assert.False(result.IsSuccess);
Assert.Equal(errorMsg, result.ErrorMsg);
Assert.Equal(statusCode, result.StatusCode);
}

[Fact]
public void PropagateError_WhenGenericResultWithErrorPassed_ShouldReturnResultWithError()
{
const int statusCode = 500;
const string errorMsg = "error message";
var resultWithError = Result<int>.Failure(statusCode, errorMsg);

var result = Result.PropagateError(resultWithError);

Assert.True(result.IsError);
Assert.False(result.IsSuccess);
Assert.Equal(errorMsg, result.ErrorMsg);
Assert.Equal(statusCode, result.StatusCode);
}

[Fact]
public void PropagateError_WhenGenericResultWithSuccessPassed_ShouldThrowArgumentException()
{
var resultWithSuccess = Result<int>.Success(123);

var act = () => Result<int>.PropagateError(resultWithSuccess);

Assert.Throws<ArgumentException>(act);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using TickAPI.Common.Auth.Abstractions;
using TickAPI.Common.Auth.Enums;
using TickAPI.Common.Auth.Responses;
using TickAPI.Common.Result;
using TickAPI.Common.Results.Generic;
using TickAPI.Customers.Abstractions;
using TickAPI.Customers.Controllers;
using TickAPI.Customers.DTOs.Request;
Expand Down Expand Up @@ -41,7 +41,7 @@ public async Task GoogleLogin_WhenAuthSuccessAndCustomerExists_ShouldReturnToken
customerServiceMock.Object);

// Act
var actionResult = await sut.GoogleLogin(new GoogleLoginDto(accessToken));
var actionResult = await sut.GoogleLogin(new GoogleCustomerLoginDto(accessToken));

// Assert
Assert.Equal(jwtToken, actionResult.Value?.Token);
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task GoogleLogin_WhenAuthSuccessAndCustomerDoesNotExist_ShouldCreat
customerServiceMock.Object);

// Act
var result = await sut.GoogleLogin(new GoogleLoginDto( accessToken ));
var result = await sut.GoogleLogin(new GoogleCustomerLoginDto( accessToken ));

// Assert
Assert.Equal(jwtToken, result.Value?.Token);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Http;
using Moq;
using TickAPI.Common.Result;
using TickAPI.Common.Results.Generic;
using TickAPI.Common.Time.Abstractions;
using TickAPI.Customers.Abstractions;
using TickAPI.Customers.Models;
Expand Down
Loading
Loading