Skip to content

Commit

Permalink
Using Assert methods instead of FluentAssertions package, npm i on Pr…
Browse files Browse the repository at this point in the history
…ocessExplorer frontend
  • Loading branch information
lilla28 committed Apr 21, 2023
1 parent 6db36d9 commit 6785ece
Show file tree
Hide file tree
Showing 12 changed files with 27,450 additions and 19,740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -11,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../LocalCollector/LocalCollector.csproj" />
<ProjectReference Include="..\LocalCollector\LocalCollector.csproj" />
<ProjectReference Include="..\ProcessExplorer.Abstractions\ProcessExplorer.Abstractions.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System;
using System.Diagnostics;
using System.Threading;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Moq;
using ProcessExplorer.Abstractions.Handlers;
Expand All @@ -40,9 +39,9 @@ public void AddChildProcesses_will_add_child_processes_to_the_list()

var result = processMonitor.GetProcessIds().ToArray();

result.Should().NotBeEmpty();
result.Should().HaveCount(2);
result.Should().Contain(testApplication.Id);
Assert.NotEmpty(result);
Assert.Equal(2, result.Length);
Assert.Contains(testApplication.Id, result);

processMonitor.Dispose();
}
Expand All @@ -58,9 +57,9 @@ public void AddProcess_will_add_process_to_the_watchable_list()
processMonitor.AddProcess(process.Id);
var result = processMonitor.GetProcessIds().ToArray();

result.Should().NotBeEmpty();
result.Should().HaveCount(1);
result.Should().Contain(process.Id);
Assert.NotEmpty(result);
Assert.Single(result);
Assert.Contains(process.Id, result);

process.Kill();
processMonitor.Dispose();
Expand All @@ -76,7 +75,7 @@ public void CheckIfIsComposeProcess_will_check_if_it_is_contained_by_the_list_an

var result = processMonitor.CheckIfIsComposeProcess(process.Id);

result.Should().BeTrue();
Assert.True(result);

process.Kill();
processMonitor.Dispose();
Expand All @@ -90,7 +89,7 @@ public void CheckIfIsComposeProcess_will_check_if_it_is_contained_by_the_list_an
var process = Process.Start(GetSimpleTestApplicationPath());
var result = processMonitor.CheckIfIsComposeProcess(process.Id);

result.Should().BeFalse();
Assert.False(result);

process.Kill();
processMonitor.Dispose();
Expand All @@ -107,7 +106,7 @@ public void ClearProcessIds_will_remove_all_the_elements()
processMonitor.ClearProcessIds();
var result = processMonitor.GetProcessIds().ToArray();

result.Should().BeEmpty();
Assert.Empty(result);

process.Kill();
processMonitor.Dispose();
Expand All @@ -124,7 +123,8 @@ public void GetCpuUsage_will_return_with_some_value()
process.Id,
process.ProcessName);

cpuUsageResult.Should().BeGreaterThanOrEqualTo(0);
Assert.True(cpuUsageResult >= 0);

process.Kill();
processMonitor.Dispose();
}
Expand All @@ -139,7 +139,8 @@ public void GetMemoryUsage_will_return_with_some_value()
Environment.ProcessId,
Process.GetProcessById(Environment.ProcessId).ProcessName);

memoryUsageResult.Should().BeGreaterThan(0);
Assert.True(memoryUsageResult > 0);

processMonitor.Dispose();
}

Expand All @@ -154,8 +155,8 @@ public void GetParentId_will_return_the_parent_id_of_the_process()
//Expected parentid should be the current process id, as we are starting this process from the code.
var parentId = processMonitor.GetParentId(process.Id, process.ProcessName);

parentId.Should().NotBeNull();
parentId.Should().Be(Process.GetCurrentProcess().Id);
Assert.NotNull(parentId);
Assert.Equal(Process.GetCurrentProcess().Id, parentId);

process.Kill();
processMonitor.Dispose();
Expand All @@ -170,7 +171,7 @@ public void GetParentId_will_return_null()
//Expected parentid should be the current process id, as we are starting this process from the code.
var parentId = processMonitor.GetParentId(666666, string.Empty);

parentId.Should().BeNull();
Assert.Null(parentId);

processMonitor.Dispose();
}
Expand All @@ -191,8 +192,8 @@ public void SetProcessIds_will_set_the_ids_and_its_child_process_ids()

var result = processMonitor.GetProcessIds().ToArray();

result.Should().Contain(processes);
result.Should().HaveCount(3);
Assert.NotStrictEqual(processes, result);
Assert.Equal(3, result.Length);

processMonitor.Dispose();
}
Expand Down Expand Up @@ -221,7 +222,8 @@ public void WatchProcesses_will_begin_to_watch_all_the_processes_in_windows()

var result = processMonitor.GetProcessIds().ToArray();

result.Should().HaveCountGreaterOrEqualTo(3);
Assert.True(result.Length >= 3);

createdProcessActionMock.Verify(x => x.Invoke(It.IsAny<int>()), Times.AtLeast(3));

processMonitor.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Moq;
using ProcessExplorer.Abstractions.Infrastructure;
Expand Down Expand Up @@ -179,7 +178,7 @@ public async Task LaunchSubsystemAutomatically_will_use_subsystemLauncher_to_lau

await subsystemController.LaunchSubsystemAutomatically(subsystem.Key);

subsystem.Value.AutomatedStart.Should().BeTrue();
Assert.True(subsystem.Value.AutomatedStart);

subsystemLauncherMock.Verify(x => x.LaunchSubsystem(It.IsAny<Guid>(), It.IsAny<string>()));
}
Expand All @@ -203,7 +202,7 @@ public async Task LaunchSubsystemAutomatically_will_use_subsystemCommunicator_to

await subsystemController.LaunchSubsystemAutomatically(subsystem.Key);

subsystem.Value.AutomatedStart.Should().BeTrue();
Assert.True(subsystem.Value.AutomatedStart);

subsystemLauncherCommunicatorMock.Verify(x => x.SendLaunchSubsystemsRequest(It.IsAny<Dictionary<Guid, string>>()), Times.Exactly(2));
}
Expand Down Expand Up @@ -614,7 +613,8 @@ public async Task ModifySubsystemState_will_modify_the_state_and_trigger_UI_upda

await subsystemController.ModifySubsystemState(subsystem.Key, "DummyState");

subsystem.Value.State.Should().Be("DummyState");
Assert.Equal("DummyState", subsystem.Value.State);

uiDelegateMock.Verify(x => x.Invoke(It.IsAny<Func<IUiHandler, Task>>()), Times.Exactly(2)); // due IUiHandler function will be called twice as per after initialization of the subsystems we are pushing data to the uis.
}

Expand Down Expand Up @@ -661,8 +661,8 @@ public async Task AddSubsystems_will_add_elements_and_update_to_the_ui(IEnumerab
await subsystemController.AddSubsystems(newElements);

var result = subsystemController.GetSubsystems();
result.Should().Contain(subsystems);
result.Should().Contain(newElements);
Assert.NotStrictEqual(subsystems, result);
Assert.NotStrictEqual(newElements, result);

uiDelegateMock.Verify(x => x.Invoke(It.IsAny<Func<IUiHandler, Task>>()), Times.Exactly(2));
}
Expand All @@ -685,11 +685,11 @@ public async Task RemoveSubsystem_will_remove_element_without_triggering_shutdow
var subsystemtoDelete =
subsystems.First(x => x.Value.State == SubsystemState.Stopped && !x.Value.AutomatedStart);

subsystemController.RemoveSubsystem(subsystemtoDelete.Key);
await subsystemController.RemoveSubsystem(subsystemtoDelete.Key);

var result = subsystemController.GetSubsystems();

result.Should().NotContain(subsystemtoDelete);
Assert.DoesNotContain(subsystemtoDelete, result);

subsystemLauncherMock.Verify(x => x.ShutdownSubsystem(It.IsAny<Guid>(), It.IsAny<string>()), Times.Never);
}
Expand All @@ -712,11 +712,11 @@ public async Task RemoveSubsystem_will_remove_element_wit_triggering_shutdown(IE
var subsystemtoDelete =
subsystems.First(x => x.Value.State == SubsystemState.Started);

subsystemController.RemoveSubsystem(subsystemtoDelete.Key);
await subsystemController.RemoveSubsystem(subsystemtoDelete.Key);

var result = subsystemController.GetSubsystems();

result.Should().NotContain(subsystemtoDelete);
Assert.DoesNotContain(subsystemtoDelete, result);

subsystemLauncherMock.Verify(x => x.ShutdownSubsystem(It.IsAny<Guid>(), It.IsAny<string>()), Times.Once);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Moq;
using ProcessExplorer.Abstractions.Subsystems;
Expand Down Expand Up @@ -45,7 +44,7 @@ public async Task LaunchSubsystem_will_invoke_dummy_launch_request(TestInformati
var result = await subsystemLauncher.LaunchSubsystem(testInformation.LaunchRequestId, testInformation.LaunchRequestSubsystemName);

// Assert
result.Should().Be(testInformation.ExpectedLaunchStateResult);
Assert.Equal(testInformation.ExpectedLaunchStateResult, result);

var element = testInformation.Subsystems.FirstOrDefault(x => x.Key == testInformation.LaunchRequestId);

Expand Down Expand Up @@ -77,7 +76,7 @@ public async Task LauchSubsystem_will_return_stopped_when_no_launchType_added(Te
var result = await subsystemLauncher.LaunchSubsystem(testInformation.LaunchRequestId, testInformation.LaunchRequestSubsystemName);

//Assert
result.Should().Be(SubsystemState.Stopped); //That is the default value
Assert.Equal(SubsystemState.Stopped, result); //That is the default value
}

[Theory]
Expand All @@ -97,7 +96,7 @@ public async Task LaunchSubsystemAfterTime_will_wait_before_launching_a_subsyste
stopwatch.Stop();

// Assert
stopwatch.ElapsedMilliseconds.Should().BeGreaterThanOrEqualTo(periodOfTime);
Assert.True(stopwatch.ElapsedMilliseconds >= periodOfTime);
}

[Theory]
Expand All @@ -118,7 +117,7 @@ public async Task LaunchSubsystems_will_launch_subsystems(TestInformation testIn
var result = await subsystemLauncher.LaunchSubsystems(testInformation.LaunchRequestIds);

// Assert
result.Should().BeEquivalentTo(testInformation.ExpectedLaunchStateResults);
Assert.Equal(testInformation.ExpectedLaunchStateResults, result);

launchRequestMock.Verify(x => x.Invoke(It.IsAny<DummyStartType>()), Times.Exactly(testInformation.ExpectedLaunchStateResults.Count()));
}
Expand Down Expand Up @@ -149,7 +148,8 @@ public async Task ShutdownSubsytem_will_trigger_the_shutdown_command(TestInforma
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
Times.Once);
result.Should().Be(SubsystemState.Stopped);

Assert.Equal(SubsystemState.Stopped, result);
}

[Theory]
Expand All @@ -174,7 +174,8 @@ public async Task ShutdownSubsytem_will_return_running_state_if_no_stop_request_
It.IsAny<Exception>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
Times.Once);
result.Should().Be(SubsystemState.Running);

Assert.Equal(SubsystemState.Running, result);
}

[Theory]
Expand All @@ -195,7 +196,7 @@ public async Task StopSubsystems_will_trigger_stop_request(TestInformation testI
var result = await subsystemLauncher.ShutdownSubsystems(testInformation.StopRequestIds);

// Assert
result.Should().BeEquivalentTo(testInformation.ExpectedStopStateResults);
Assert.Equal(testInformation.ExpectedStopStateResults, result);

stopRequestMock.Verify(x => x.Invoke(It.IsAny<DummyStopType>()), Times.Exactly(testInformation.ExpectedStopStateResults.Count()));
}
Expand Down Expand Up @@ -235,7 +236,7 @@ public async Task RestartSubsystem_will_return_started_state_and_trigger_launch_

launchRequestMock.Verify(x => x.Invoke(It.IsAny<DummyStartType>()), Times.Once);

result.Should().Be(SubsystemState.Started);
Assert.Equal(SubsystemState.Started, result);
}

[Theory]
Expand Down Expand Up @@ -277,7 +278,7 @@ public async Task RestartSubsystem_will_log_subsystem_stop_debugerror_if_no_stop

launchRequestMock.Verify(x => x.Invoke(It.IsAny<DummyStartType>()), Times.Never);

result.Should().Be(SubsystemState.Running);
Assert.Equal(SubsystemState.Running, result);
}

[Theory]
Expand Down Expand Up @@ -318,7 +319,7 @@ public async Task RestartSubsytem_will_log_subsystem_restart_error_if_no_launch_

stopRequestMock.Verify(x => x.Invoke(It.IsAny<DummyStopType>()), Times.Once);

result.Should().Be(SubsystemState.Stopped);
Assert.Equal(SubsystemState.Stopped, result);
}

[Theory]
Expand Down
Loading

0 comments on commit 6785ece

Please sign in to comment.