Skip to content

Commit

Permalink
Refactor GetVersion() into a property
Browse files Browse the repository at this point in the history
  • Loading branch information
falox committed Nov 23, 2020
1 parent dcb1fb4 commit 69406e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/libvirt/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Open(bool readOnly = false)
{
if (IsDisposed)
{
throw new ObjectDisposedException(null, "Cannot open a disposed Connect.");
throw new ObjectDisposedException("Connect", "Cannot open a disposed connection.");
}

if (readOnly)
Expand Down
16 changes: 9 additions & 7 deletions src/libvirt/Libvirt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllI

public const int VIR_UUID_BUFLEN = 36;

public static Version GetVersion()
public static Version Version
{
LibvirtHelper.ThrowExceptionOnError(virGetVersion(out ulong libVer, null, out _));

int release = (int) (libVer % 1000);
int minor = (int) ((libVer % 1000000) / 1000);
int major = (int) (libVer / 1000000);
get
{
LibvirtHelper.ThrowExceptionOnError(virGetVersion(out ulong libVer, null, out _));

return new Version(major, minor, release);
int release = (int) (libVer % 1000);
int minor = (int) ((libVer % 1000000) / 1000);
int major = (int) (libVer / 1000000);

return new Version(major, minor, release);
}
}

#region Library
Expand Down
2 changes: 1 addition & 1 deletion src/libvirt/libvirt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>libvirt-csharp</AssemblyName>
<Version>0.0.1-alpha1</Version>
<Version>0.0.1-alpha2</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>libvirt-csharp.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
6 changes: 5 additions & 1 deletion tests/libvirt.Tests/LibraryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ public class LibraryTests
[Fact]
public void GetVersion_ReturnVersion()
{
Libvirt.GetVersion();
// Act
var version = Libvirt.Version;

// Assert
Assert.True(version > new System.Version(0,0,1));
}
}
}

0 comments on commit 69406e8

Please sign in to comment.