Skip to content

Commit

Permalink
Unit tests for universal priority curves #2545 (#2548)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbasti committed Sep 17, 2024
1 parent 5092c18 commit f34d0b3
Showing 1 changed file with 80 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -19,9 +20,11 @@ public class LogCurvePriorityServiceTests
private readonly List<string> _prioritizedCurvesWell1Wellbore1 = new() { "curve1", "curve2" };
private readonly List<string> _prioritizedCurvesWell1Wellbore2 = new() { "A", "B", "C" };
private readonly List<string> _prioritizedCurvesWell2Wellbore1 = new() { "1", "2", "3", "4" };
private readonly List<string> _prioritizedCurvesUniversal = new() { "A", "B", "C" };
private readonly LogCurvePriority _logCurvePriorityWell1Wellbore1;
private readonly LogCurvePriority _logCurvePriorityWell1Wellbore2;
private readonly LogCurvePriority _logCurvePriorityWell2Wellbore1;
private readonly LogCurvePriority _logCurvePriorityUniversal;

public LogCurvePriorityServiceTests()
{
Expand All @@ -39,6 +42,10 @@ public LogCurvePriorityServiceTests()
{
PrioritizedCurves = _prioritizedCurvesWell2Wellbore1
};
_logCurvePriorityUniversal = new LogCurvePriority("universal")
{
PrioritizedCurves = _prioritizedCurvesUniversal
};

_repository.Setup(repo => repo.GetDocumentAsync(It.IsAny<string>())).ReturnsAsync((LogCurvePriority)null);
_repository.Setup(repo => repo.GetDocumentAsync("well1-wellbore1")).ReturnsAsync(_logCurvePriorityWell1Wellbore1);
Expand All @@ -63,6 +70,16 @@ public async Task GetPrioritizedLocalCurves_CorrectIds_ReturnsExpectedCurves()
_repository.Verify(repo => repo.GetDocumentAsync(It.Is<string>(id => id == $"{wellUid}-{wellboreUid}")), Times.Once);
}

[Fact]
public async Task GetPrioritizedUniversalCurves_CorrectIds_ReturnsExpectedCurves()
{
_repository.Setup(repo => repo.GetDocumentAsync("universal")).ReturnsAsync(_logCurvePriorityUniversal);
var result = await _logCurvePriorityService.GetPrioritizedUniversalCurves();

Assert.Equal(_prioritizedCurvesUniversal, result);
_repository.Verify(repo => repo.GetDocumentAsync(It.Is<string>(id => id == "universal")), Times.Once);
}

[Fact]
public async Task GetPrioritizedLocalCurves_IncorrectId_ReturnsNull()
{
Expand All @@ -75,39 +92,83 @@ public async Task GetPrioritizedLocalCurves_IncorrectId_ReturnsNull()
_repository.Verify(repo => repo.GetDocumentAsync(It.Is<string>(id => id == $"{wellUid}-{wellboreUid}")), Times.Once);
}

[Fact]
public async Task GetPrioritizedUniversalCurves_IncorrectId_ReturnsNull()
{
var result = await _logCurvePriorityService.GetPrioritizedUniversalCurves();

Assert.Null(result);
_repository.Verify(repo => repo.GetDocumentAsync(It.Is<string>(id => id == $"universal")), Times.Once);
}

[Fact]
public async Task SetPrioritizedLocalCurves_NoExistingPriority_CreatesNewPriority()
{
var wellUid = "well3";
var wellboreUid = "wellbore3";
var curves = new List<string> { "AA", "AB" };
var curves = new List<string> { "AA", "AB", "AA" };
var expectedUniqueCurves = new List<string> { "AA", "AB" };
var logCurvePriority = new LogCurvePriority($"{wellUid}-{wellboreUid}")
{
PrioritizedCurves = curves
};

var result = await _logCurvePriorityService.SetPrioritizedLocalCurves(wellUid, wellboreUid, curves);

Assert.Equal(curves, result);
Assert.Equal(expectedUniqueCurves, result);
_repository.Verify(repo => repo.UpdateDocumentAsync(It.IsAny<string>(), It.IsAny<LogCurvePriority>()), Times.Never);
_repository.Verify(repo => repo.CreateDocumentAsync(It.Is<LogCurvePriority>(lcp => lcp.Id == $"{wellUid}-{wellboreUid}" && lcp.PrioritizedCurves.SequenceEqual(expectedUniqueCurves))), Times.Once);
}

[Fact]
public async Task SetPrioritizedUniversalCurves_NoExistingPriority_CreatesNewPriority()
{
var curves = new List<string> { "AA", "AB", "AA" };
var expectedUniqueCurves = new List<string> { "AA", "AB" };
var logCurvePriority = new LogCurvePriority($"universal")
{
PrioritizedCurves = curves
};

var result = await _logCurvePriorityService.SetPrioritizedUniversalCurves(curves);
Assert.Equal(expectedUniqueCurves, result);
_repository.Verify(repo => repo.UpdateDocumentAsync(It.IsAny<string>(), It.IsAny<LogCurvePriority>()), Times.Never);
_repository.Verify(repo => repo.CreateDocumentAsync(It.Is<LogCurvePriority>(lcp => lcp.Id == $"{wellUid}-{wellboreUid}" && lcp.PrioritizedCurves.SequenceEqual(curves))), Times.Once);
_repository.Verify(repo => repo.CreateDocumentAsync(It.Is<LogCurvePriority>(lcp => lcp.Id == $"universal" && lcp.PrioritizedCurves.SequenceEqual(expectedUniqueCurves))), Times.Once);
}

[Fact]
public async Task SetPrioritizedLocalCurves_ExistingPriority_ReplacesPriority()
{
var wellUid = "well1";
var wellboreUid = "wellbore2";
var curves = new List<string> { "D", "E" };
var curves = new List<string> { "D", "E", "D" };
var expectedUniqueCurves = new List<string> { "D", "E" };
var logCurvePriority = new LogCurvePriority($"{wellUid}-{wellboreUid}")
{
PrioritizedCurves = curves
};

var result = await _logCurvePriorityService.SetPrioritizedLocalCurves(wellUid, wellboreUid, curves);

Assert.Equal(curves, result);
_repository.Verify(repo => repo.UpdateDocumentAsync($"{wellUid}-{wellboreUid}", It.Is<LogCurvePriority>(lcp => lcp.PrioritizedCurves.SequenceEqual(curves))), Times.Once);
Assert.Equal(expectedUniqueCurves, result);
_repository.Verify(repo => repo.UpdateDocumentAsync($"{wellUid}-{wellboreUid}", It.Is<LogCurvePriority>(lcp => lcp.PrioritizedCurves.SequenceEqual(expectedUniqueCurves))), Times.Once);
}

[Fact]
public async Task SetPrioritizedUniversalCurves_ExistingPriority_ReplacesPriority()
{
_repository.Setup(repo => repo.GetDocumentAsync("universal")).ReturnsAsync(_logCurvePriorityUniversal);
var curves = new List<string> { "D", "E", "D" };
var expectedUniqueCurves = new List<string> { "D", "E" };
var logCurvePriority = new LogCurvePriority($"universal")
{
PrioritizedCurves = curves
};

var result = await _logCurvePriorityService.SetPrioritizedUniversalCurves(curves);

Assert.Equal(expectedUniqueCurves, result);
_repository.Verify(repo => repo.UpdateDocumentAsync($"universal", It.Is<LogCurvePriority>(lcp => lcp.PrioritizedCurves.SequenceEqual(expectedUniqueCurves))), Times.Once);
}

[Fact]
Expand All @@ -123,5 +184,18 @@ public async Task SetPrioritizedLocalCurves_EmptyInput_RemovesPriorityObject()
_repository.Verify(repo => repo.UpdateDocumentAsync(It.IsAny<string>(), It.IsAny<LogCurvePriority>()), Times.Never);
_repository.Verify(repo => repo.DeleteDocumentAsync($"{wellUid}-{wellboreUid}"), Times.Once);
}

[Fact]
public async Task SetPrioritizedUniversalCurves_EmptyInput_RemovesPriorityObject()
{
var expectedResult = 0;
_repository.Setup(repo => repo.GetDocumentAsync("universal")).ReturnsAsync(_logCurvePriorityUniversal);
var curves = new List<string>();

var result = await _logCurvePriorityService.SetPrioritizedUniversalCurves(curves);

Assert.Equal(result.Count, expectedResult);
_repository.Verify(repo => repo.UpdateDocumentAsync(It.IsAny<string>(), It.IsAny<LogCurvePriority>()), Times.Once);
}
}
}

0 comments on commit f34d0b3

Please sign in to comment.