I am working on unit testing using visual studio unit test framework
In my unit test method, I want to assert if the result is a Guid like
3C99A192-9844-4174-AC32-91976A5F2CBF
.
Currently, I have come up with this. But I am sure there will be a better way to handle this.
[TestMethod]
public void CreateAppointment_Should_Return_Guid()
{
string result = CreateAppointment();
Guid guidResult;
if (Guid.TryParse(result.GuestId, guidResult))
{
Assert.IsTrue(true);
}
else
{
Assert.IsTrue(false);
}
}
Why not shorter one? TryParse
returns bool.
Guid guidResult;
Assert.IsTrue(Guid.TryParse(result.GuestId, out guidResult));
your idea seems to be legit. You are checking if string parses to guid, so you can tell if string is valid guid.
This might help: Assert.IsInstanceOfType(CreateAppointment(), typeof(Guid));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With