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
55 changes: 26 additions & 29 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
<Using Include="Xunit"/>
<Using Include="Shouldly"/>
</ItemGroup>

<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
<PackageReference Include="NSubstitute" />
<PackageReference Include="Shouldly" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
<Using Include="Xunit" />
<Using Include="Shouldly" />
</ItemGroup>
<ItemGroup Condition="'$(ProjectName.ToLower().Contains(`test`))' == 'true'">
<PackageReference Include="NSubstitute" />
<PackageReference Include="Shouldly" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<PackageVersion Include="Shouldly" Version="4.3.0"/>
<PackageVersion Include="coverlet.collector" Version="6.0.4"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
<PackageVersion Include="xunit" Version="2.9.3"/>
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2">
<PackageVersion Include="xunit.v3" Version="2.0.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using ScriptBee.Domain.Model.Instance;
using ScriptBee.Domain.Model.Project;
using ScriptBee.Tests.Common;
using Xunit.Abstractions;

namespace ScriptBee.Analysis.Instance.Docker.Tests;

Expand Down Expand Up @@ -53,12 +52,17 @@ public async Task Allocate_ShouldCreateAndStartContainerAndReturnUrlWithNetworkI
var instanceId = new InstanceId(Guid.NewGuid());
var image = new AnalysisInstanceImage(DockerFixture.TestImageName);

var containerUrl = await _calculationInstanceDockerAdapter.Allocate(instanceId, image);
var containerUrl = await _calculationInstanceDockerAdapter.Allocate(
instanceId,
image,
TestContext.Current.CancellationToken
);

containerUrl.ShouldStartWith("http://");
containerUrl.ShouldContain($":{_testPort}");
var containers = await _dockerFixture.DockerClient.Containers.ListContainersAsync(
new ContainersListParameters { All = true }
new ContainersListParameters { All = true },
TestContext.Current.CancellationToken
);
var ourContainer = containers.FirstOrDefault(c =>
c.Names.Contains($"/scriptbee-calculation-{instanceId}")
Expand All @@ -80,7 +84,11 @@ public async Task Allocate_ShouldUseConfiguredNetworkAndContainerName()
var instanceId = new InstanceId(Guid.NewGuid());
var image = new AnalysisInstanceImage(DockerFixture.TestImageName);

await _calculationInstanceDockerAdapter.Allocate(instanceId, image);
await _calculationInstanceDockerAdapter.Allocate(
instanceId,
image,
TestContext.Current.CancellationToken
);

var containers = await _dockerFixture.DockerClient.Containers.ListContainersAsync(
new ContainersListParameters
Expand All @@ -96,7 +104,8 @@ public async Task Allocate_ShouldUseConfiguredNetworkAndContainerName()
}
},
},
}
},
TestContext.Current.CancellationToken
);
containers.ShouldHaveSingleItem();
containers.First().Names.ShouldContain($"/scriptbee-calculation-{instanceId}");
Expand All @@ -113,7 +122,8 @@ public async Task Deallocate_ShouldStopAndRemoveExistingContainer()

var instanceUrl = await _calculationInstanceDockerAdapter.Allocate(
instanceId,
instanceImage
instanceImage,
TestContext.Current.CancellationToken
);
instanceUrl.ShouldStartWith("http://");
var instanceInfo = new InstanceInfo(
Expand All @@ -138,7 +148,8 @@ public async Task Deallocate_ShouldStopAndRemoveExistingContainer()
new Dictionary<string, bool> { { containerName, true } }
},
},
}
},
TestContext.Current.CancellationToken
);
containers.ShouldBeEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ public class DockerFixture : IAsyncLifetime

public readonly DockerClient DockerClient = new DockerClientConfiguration().CreateClient();

public async Task InitializeAsync()
public async ValueTask InitializeAsync()
{
await EnsureNetworkExists();

await PullTestImageIfNotExists();
}

public async Task DisposeAsync()
public async ValueTask DisposeAsync()
{
var containers = await DockerClient.Containers.ListContainersAsync(
new ContainersListParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ public async Task CreateFileSuccessfully()
.GetPathToUserFolder(pathToFileInSrcFolder)
.Returns("path/to/user/folder/file.txt");

var result = await _createFileAdapter.Create(projectId, pathToFileTxt, "content");
var result = await _createFileAdapter.Create(
projectId,
pathToFileTxt,
"content",
TestContext.Current.CancellationToken
);

result.AsT0.ShouldBe(
new CreateFileResult("file.txt", pathToFileTxt, "path/to/user/folder/file.txt")
);
(await System.IO.File.ReadAllTextAsync(pathToFileInSrcFolder)).ShouldBe("content");
(
await System.IO.File.ReadAllTextAsync(
pathToFileInSrcFolder,
TestContext.Current.CancellationToken
)
).ShouldBe("content");
}

[Fact]
Expand All @@ -57,9 +67,18 @@ public async Task CreateFileAlreadyExists()
_configFoldersService
.GetPathToSrcFolder(projectId, pathToFileTxt)
.Returns(pathToFileInSrcFolder);
await System.IO.File.WriteAllTextAsync(pathToFileInSrcFolder, "test");
await System.IO.File.WriteAllTextAsync(
pathToFileInSrcFolder,
"test",
TestContext.Current.CancellationToken
);

var result = await _createFileAdapter.Create(projectId, pathToFileTxt, "content");
var result = await _createFileAdapter.Create(
projectId,
pathToFileTxt,
"content",
TestContext.Current.CancellationToken
);

result.AsT1.ShouldBe(new FileAlreadyExistsError(pathToFileTxt));
}
Expand Down
38 changes: 0 additions & 38 deletions test/Adapters/Driven/Persistence.File.Tests/FilePathAttribute.cs

This file was deleted.

18 changes: 15 additions & 3 deletions test/Adapters/Driven/Persistence.File.Tests/LoadFileAdapterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,17 @@ public async Task GetContentSuccessfully()
_configFoldersService
.GetPathToSrcFolder(projectId, pathToFileTxt)
.Returns(pathToFileInSrcFolder);
await System.IO.File.WriteAllTextAsync(pathToFileInSrcFolder, "content");
await System.IO.File.WriteAllTextAsync(
pathToFileInSrcFolder,
"content",
TestContext.Current.CancellationToken
);

var result = await _loadFileAdapter.GetScriptContent(projectId, pathToFileTxt);
var result = await _loadFileAdapter.GetScriptContent(
projectId,
pathToFileTxt,
TestContext.Current.CancellationToken
);

result.AsT0.ShouldBe("content");
}
Expand All @@ -53,7 +61,11 @@ public async Task GivenFileDoesNotExists_GetContent_ThenFileDoesNotExistsErrorIs
.GetPathToSrcFolder(projectId, pathToFileTxt)
.Returns(pathToFileInSrcFolder);

var result = await _loadFileAdapter.GetScriptContent(projectId, pathToFileTxt);
var result = await _loadFileAdapter.GetScriptContent(
projectId,
pathToFileTxt,
TestContext.Current.CancellationToken
);

result.AsT1.ShouldBe(new FileDoesNotExistsError(pathToFileTxt));
}
Expand Down
Loading
Loading