Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix list proxy not showing artifacts w no res
- Loading branch information
Showing
7 changed files
with
328 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.Text.Json; | ||
using Art.Common.Management; | ||
using Art.Common.Proxies; | ||
using Art.TestsBase; | ||
using NUnit.Framework; | ||
|
||
namespace Art.Common.Tests; | ||
|
||
public class ArtifactToolDumpProxyTests | ||
{ | ||
[Test] | ||
public async Task FindOnlyTool_WithoutArtifactList_Throws() | ||
{ | ||
var profile = new ArtifactToolProfile("tool", null, null); | ||
var tool = new ProgrammableArtifactFindTool((v, k) => | ||
{ | ||
int i = int.Parse(k); | ||
if (1 <= i && i <= 3) | ||
{ | ||
return v.CreateData($"{i}"); | ||
} | ||
return null; | ||
}); | ||
await tool.InitializeAsync(profile: profile); | ||
var proxy = new ArtifactToolDumpProxy(tool, new ArtifactToolDumpOptions(), null); | ||
Assert.That(async () => await proxy.DumpAsync(), Throws.InstanceOf<NotSupportedException>()); | ||
} | ||
|
||
[Test] | ||
public async Task FindOnlyTool_WithArtifactList_Success() | ||
{ | ||
var options = new Dictionary<string, JsonElement> { { "artifactList", JsonSerializer.SerializeToElement(new[] { "1", "2", "3" }) } }; | ||
var profile = new ArtifactToolProfile("tool", null, options); | ||
var arm = new InMemoryArtifactRegistrationManager(); | ||
var config = new ArtifactToolConfig(arm, new NullArtifactDataManager()); | ||
var tool = new ProgrammableArtifactFindTool((v, k) => | ||
{ | ||
int i = int.Parse(k); | ||
if (1 <= i && i <= 3) | ||
{ | ||
return v.CreateData($"{i}"); | ||
} | ||
return null; | ||
}); | ||
await tool.InitializeAsync(config: config, profile: profile); | ||
var proxy = new ArtifactToolDumpProxy(tool, new ArtifactToolDumpOptions(), null); | ||
await proxy.DumpAsync(); | ||
Assert.That((await arm.ListArtifactsAsync()).Select(v => int.Parse(v.Key.Id)), Is.EquivalentTo(new[] { 1, 2, 3 })); | ||
} | ||
|
||
[Test] | ||
public async Task DumpOnlyTool_WithoutArtifactList_Success() | ||
{ | ||
var options = new Dictionary<string, JsonElement> { { "artifactList", JsonSerializer.SerializeToElement(new[] { "1", "2", "3" }) } }; | ||
var profile = new ArtifactToolProfile("tool", null, options); | ||
var arm = new InMemoryArtifactRegistrationManager(); | ||
var config = new ArtifactToolConfig(arm, new NullArtifactDataManager()); | ||
var tool = new AsyncProgrammableArtifactDumpTool(async v => | ||
{ | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
await v.DumpArtifactAsync(v.CreateData($"{i}")); | ||
} | ||
}); | ||
await tool.InitializeAsync(config: config, profile: profile); | ||
var proxy = new ArtifactToolDumpProxy(tool, new ArtifactToolDumpOptions(), null); | ||
await proxy.DumpAsync(); | ||
Assert.That((await arm.ListArtifactsAsync()).Select(v => int.Parse(v.Key.Id)), Is.EquivalentTo(new[] { 1, 2, 3 })); | ||
} | ||
|
||
[Test] | ||
public async Task DumpOnlyTool_WithArtifactList_DoesNotFilter() | ||
{ | ||
var options = new Dictionary<string, JsonElement> { { "artifactList", JsonSerializer.SerializeToElement(new[] { "1", "2" }) } }; | ||
var profile = new ArtifactToolProfile("tool", null, options); | ||
var arm = new InMemoryArtifactRegistrationManager(); | ||
var config = new ArtifactToolConfig(arm, new NullArtifactDataManager()); | ||
var tool = new AsyncProgrammableArtifactDumpTool(async v => | ||
{ | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
await v.DumpArtifactAsync(v.CreateData($"{i}")); | ||
} | ||
}); | ||
await tool.InitializeAsync(config: config, profile: profile); | ||
var proxy = new ArtifactToolDumpProxy(tool, new ArtifactToolDumpOptions(), null); | ||
await proxy.DumpAsync(); | ||
Assert.That((await arm.ListArtifactsAsync()).Select(v => int.Parse(v.Key.Id)), Is.EquivalentTo(new[] { 1, 2, 3 })); | ||
} | ||
|
||
// TODO prioritisation tests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Text.Json; | ||
using Art.Common.Proxies; | ||
using Art.TestsBase; | ||
using NUnit.Framework; | ||
|
||
namespace Art.Common.Tests; | ||
|
||
public class ArtifactToolListProxyTests | ||
{ | ||
[Test] | ||
public async Task FindOnlyTool_WithoutArtifactList_Throws() | ||
{ | ||
var profile = new ArtifactToolProfile("tool", null, null); | ||
var tool = new ProgrammableArtifactFindTool((v, k) => | ||
{ | ||
int i = int.Parse(k); | ||
if (1 <= i && i <= 3) | ||
{ | ||
return v.CreateData($"{i}"); | ||
} | ||
return null; | ||
}); | ||
await tool.InitializeAsync(profile: profile); | ||
var proxy = new ArtifactToolListProxy(tool, new ArtifactToolListOptions(), null); | ||
Assert.That(async () => await proxy.ListAsync().ToListAsync(), Throws.InstanceOf<NotSupportedException>()); | ||
} | ||
|
||
[Test] | ||
public async Task FindOnlyTool_WithArtifactList_Success() | ||
{ | ||
var options = new Dictionary<string, JsonElement> { { "artifactList", JsonSerializer.SerializeToElement(new[] { "1", "2", "3" }) } }; | ||
var profile = new ArtifactToolProfile("tool", null, options); | ||
var tool = new ProgrammableArtifactFindTool((v, k) => | ||
{ | ||
int i = int.Parse(k); | ||
if (1 <= i && i <= 3) | ||
{ | ||
return v.CreateData($"{i}"); | ||
} | ||
return null; | ||
}); | ||
await tool.InitializeAsync(profile: profile); | ||
var proxy = new ArtifactToolListProxy(tool, new ArtifactToolListOptions(), null); | ||
var results = await proxy.ListAsync().ToListAsync(); | ||
Assert.That(results.Select(v => int.Parse(v.Info.Key.Id)), Is.EquivalentTo(new[] { 1, 2, 3 })); | ||
} | ||
|
||
[Test] | ||
public async Task DumpOnlyTool_WithoutArtifactList_Success() | ||
{ | ||
var profile = new ArtifactToolProfile("tool", null, null); | ||
var tool = new AsyncProgrammableArtifactDumpTool(async v => | ||
{ | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
await v.DumpArtifactAsync(v.CreateData($"{i}")); | ||
} | ||
}); | ||
await tool.InitializeAsync(profile: profile); | ||
var proxy = new ArtifactToolListProxy(tool, new ArtifactToolListOptions(), null); | ||
var results = await proxy.ListAsync().ToListAsync(); | ||
Assert.That(results.Select(v => int.Parse(v.Info.Key.Id)), Is.EquivalentTo(new[] { 1, 2, 3 })); | ||
} | ||
|
||
[Test] | ||
public async Task DumpOnlyTool_WithArtifactList_DoesNotFilter() | ||
{ | ||
var options = new Dictionary<string, JsonElement> { { "artifactList", JsonSerializer.SerializeToElement(new[] { "1", "2" }) } }; | ||
var profile = new ArtifactToolProfile("tool", null, options); | ||
var tool = new AsyncProgrammableArtifactDumpTool(async v => | ||
{ | ||
for (int i = 1; i <= 3; i++) | ||
{ | ||
await v.DumpArtifactAsync(v.CreateData($"{i}")); | ||
} | ||
}); | ||
await tool.InitializeAsync(profile: profile); | ||
var proxy = new ArtifactToolListProxy(tool, new ArtifactToolListOptions(), null); | ||
var results = await proxy.ListAsync().ToListAsync(); | ||
Assert.That(results.Select(v => int.Parse(v.Info.Key.Id)), Is.EquivalentTo(new[] { 1, 2, 3 })); | ||
} | ||
|
||
// TODO prioritisation tests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.