Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RemoteNet committed Nov 22, 2024
1 parent 503f1ad commit 3cfbf99
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 72 deletions.
139 changes: 72 additions & 67 deletions src/RemoteNET.Tests/DynamicRemoteCharStarTests.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,93 @@
using RemoteNET;
using System.Globalization;

[TestFixture]
public class DynamicRemoteCharStarTests

namespace RemoteNET.Tests
{
[Test]
public void TestPropertyAccess()

[TestFixture]
public class DynamicRemoteCharStarTests
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestPropertyAccess()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Test property access using dynamic proxy
Assert.AreEqual(13, proxy.Length);
Assert.AreEqual("Hello", proxy.Substring(0, 5));
}
// Test property access using dynamic proxy
Assert.That(proxy.Length, Is.EqualTo(13));
Assert.That(proxy.Substring(0, 5), Is.EqualTo("Hello"));
}

[Test]
public void TestPropertyModification()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestPropertyModification()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Modify property using dynamic proxy
proxy = proxy.Replace("world", "C#");
Assert.AreEqual("Hello, C#!", proxy);
}
// Modify property using dynamic proxy
proxy = proxy.Replace("world", "C#");
Assert.That(proxy, Is.EqualTo("Hello, C#!"));
}

[Test]
public void TestMethodInvocation()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestMethodInvocation()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Invoke method using dynamic proxy
proxy = proxy.ToUpper();
Assert.AreEqual("HELLO, WORLD!", proxy);
}
// Invoke method using dynamic proxy
proxy = proxy.ToUpper();
Assert.That(proxy, Is.EqualTo("HELLO, WORLD!"));
}

[Test]
public void TestSubclassParameter()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestSubclassParameter()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Invoke ToString method with a string parameter
string formattedString = proxy.ToString(CultureInfo.InvariantCulture);
Assert.AreEqual("Hello, world!", formattedString);
// Invoke ToString method with a string parameter
string formattedString = proxy.ToString(CultureInfo.InvariantCulture);
Assert.That(formattedString, Is.EqualTo("Hello, world!"));

// Invoke ToString method with an IFormatProvider (a subclass of object) as a parameter
IFormatProvider formatProvider = CultureInfo.InvariantCulture;
string formattedStringWithProvider = proxy.ToString(formatProvider);
Assert.AreEqual("Hello, world!", formattedStringWithProvider);
}
// Invoke ToString method with an IFormatProvider (a subclass of object) as a parameter
IFormatProvider formatProvider = CultureInfo.InvariantCulture;
string formattedStringWithProvider = proxy.ToString(formatProvider);
Assert.That(formattedStringWithProvider, Is.EqualTo("Hello, world!"));
}

[Test]
public void TestImplicitConversion()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestImplicitConversion()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Implicit conversion from DynamicRemoteCharStar to string
string convertedString = proxy;
Assert.AreEqual("Hello, world!", convertedString);
}
// Implicit conversion from DynamicRemoteCharStar to string
string convertedString = proxy;
Assert.That(convertedString, Is.EqualTo("Hello, world!"));
}

[Test]
public void TestExplicitConversion()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestExplicitConversion()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Explicit conversion from DynamicRemoteCharStar to string
string convertedString = (string)proxy;
Assert.AreEqual("Hello, world!", convertedString);
}
// Explicit conversion from DynamicRemoteCharStar to string
string convertedString = (string)proxy;
Assert.That(convertedString, Is.EqualTo("Hello, world!"));
}

[Test]
public void TestToStringConversion()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);
[Test]
public void TestToStringConversion()
{
string initialString = "Hello, world!";
dynamic proxy = new DynamicRemoteCharStar(null, 0x100, initialString);

// Explicit conversion from DynamicRemoteCharStar to string
string convertedString = proxy.ToString();
Assert.AreEqual("Hello, world!", convertedString);
// Explicit conversion from DynamicRemoteCharStar to string
string convertedString = proxy.ToString();
Assert.That(convertedString, Is.EqualTo("Hello, world!"));
}
}
}
4 changes: 2 additions & 2 deletions src/RemoteNET.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void ConnectRemoteApp()
var app = RemoteAppFactory.Connect(target.Process, RuntimeType.Managed);

// Assert
Assert.IsNotNull(app);
Assert.That(app, Is.Not.Null);
app.Dispose();
}

Expand All @@ -43,7 +43,7 @@ public void CheckAlivenessRemoteApp(int sleepSeconds)
bool alive = app.Communicator.CheckAliveness();

// Assert
Assert.True(alive);
Assert.That(alive, Is.True);
var unmanAppp = RemoteAppFactory.Connect(target.Process, RuntimeType.Unmanaged);
app.Dispose();
unmanAppp.Dispose();
Expand Down
6 changes: 3 additions & 3 deletions src/RemoteNET.Tests/RttiTypesFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void AddFunctionImpl_DifferentDeclaringClassOnFunc_DifferentDeclaringType
// Assert
MethodInfo method = childType.GetMethods().Single();
string decTypeLongName = $"{method.DeclaringType.Namespace}::{method.DeclaringType.Name}";
Assert.That(childTypeLongName, Is.Not.EqualTo(decTypeLongName));
Assert.That(childTypeLongName, Is.EqualTo(decTypeLongName));
}


Expand Down Expand Up @@ -320,7 +320,7 @@ public void UndecoratingConstRef()

// Assert
var arg = args[1];
Assert.AreEqual("Peek::WClass&", arg);
Assert.That(arg, Is.EqualTo("Peek::WClass&"));
}

[Test]
Expand Down Expand Up @@ -350,7 +350,7 @@ public void UndecoratingConstRef_ParseType_NoMethod()

// Assert
// Expecting `AddFunctionImpl` to NOT add that function (not supported yet)
Assert.IsEmpty(childType.GetMethods());
Assert.That(childType.GetMethods(), Is.Empty);
}
}
}

0 comments on commit 3cfbf99

Please sign in to comment.