-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unittests for ViewServiceContainer class
- Loading branch information
1 parent
386460a
commit 8922ed5
Showing
4 changed files
with
144 additions
and
9 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
MessageCommunicator.TestGui.Tests/MessageCommunicator.TestGui.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<LangVersion>8.0</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FakeItEasy" Version="6.2.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" /> | ||
<PackageReference Include="coverlet.collector" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\MessageCommunicator\MessageCommunicator.csproj" /> | ||
<ProjectReference Include="..\MessageCommunicator.TestGui\MessageCommunicator.TestGui.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
98 changes: 98 additions & 0 deletions
98
MessageCommunicator.TestGui.Tests/ViewServiceContainerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reactive.Disposables; | ||
using System.Text; | ||
using Avalonia.Controls; | ||
using FakeItEasy; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace MessageCommunicator.TestGui.Tests | ||
{ | ||
[TestClass] | ||
public class ViewServiceContainerTests | ||
{ | ||
[TestMethod] | ||
public void Check_EmptyObject() | ||
{ | ||
var fakeOwner = A.Fake<IControl>(); | ||
var viewServiceContainer = new ViewServiceContainer(fakeOwner); | ||
|
||
Assert.IsFalse(viewServiceContainer.IsObserving); | ||
} | ||
|
||
[TestMethod] | ||
public void Check_RegisterNullViewModel() | ||
{ | ||
var fakeOwner = A.Fake<IControl>(); | ||
var viewServiceContainer = new ViewServiceContainer(fakeOwner); | ||
|
||
var compositeDisposable = new CompositeDisposable(); | ||
viewServiceContainer.StartObserving(compositeDisposable, null); | ||
|
||
Assert.IsTrue(compositeDisposable.Count == 1); | ||
Assert.IsTrue(viewServiceContainer.IsObserving); | ||
} | ||
|
||
[TestMethod] | ||
public void Check_RegisterNullViewModel_WithDeregister() | ||
{ | ||
var fakeOwner = A.Fake<IControl>(); | ||
var viewServiceContainer = new ViewServiceContainer(fakeOwner); | ||
|
||
var compositeDisposable = new CompositeDisposable(); | ||
viewServiceContainer.StartObserving(compositeDisposable, null); | ||
|
||
compositeDisposable.Dispose(); | ||
|
||
Assert.IsTrue(compositeDisposable.Count == 0); | ||
Assert.IsFalse(viewServiceContainer.IsObserving); | ||
} | ||
|
||
[TestMethod] | ||
public void Check_RegisterNullViewModel_WithViewService() | ||
{ | ||
var fakeOwner = A.Fake<IControl>(); | ||
var viewServiceContainer = new ViewServiceContainer(fakeOwner); | ||
var fakeViewService1 = A.Fake<IViewService>(); | ||
var fakeViewService2 = A.Fake<IViewService>(); | ||
|
||
viewServiceContainer.ViewServices.Add(fakeViewService1); | ||
|
||
var compositeDisposable = new CompositeDisposable(); | ||
viewServiceContainer.StartObserving(compositeDisposable, null); | ||
|
||
viewServiceContainer.ViewServices.Add(fakeViewService2); | ||
|
||
Assert.IsTrue(compositeDisposable.Count == 1); | ||
Assert.IsTrue(viewServiceContainer.IsObserving); | ||
Assert.IsTrue(Fake.GetCalls(fakeViewService1).Any(actCall => actCall.Method.Name == $"add_{nameof(IViewService.ViewServiceRequest)}")); | ||
Assert.IsTrue(Fake.GetCalls(fakeViewService2).Any(actCall => actCall.Method.Name == $"add_{nameof(IViewService.ViewServiceRequest)}")); | ||
} | ||
|
||
[TestMethod] | ||
public void Check_RegisterNullViewModel__WithDeregister_WithViewService() | ||
{ | ||
var fakeOwner = A.Fake<IControl>(); | ||
var viewServiceContainer = new ViewServiceContainer(fakeOwner); | ||
var fakeViewService1 = A.Fake<IViewService>(); | ||
var fakeViewService2 = A.Fake<IViewService>(); | ||
|
||
viewServiceContainer.ViewServices.Add(fakeViewService1); | ||
|
||
var compositeDisposable = new CompositeDisposable(); | ||
viewServiceContainer.StartObserving(compositeDisposable, null); | ||
|
||
viewServiceContainer.ViewServices.Add(fakeViewService2); | ||
|
||
compositeDisposable.Dispose(); | ||
|
||
Assert.IsTrue(compositeDisposable.Count == 0); | ||
Assert.IsFalse(viewServiceContainer.IsObserving); | ||
Assert.IsTrue(Fake.GetCalls(fakeViewService1).Any(actCall => actCall.Method.Name == $"add_{nameof(IViewService.ViewServiceRequest)}")); | ||
Assert.IsTrue(Fake.GetCalls(fakeViewService1).Any(actCall => actCall.Method.Name == $"remove_{nameof(IViewService.ViewServiceRequest)}")); | ||
Assert.IsTrue(Fake.GetCalls(fakeViewService2).Any(actCall => actCall.Method.Name == $"add_{nameof(IViewService.ViewServiceRequest)}")); | ||
Assert.IsTrue(Fake.GetCalls(fakeViewService2).Any(actCall => actCall.Method.Name == $"remove_{nameof(IViewService.ViewServiceRequest)}")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters