Skip to content

Commit

Permalink
Merge pull request #99 from doodz/Develop
Browse files Browse the repository at this point in the history
[MMS] : Doods : add TU
  • Loading branch information
doodz authored May 5, 2021
2 parents b9743de + fd191f0 commit 28a4f0c
Show file tree
Hide file tree
Showing 68 changed files with 5,896 additions and 7,613 deletions.
254 changes: 254 additions & 0 deletions Doods.Openmediavault.TU/Clients/OmvSystemClientUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Doods.Openmediavault.Mobile.Std.Enums;
using Doods.Openmediavault.Rpc.Std;
using Doods.Openmediavault.Rpc.Std.Clients;
using Doods.Openmediavault.Rpc.std.Data.V4;
using Doods.Openmediavault.Rpc.std.Data.V4.Settings;
using Doods.Openmediavault.Rpc.std.Data.V5;
using Doods.Openmediavault.Rpc.Std.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Doods.Openmediavault.TU.Clients
{
[TestClass]
public class OMVVersionsUnitTest
{
[DataTestMethod]
[DataRow("NotFound")]
[DataRow("Ix")]
[DataRow("Omnius")]
[DataRow("Fedaykin")]
[DataRow("Sardaukar")]
[DataRow("Kralizec")]
[DataRow("Stone burner")]
[DataRow("Erasmus")]
[DataRow("Arrakis")]
[DataRow("Usul")]
public void Create(string version)
{
var v = OMVVersions.GetVersionFromString(version);
Assert.IsNotNull(v);
Assert.AreEqual(version, v.Name);
}

[TestMethod]
public void NotFound()
{
var v = OMVVersions.GetVersionFromString("version");
Assert.IsNotNull(v);
Assert.AreEqual("NotFound", v.Name);
}

[TestMethod]
public void Version4lowerThan5()
{
var b = (OMVVersions.Version4 < OMVVersions.Version5);
Assert.IsTrue(b);
}
[TestMethod]
public void Version4UpperThan2()
{

var b = (OMVVersions.Version4 > OMVVersions.Version2);
Assert.IsTrue(b);
}
}


[TestClass]
public class OmvSystemClientUnitTest
{
[TestMethod]
public void Create()
{
var rpcClient = new Mock<IRpcClient>();
var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
}
[TestMethod]
public async Task GetTimeZoneList()
{
var rpcClient = new Mock<IRpcClient>();
//rpcClient.Setup(c => c.ExecuteTaskAsync<It.IsAnyType>()).ReturnsAsync(()=>default);
var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
var result = await obj.GetTimeZoneList();
Assert.IsNotNull(result);
Assert.AreEqual(0,result.Count());
}

[TestMethod]
public async Task GetTimeZoneList2()
{
var rpcClient = new Mock<IRpcClient>();
rpcClient.Setup(c => c.ExecuteTaskAsync<IEnumerable<string>>(It.IsAny<IRpcRequest>()))
.ReturnsAsync(new List<string>(){"foo","bar"});
var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
var result = await obj.GetTimeZoneList();
Assert.IsNotNull(result);
Assert.AreEqual(2, result.Count());
}

[TestMethod]
public async Task GetDateAndTimeSetting()
{
var rpcClient = new Mock<IRpcClient>();
rpcClient.Setup(c => c.ExecuteTaskAsync<TimeSetting>(It.IsAny<IRpcRequest>()))
.ReturnsAsync(new TimeSetting());
var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
var result = await obj.GetDateAndTimeSetting();
Assert.IsNotNull(result);
}

[TestMethod]
public async Task SetDateAndTimeSetting()
{
var rpcClient = new Mock<IRpcClient>();
var settings = new TimeSetting();
rpcClient.Setup(c => c.ExecuteTaskAsync<object>(It.IsAny<IRpcRequest>()))
.ReturnsAsync(new object());
var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
var result = await obj.SetDateAndTimeSetting(settings);
Assert.IsNotNull(result);
}
[TestMethod]
public async Task GetSystemInformationsV4()
{
var rpcClient = new Mock<IRpcClient>();
var slt = new List<SystemInformation>();

var info = new SystemInformation();
info.Name = "ts";
info.Value = (ValueUnion)"1000";
slt.Add(info);

info = new SystemInformation();
info.Name = "System time";
info.Value = (ValueUnion)"System_time_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "Hostname";
info.Value = (ValueUnion)"Hostname_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "Version";
info.Value = (ValueUnion)"Version_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "Processor";
info.Value = (ValueUnion)"Processor_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "MemTotal";
info.Value = (ValueUnion)"2000";
slt.Add(info);

info = new SystemInformation();
info.Name = "Kernel";
info.Value = (ValueUnion)"Kernel_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "Uptime";
info.Value = (ValueUnion)"Uptime_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "Load average";
info.Value = (ValueUnion)"Load_average_string";
slt.Add(info);

info = new SystemInformation();
info.Name = "configDirty";
info.Value = (ValueUnion)"true";
slt.Add(info);

info = new SystemInformation();
info.Name = "rebootRequired";
info.Value = (ValueUnion)"false";
slt.Add(info);

info = new SystemInformation();
info.Name = "pkgUpdatesAvailable";
info.Value = (ValueUnion)"true";
slt.Add(info);


//rpcClient.Setup(c => c.ExecuteTaskAsync<IEnumerable<SystemInformation>>(It.IsAny<IRpcRequest>()))
// .ReturnsAsync(slt);
//rpcClient.Setup(c => c.ExecuteTaskAsync<IEnumerable<SystemInformation>>(It.IsAny<IRpcRequest>()))
// .ReturnsAsync(slt);
rpcClient.Setup(c => c.ExecuteTaskAsync<object>(It.Is<IRpcRequest>(t => t.Method == "getInformation")))
.ReturnsAsync("Arrakis");
rpcClient.Setup(c => c.ExecuteTaskAsync<IEnumerable<SystemInformation>> (It.IsAny<IRpcRequest>()))
.ReturnsAsync(slt);



//rpcClient.Setup(c => c.ExecuteTaskAsync<object>(It.Is<IRpcRequest>(t => t.Method == "getInformation")))
// .ReturnsAsync("Arrakis");

var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
obj.SetOMVVersion(OMVVersions.Version4);
var result = await obj.GetSystemInformations();
Assert.IsNotNull(result);
}


[TestMethod]
public async Task GetSystemInformationsV5()
{
var rpcClient = new Mock<IRpcClient>();

//rpcClient.Setup(c => c.ExecuteTaskAsync<object>(It.Is<IRpcRequest>(t => t.Method == "getInformation")))
// .ReturnsAsync("Usul");

//rpcClient.SetupSequence(c => c.ExecuteTaskAsync<object>(It.IsAny<IRpcRequest>()))
// .ReturnsAsync("Usul")
// .ReturnsAsync(new OMVInformations());


// rpcClient.Setup(c => c.ExecuteTaskAsync<It.IsSubtype<OMVInformations>(It.Is<IRpcRequest>(t => t.Method == "getInformation")))
// .ReturnsAsync("Usul");

rpcClient.Setup(c => c.ExecuteTaskAsync<object>(It.Is<IRpcRequest>(t => t.Method == "getInformation")))
.ReturnsAsync("Usul");
rpcClient.Setup(c => c.ExecuteTaskAsync<OMVInformations>(It.Is<IRpcRequest>(t => t.Method == "getInformation")))
.ReturnsAsync(new OMVInformations());
var obj = new OmvSystemClient(rpcClient.Object);
Assert.IsNotNull(obj);
obj.SetOMVVersion(OMVVersions.Version5);
var result = await obj.GetSystemInformations();
Assert.IsNotNull(result);
}


//case "CPU usage":
// obj.CpuUsage = information.Value.ValueClass.Value;
// break;
//case "":
// obj.MemTotal = long.Parse(information.Value.SimpleStringValue);
// break;
//case "Memory usage":
// obj.MemUsed = long.Parse(information.Value.ValueClass.Value.ToString());
// break;




}
}
19 changes: 19 additions & 0 deletions Doods.Openmediavault.TU/Data/V4/IsRunningUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Doods.Openmediavault.Rpc.std.Data.V4;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Doods.Openmediavault.TU.Data.V5
{
[TestClass]
public class IsRunningUnitTest
{
[TestMethod]
public void Create()
{
var obj = new IsRunning();
Assert.IsNotNull(obj);
Assert.IsFalse(obj.Running);

Assert.IsNull(obj.Filename);
}
}
}
40 changes: 40 additions & 0 deletions Doods.Openmediavault.TU/Data/V5/OMVInformationsUnitTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Text;
using Doods.Openmediavault.Rpc.std.Data.V5;
using System.Collections.Generic;
using System.Linq;
using Doods.Framework.Ssh.Std.Requests;
using Doods.Framework.Ssh.Std.Serializers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NuGet.Frameworks;

namespace Doods.Openmediavault.TU.Data.V5
{
[TestClass]
public class OMVInformationsUnitTest
{
[TestMethod]
public void Create()
{
var obj = new OMVInformations();
Assert.IsNotNull(obj);
Assert.IsFalse(obj.LegacyMode);
Assert.AreEqual(default(long),obj.Ts);
Assert.IsNull(obj.Time);
Assert.IsNull(obj.Hostname);
Assert.IsNull(obj.Version);
Assert.IsNull(obj.CpuModelName);
Assert.AreEqual(default(double), obj.CpuUsage);
Assert.AreEqual(default(long), obj.MemTotal);
Assert.AreEqual(default(long), obj.MemUsed);
Assert.IsNull(obj.Kernel);
Assert.IsNull(obj.Uptime);
Assert.IsNull(obj.LoadAverage);
Assert.IsFalse(obj.ConfigDirty);
Assert.IsFalse(obj.RebootRequired);
Assert.IsFalse(obj.PkgUpdatesAvailable);
}
}
}
27 changes: 27 additions & 0 deletions Doods.Openmediavault.TU/Doods.Openmediavault.TU.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Doods.Openmedivault\Doods.Openmediavault.Mobile.Std\Doods.Openmediavault.Mobile.Std.csproj" />
<ProjectReference Include="..\Doods.Openmedivault\Doods.Openmediavault.Rpc.std\Doods.Openmediavault.Rpc.Std.csproj" />
<ProjectReference Include="..\Doods.Openmedivault\Doods.Openmedivault.Http.Std\Doods.Openmedivault.Http.Std.csproj" />
<ProjectReference Include="..\Doods.Openmedivault\Doods.Openmedivault.Ssh.Std\Doods.Openmedivault.Ssh.Std.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SSH.NET" Version="2020.0.1" />
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RestSharp" Version="106.11.7" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public sealed class OMVVersions
public static OMVVersion Version4 = new OMVVersion("4.0", "Arrakis");
public static OMVVersion Version5 = new OMVVersion("5.0", "Usul");


/// <summary>
/// Get Version object from string who contain version name
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.1.0" />
<PackageReference Include="Autofac" Version="6.2.0" />
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ namespace Doods.Openmedivault.Ssh.Std.Requests
public interface IJsonSerializer : /*ISerializer, */IDeserializer
{
}


}
Loading

0 comments on commit 28a4f0c

Please sign in to comment.