Skip to content

Commit

Permalink
test: add 10 test to assetmanager test
Browse files Browse the repository at this point in the history
  • Loading branch information
pabllopf committed Jan 30, 2024
1 parent 72481b2 commit 1037f4c
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 7 deletions.
Empty file.
206 changes: 201 additions & 5 deletions 6_Ideation/Data/test/Resource/AssetManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

using System;
using System.IO;
using System.Threading;
using Alis.Core.Aspect.Data.Resource;
using Xunit;

Expand Down Expand Up @@ -184,11 +183,8 @@ public void Find_EmptyAssetName_ShouldReturnEmptyString()
[Fact]
public void Find_NullAssetName_v2_ShouldThrowArgumentNullException()
{
// Arrange
string assetName = null;

// Act & Assert
Assert.Throws<ArgumentNullException>(() => AssetManager.Find(assetName));
Assert.Throws<ArgumentNullException>(() => AssetManager.Find(null));
}

/// <summary>
Expand Down Expand Up @@ -220,5 +216,205 @@ public void Find_AssetsDirectoryDoesNotExist_ShouldReturnEmptyString()
Assert.Equal(string.Empty, actualAssetPath);
}

/// <summary>
/// Tests that find white space asset name should throw argument exception
/// </summary>
[Fact]
public void Find_WhiteSpaceAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = " ";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName));
}

/// <summary>
/// Tests that find only invalid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_OnlyInvalidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = "invalid:asset:name.txt";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName));
}

/// <summary>
/// Tests that find invalid and valid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_InvalidAndValidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = "invalid:asset.txt";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName));
}

/// <summary>
/// Tests that find white space and valid chars asset name should return correct path
/// </summary>
[Fact]
public void Find_WhiteSpaceAndValidCharsAssetName_ShouldReturnCorrectPath()
{
// Arrange
string assetName = " valid asset.txt ";

// Act
string actualAssetPath = AssetManager.Find(assetName.Trim());

// Assert
Assert.Empty(actualAssetPath);
}

/// <summary>
/// Tests that find white space and invalid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_WhiteSpaceAndInvalidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = " invalid:asset.txt ";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find white space invalid and valid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_WhiteSpaceInvalidAndValidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = " invalid:asset.txt ";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find invalid chars around valid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_InvalidCharsAroundValidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = ":validasset:";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName));
}

/// <summary>
/// Tests that find white space around valid chars asset name should return correct path
/// </summary>
[Fact]
public void Find_WhiteSpaceAroundValidCharsAssetName_ShouldReturnCorrectPath()
{
// Arrange
string assetName = " validasset ";

// Act
string actualAssetPath = AssetManager.Find(assetName.Trim());

// Assert
Assert.Empty(actualAssetPath);
}

/// <summary>
/// Tests that find white space around invalid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_WhiteSpaceAroundInvalidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = " :invalidasset: ";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find white space invalid chars around valid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_WhiteSpaceInvalidCharsAroundValidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = " :validasset: ";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find invalid chars white space around valid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_InvalidCharsWhiteSpaceAroundValidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = ": validasset :";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find valid chars white space around invalid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_ValidCharsWhiteSpaceAroundInvalidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = "validasset :invalidasset: validasset";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find valid chars invalid chars around white space asset name should throw argument exception
/// </summary>
[Fact]
public void Find_ValidCharsInvalidCharsAroundWhiteSpaceAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = "validasset: :validasset";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find invalid chars valid chars around white space asset name should throw argument exception
/// </summary>
[Fact]
public void Find_InvalidCharsValidCharsAroundWhiteSpaceAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = ":validasset :validasset:";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}

/// <summary>
/// Tests that find white space valid chars around invalid chars asset name should throw argument exception
/// </summary>
[Fact]
public void Find_WhiteSpaceValidCharsAroundInvalidCharsAssetName_ShouldThrowArgumentException()
{
// Arrange
string assetName = " validasset:invalidasset:validasset ";

// Act & Assert
Assert.Throws<ArgumentException>(() => AssetManager.Find(assetName.Trim()));
}
}
}
4 changes: 2 additions & 2 deletions 6_Ideation/Thread/test/ThreadManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public void StartThread_ShouldStartNewThread()
{
while (!token.IsCancellationRequested)
{
System.Threading.Thread.Sleep(1000); // Task that sleeps for 1 second
System.Threading.Thread.Sleep(10); // Task that sleeps for 1 second
}
}, cts.Token);

// Act
threadManager.StartThread(threadTask);

//wait 1s
System.Threading.Thread.Sleep(1000);
System.Threading.Thread.Sleep(100);

// stop the thread
threadManager.StopAllThreads();
Expand Down

0 comments on commit 1037f4c

Please sign in to comment.