Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbasti committed Sep 20, 2024
1 parent 3155f8a commit 40f7da0
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 39 deletions.
15 changes: 13 additions & 2 deletions Src/Witsml/WitsmlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public interface IWitsmlClient
Task<string> AddToStoreAsync(string query, OptionsIn optionsIn = null);
Task<QueryResult> UpdateInStoreAsync<T>(T query) where T : IWitsmlQueryType;
Task<string> UpdateInStoreAsync(string query, OptionsIn optionsIn = null);
Task<QueryResult> DeleteFromStoreAsync<T>(T query, OptionsIn optionsIn = null) where T : IWitsmlQueryType;
Task<QueryResult> DeleteFromStoreAsync<T>(T query) where T : IWitsmlQueryType;
Task<QueryResult> DeleteFromStoreAsync<T>(T query, OptionsIn optionsIn) where T : IWitsmlQueryType;
Task<string> DeleteFromStoreAsync(string query, OptionsIn optionsIn = null);
Task<QueryResult> TestConnectionAsync();
Task<WitsmlCapServers> GetCap();
Expand Down Expand Up @@ -367,7 +368,17 @@ public async Task<string> UpdateInStoreAsync(string query, OptionsIn optionsIn =
throw new Exception($"Error while adding to store: {response.Result} - {errorResponse.Result}. {response.SuppMsgOut}");
}

public async Task<QueryResult> DeleteFromStoreAsync<T>(T query, OptionsIn optionsIn = null) where T : IWitsmlQueryType
public Task<QueryResult> DeleteFromStoreAsync<T>(T query) where T : IWitsmlQueryType
{
return DeleteFromStoreAsyncImplementation(query);
}

public Task<QueryResult> DeleteFromStoreAsync<T>(T query, OptionsIn optionsIn) where T : IWitsmlQueryType
{
return DeleteFromStoreAsyncImplementation(query, optionsIn);
}

private async Task<QueryResult> DeleteFromStoreAsyncImplementation<T>(T query, OptionsIn optionsIn = null) where T : IWitsmlQueryType
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DeleteWellboreWorker(ILogger<DeleteWellboreJob> logger, IWitsmlClientProv
string wellboreUid = job.ToDelete.WellboreUid;

WitsmlWellbores witsmlWellbore = WellboreQueries.DeleteWitsmlWellbore(wellUid, wellboreUid);
QueryResult result = cascadedDelete ? await GetTargetWitsmlClientOrThrow().DeleteFromStoreAsync(witsmlWellbore, new OptionsIn(CascadedDelete: true)) : await GetTargetWitsmlClientOrThrow().DeleteFromStoreAsync(witsmlWellbore);
QueryResult result = await GetTargetWitsmlClientOrThrow().DeleteFromStoreAsync(witsmlWellbore);
if (result.IsSuccessful)
{
Logger.LogInformation("Deleted wellbore. WellUid: {WellUid}, WellboreUid: {WellboreUid}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task Execute_DeleteTwoMnemonics_ReturnResult()
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(
Match.Create<IWitsmlQueryType>(o =>
((WitsmlLogs)o).Logs.First().UidWell == WellUid &&
((WitsmlLogs)o).Logs.First().UidWellbore == WellboreUid), null))
((WitsmlLogs)o).Logs.First().UidWellbore == WellboreUid)))
.ReturnsAsync(new QueryResult(true));

(WorkerResult result, RefreshAction refreshAction) = await _worker.Execute(CreateJob(ComponentType.Mnemonic));
Expand All @@ -82,7 +82,7 @@ public async Task Execute_DeleteTwoMnemonics_ReturnResult()
public async Task Execute_DeleteTwoTubularComponents_CorrectQuery()
{
List<IWitsmlQueryType> deleteQueries = new();
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>()))
.Callback<IWitsmlQueryType>(deleteQueries.Add)
.ReturnsAsync(new QueryResult(true));

Expand All @@ -103,7 +103,7 @@ public async Task Execute_DeleteTwoTubularComponents_CorrectQuery()
[Fact]
public async Task Execute_DeleteTwoTubularComponents_ReturnResult()
{
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>()))
.ReturnsAsync(new QueryResult(true));

(WorkerResult result, RefreshAction refreshAction) = await _worker.Execute(CreateJob(ComponentType.TubularComponent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task JobHasNoIndexRanges_DoNothing()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Never);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Never);
Assert.True(result.IsSuccess);
}

Expand All @@ -82,7 +82,7 @@ public async Task MnemonicsNotFoundOnLogObject_DoNothing()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Never);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Never);
Assert.True(result.IsSuccess);
}

Expand All @@ -99,7 +99,7 @@ public async Task LogObjectNotFound_SetNoSuccess()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Never);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Never);
Assert.False(result.IsSuccess);
}

Expand All @@ -111,7 +111,7 @@ public async Task SingleIndexRange_ShouldRunSingleDeleteQuery()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Once());
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Once());
Assert.True(result.IsSuccess);
}

Expand All @@ -129,7 +129,7 @@ public async Task SingleIndexRangeDecreasing_ShouldRunSingleDeleteQuery()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.Is<WitsmlLogs>(logs => logs.Logs.First().StartIndex.Value == "20" && logs.Logs.First().EndIndex.Value == "10"), null), Times.Once());
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.Is<WitsmlLogs>(logs => logs.Logs.First().StartIndex.Value == "20" && logs.Logs.First().EndIndex.Value == "10")), Times.Once());
Assert.True(result.IsSuccess);
}

Expand All @@ -149,7 +149,7 @@ public async Task TwoIndexRanges_ShouldRunTwoDeleteQueries_DepthIndexed()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Exactly(2));
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Exactly(2));
Assert.True(result.IsSuccess);
}

Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task TwoIndexRanges_ShouldRunTwoDeleteQueries_TimeIndexed()
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Exactly(2));
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Exactly(2));
Assert.True(result.IsSuccess);
}

Expand All @@ -203,7 +203,7 @@ public async Task IndexRangeOutsideLogIndex_ShouldNotRunAnyDeleteQueries_DepthIn
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Never);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Never);
Assert.True(result.IsSuccess);
}

Expand All @@ -229,7 +229,7 @@ public async Task IndexRangeOutsideLogIndex_ShouldNotRunAnyDeleteQueries_TimeInd
(WorkerResult result, RefreshAction _) = await _worker.Execute(job);

_witsmlClient.Verify(client => client.GetFromStoreAsync(It.IsAny<WitsmlLogs>(), It.Is<OptionsIn>((ops) => ops.ReturnElements == ReturnElements.HeaderOnly)), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Never);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Never);
Assert.True(result.IsSuccess);
}

Expand All @@ -245,7 +245,7 @@ private void SetupLog(string indexType, Index startIndex, Index endIndex, string
.ReturnsAsync(new WitsmlLogs());

_witsmlClient.Setup(client =>
client.DeleteFromStoreAsync(It.Is<WitsmlLogs>(witsmlLogs => witsmlLogs.Logs.First().Uid == LogUid), null))
client.DeleteFromStoreAsync(It.Is<WitsmlLogs>(witsmlLogs => witsmlLogs.Logs.First().Uid == LogUid)))
.ReturnsAsync(new QueryResult(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task Execute_DeleteTwoLogs_ReturnResult()
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(
Match.Create<IWitsmlQueryType>(o =>
((WitsmlLogs)o).Logs.First().UidWell == WellUid &&
((WitsmlLogs)o).Logs.First().UidWellbore == WellboreUid), null))
((WitsmlLogs)o).Logs.First().UidWellbore == WellboreUid)))
.ReturnsAsync(new QueryResult(true));

(WorkerResult result, RefreshAction refreshAction) = await _worker.Execute(CreateJob(EntityType.Log));
Expand All @@ -75,7 +75,7 @@ public async Task Execute_DeleteTwoTubulars_ReturnResult()
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(
Match.Create<IWitsmlQueryType>(o =>
((WitsmlTubulars)o).Tubulars.First().UidWell == WellUid &&
((WitsmlTubulars)o).Tubulars.First().UidWellbore == WellboreUid), null))
((WitsmlTubulars)o).Tubulars.First().UidWellbore == WellboreUid)))
.ReturnsAsync(new QueryResult(true));

(WorkerResult result, RefreshAction refreshAction) = await _worker.Execute(CreateJob(EntityType.Tubular));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using Witsml;
using Witsml.Data;
using Witsml.ServiceReference;

using WitsmlExplorer.Api.Jobs;
using WitsmlExplorer.Api.Models;
Expand Down Expand Up @@ -51,7 +52,7 @@ private static DeleteWellJob CreateJob()
[Fact]
public async Task Execute_DeleteWell_RefreshAction()
{
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>()))
.ReturnsAsync(new QueryResult(true));

(WorkerResult result, RefreshAction refreshAction) = await _worker.Execute(CreateJob());
Expand All @@ -63,7 +64,7 @@ public async Task Execute_DeleteWell_RefreshAction()
public async Task Execute_DeleteWell_ReturnResult()
{
WitsmlWells query = null;
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlWells>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlWells>()))
.Callback<WitsmlWells>((wells) => query = wells)
.ReturnsAsync(new QueryResult(true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using Witsml;
using Witsml.Data;
using Witsml.ServiceReference;

using WitsmlExplorer.Api.Jobs;
using WitsmlExplorer.Api.Models;
Expand Down Expand Up @@ -53,7 +54,7 @@ private static DeleteWellboreJob CreateJob()
[Fact]
public async Task Execute_DeleteWellbore_RefreshAction()
{
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>()))
.ReturnsAsync(new QueryResult(true));

(WorkerResult result, RefreshAction refreshAction) = await _worker.Execute(CreateJob());
Expand All @@ -66,7 +67,7 @@ public async Task Execute_DeleteWellbore_RefreshAction()
public async Task Execute_DeleteWellbore_ReturnResult()
{
WitsmlWellbores query = null;
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlWellbores>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlWellbores>()))
.Callback<WitsmlWellbores>((wellBores) => query = wellBores)
.ReturnsAsync(new QueryResult(true));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public async void RenameMnemonic_Execute_ValidResults()
.ReturnsAsync(new QueryResult(true));

_witsmlClient.Setup(client =>
client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null))
client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()))
.ReturnsAsync(new QueryResult(true));

await _worker.Execute(job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Expected Data (indexCurve, curve1):
var (result, refreshAction) = await _worker.Execute(job);

Assert.True(result.IsSuccess);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Once);
_witsmlClient.Verify(client => client.UpdateInStoreAsync(It.Is<WitsmlLogs>(logs => ValidateLogs(logs, expectedData))), Times.Once);
}

Expand Down Expand Up @@ -104,7 +104,7 @@ Expected Data (indexCurve, curve1):
var (result, refreshAction) = await _worker.Execute(job);

Assert.True(result.IsSuccess);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null), Times.Once);
_witsmlClient.Verify(client => client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()), Times.Once);
_witsmlClient.Verify(client => client.UpdateInStoreAsync(It.Is<WitsmlLogs>(logs => ValidateLogs(logs, expectedData))), Times.Once);
}

Expand Down Expand Up @@ -182,7 +182,7 @@ private void SetupClient(Mock<IWitsmlClient> witsmlClient, string indexType)
});

witsmlClient.Setup(client =>
client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>(), null))
client.DeleteFromStoreAsync(It.IsAny<WitsmlLogs>()))
.Returns((WitsmlLogs logs) =>
{
return Task.FromResult(new QueryResult(true));
Expand Down
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 Down Expand Up @@ -118,7 +119,7 @@ public async Task Execute_ReplaceTubularComponents_IsSuccess()
private void SetUpStoreForDelete(bool deleteResult = true)
{
List<IWitsmlQueryType> deleteQueries = new();
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>()))
.Callback<IWitsmlQueryType>(deleteQueries.Add)
.ReturnsAsync(new QueryResult(deleteResult));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ private static ReplaceObjectsJob SetUpReplaceObjectsJob()
private void SetUpStoreForDelete(bool queryResult = true)
{
List<IWitsmlQueryType> deleteQueries = new();
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>(), null))
_witsmlClient.Setup(client => client.DeleteFromStoreAsync(It.IsAny<IWitsmlQueryType>()))
.Callback<IWitsmlQueryType>(deleteQueries.Add)
.ReturnsAsync(new QueryResult(true));

_witsmlClient.Setup(client => client.DeleteFromStoreAsync(
Match.Create<IWitsmlQueryType>(o =>
((WitsmlTubulars)o).Tubulars.First().UidWell == WellUid &&
((WitsmlTubulars)o).Tubulars.First().UidWellbore == TargetWellboreUid), null))
((WitsmlTubulars)o).Tubulars.First().UidWellbore == TargetWellboreUid)))
.ReturnsAsync(new QueryResult(queryResult));
}

Expand Down
Loading

0 comments on commit 40f7da0

Please sign in to comment.