Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinerius committed Mar 20, 2024
1 parent 7bf7eda commit adac35c
Showing 1 changed file with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,27 @@ private void ThrowIfExitCodeIsNotZero(int exitCode)
if (exitCode != 0) throw new Exception("Exit code " + exitCode);
}

private static DCL.ABConverter.AssetBundleConverter.ConversionParams GetParams(ContentServerUtils.MappingPair mappingPair) =>
new () {rawContents = new[] { mappingPair} , entityType = "scene"} ;

[Test]
public async Task LoadVisualSceneOnStart()
{
await converter.ConvertAsync(new DCL.ABConverter.AssetBundleConverter.ConversionParams());
var exampleAsset = new ContentServerUtils.MappingPair { file = "example.png", hash = "example" };
BaseSetup(exampleAsset, out string _, out string _);

await converter.ConvertAsync(GetParams(exampleAsset));

await editor.Received().LoadVisualTestSceneAsync();
}

[Test]
public async Task InitializeDirectories()
{
await converter.ConvertAsync(new DCL.ABConverter.AssetBundleConverter.ConversionParams());
var exampleAsset = new ContentServerUtils.MappingPair { file = "example.png", hash = "example" };
BaseSetup(exampleAsset, out string _, out string _);

await converter.ConvertAsync(GetParams(exampleAsset));

directory.Received(1).InitializeDirectory(Arg.Is(EXAMPLE_AB_PATH), Arg.Any<bool>());
}
Expand All @@ -102,17 +111,9 @@ public async Task InitializeDirectories()
public async Task TextureAssetIsProcessed()
{
var exampleAsset = new ContentServerUtils.MappingPair { file = "example.png", hash = "example" };
var assetPath = new AssetPath(Config.GetDownloadPath(), exampleAsset);

string directoryName = Path.GetDirectoryName(assetPath.finalPath);
string exampleBaseURL = EXAMPLE_BASE_URL + exampleAsset.hash;

directory.Exists(directoryName).Returns(false);
webRequest.Get(exampleBaseURL).Returns(new DownloadHandlerMock());
var manifest = Substitute.For<IAssetBundleManifest>();
buildPipeline.BuildAssetBundles(Arg.Any<string>(), Arg.Any<BuildAssetBundleOptions>(), Arg.Any<BuildTarget>()).Returns(manifest);
AssetPath assetPath = BaseSetup(exampleAsset, out string directoryName, out string exampleBaseURL);

await converter.ConvertAsync(new DCL.ABConverter.AssetBundleConverter.ConversionParams());
await converter.ConvertAsync(GetParams(exampleAsset));

// Ensure that web request is done
webRequest.Received().Get(Arg.Is(exampleBaseURL));
Expand All @@ -136,6 +137,20 @@ public async Task TextureAssetIsProcessed()
await editor.Received().TestConvertedAssetsAsync(Arg.Any<Environment>(), Arg.Any<ClientSettings>(), Arg.Any<List<AssetPath>>(), Arg.Any<IErrorReporter>());
}

private AssetPath BaseSetup(ContentServerUtils.MappingPair exampleAsset, out string directoryName, out string exampleBaseURL)
{
var assetPath = new AssetPath(Config.GetDownloadPath(), exampleAsset);

directoryName = Path.GetDirectoryName(assetPath.finalPath);
exampleBaseURL = EXAMPLE_BASE_URL + exampleAsset.hash;

directory.Exists(directoryName).Returns(false);
webRequest.Get(exampleBaseURL).Returns(new DownloadHandlerMock());
var manifest = Substitute.For<IAssetBundleManifest>();
buildPipeline.BuildAssetBundles(Arg.Any<string>(), Arg.Any<BuildAssetBundleOptions>(), Arg.Any<BuildTarget>()).Returns(manifest);
return assetPath;
}

[Test]
public async Task GltfAssetIsProcessed()
{
Expand All @@ -159,7 +174,7 @@ public async Task GltfAssetIsProcessed()
gltf.TextureCount.Returns(0);
gltf.MaterialCount.Returns(0);

await converter.ConvertAsync(new DCL.ABConverter.AssetBundleConverter.ConversionParams());
await converter.ConvertAsync(GetParams(exampleAsset));

// Ensure that web request is done
webRequest.Received().Get(Arg.Is(exampleBaseURL));
Expand Down Expand Up @@ -206,7 +221,7 @@ public async Task TextureIsExtractedFromGltf()
exampleTexture.name = textureName;
gltf.GetTexture(0).Returns(exampleTexture);

await converter.ConvertAsync(new DCL.ABConverter.AssetBundleConverter.ConversionParams());
await converter.ConvertAsync(GetParams(exampleAsset));

var texturePath = $"{DOWNLOAD_FOLDER}{hash}{separator}Textures{separator}{textureName}.png";

Expand Down Expand Up @@ -250,7 +265,7 @@ public async Task MaterialIsExtractedFromGltf()
// Ensure that a when the material asset is created, the new instance of the material is a copy
assetDatabase.When(ad => ad.CreateAsset(Arg.Any<Material>(), Arg.Any<string>())).Do(c => Assert.AreNotEqual(c.Arg<Material>(), material));

await converter.ConvertAsync(new DCL.ABConverter.AssetBundleConverter.ConversionParams());
await converter.ConvertAsync(GetParams(exampleAsset));

// Ensure that a material asset is created and the texture is set for this material
assetDatabase.Received(1).CreateAsset(Arg.Is<Material>(m => m.GetTexture("_BaseMap")), Arg.Any<string>());
Expand Down

0 comments on commit adac35c

Please sign in to comment.