PCRB follow up client side services
This commit is contained in:
63
MesaFabApproval.API.Test/MonInUtilsTests.cs
Normal file
63
MesaFabApproval.API.Test/MonInUtilsTests.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using Moq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MesaFabApproval.API.Utilities;
|
||||
using MesaFabApproval.Shared.Models;
|
||||
using MesaFabApproval.Shared.Services;
|
||||
|
||||
namespace MesaFabApproval.API.Test;
|
||||
|
||||
public class MonInUtilsTests {
|
||||
private readonly Mock<IMonInWorkerClient> _mockMonInClient;
|
||||
private readonly Mock<ILogger<MonInUtils>> _mockLogger;
|
||||
private readonly MonInUtils _monInUtils;
|
||||
|
||||
public MonInUtilsTests() {
|
||||
_mockMonInClient = new Mock<IMonInWorkerClient>();
|
||||
_mockMonInClient
|
||||
.Setup(client => client.PostAverage(It.IsAny<string>(), It.IsAny<double>()))
|
||||
.Verifiable();
|
||||
|
||||
_mockLogger = new Mock<ILogger<MonInUtils>>();
|
||||
|
||||
_monInUtils = new MonInUtils(_mockMonInClient.Object, _mockLogger.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostMetrics_ShouldPostAverageAndStatusOk_WhenNoErrors() {
|
||||
string metricName = "TestMetric";
|
||||
double latency = 100;
|
||||
bool isArgumentError = false;
|
||||
bool isInternalError = false;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, latency, isArgumentError, isInternalError);
|
||||
|
||||
_mockMonInClient.Verify(client => client.PostAverage(metricName + "Latency", latency), Times.Once);
|
||||
_mockMonInClient.Verify(client => client.PostStatus(metricName, StatusValue.Ok), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostMetrics_ShouldPostAverageAndStatusOk_WhenArgumentError() {
|
||||
string metricName = "TestMetric";
|
||||
double latency = 100;
|
||||
bool isArgumentError = true;
|
||||
bool isInternalError = false;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, latency, isArgumentError, isInternalError);
|
||||
|
||||
_mockMonInClient.Verify(client => client.PostAverage(metricName + "Latency", latency), Times.Once);
|
||||
_mockMonInClient.Verify(client => client.PostStatus(metricName, StatusValue.Ok), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostMetrics_ShouldPostAverageAndStatusCritical_WhenInternalError() {
|
||||
string metricName = "TestMetric";
|
||||
double latency = 100;
|
||||
bool isArgumentError = false;
|
||||
bool isInternalError = true;
|
||||
|
||||
_monInUtils.PostMetrics(metricName, latency, isArgumentError, isInternalError);
|
||||
|
||||
_mockMonInClient.Verify(client => client.PostAverage(metricName + "Latency", latency), Times.Once);
|
||||
_mockMonInClient.Verify(client => client.PostStatus(metricName, StatusValue.Critical), Times.Once);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user