SEBWIN-679: Extended unit tests for core library and attempted to fix open windows test for external application.

This commit is contained in:
Damian Büchel 2023-07-04 17:19:42 +02:00
parent 37e3950a6f
commit 817f598d8a
4 changed files with 39 additions and 3 deletions

View file

@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SafeExamBrowser.Core.Contracts.Resources.Icons;
@ -51,7 +52,7 @@ namespace SafeExamBrowser.Applications.UnitTests
[TestMethod]
public void GetWindows_MustCorrectlyReturnOpenWindows()
{
var openWindows = new List<IntPtr> { new IntPtr(123), new IntPtr(234), new IntPtr(456), new IntPtr(345), new IntPtr(567), new IntPtr(789), };
var openWindows = new List<IntPtr> { new IntPtr(123), new IntPtr(234), new IntPtr(456), new IntPtr(345), new IntPtr(567), new IntPtr(789) };
var process1 = new Mock<IProcess>();
var process2 = new Mock<IProcess>();
var sync = new AutoResetEvent(false);
@ -84,8 +85,9 @@ namespace SafeExamBrowser.Applications.UnitTests
Assert.IsTrue(windows.Any(w => w.Handle == new IntPtr(567)));
nativeMethods.Setup(n => n.GetOpenWindows()).Returns(openWindows.Skip(2));
process2.Raise(p => p.Terminated += null, default(int));
Task.Run(() => process2.Raise(p => p.Terminated += null, default(int)));
sync.WaitOne();
sync.WaitOne();
windows = sut.GetWindows();

View file

@ -10,8 +10,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SafeExamBrowser.Communication.Contracts;
using SafeExamBrowser.Core.Contracts.OperationModel;
using SafeExamBrowser.Logging.Contracts;
using SafeExamBrowser.Core.Operations;
using SafeExamBrowser.Logging.Contracts;
namespace SafeExamBrowser.Core.UnitTests.Operations
{
@ -83,5 +83,19 @@ namespace SafeExamBrowser.Core.UnitTests.Operations
hostMock.Verify(h => h.Stop(), Times.Once);
hostMock.Verify(h => h.Start(), Times.Never);
}
[TestMethod]
public void MustFireStatusChangedEvent()
{
var fired = 0;
sut.StatusChanged += (_) => fired++;
sut.Perform();
sut.Repeat();
sut.Revert();
Assert.AreEqual(3, fired);
}
}
}

View file

@ -64,5 +64,16 @@ namespace SafeExamBrowser.Core.UnitTests.Operations
Assert.AreEqual(OperationResult.Success, repeat);
Assert.AreEqual(OperationResult.Success, revert);
}
[TestMethod]
public void MustNotFireEvents()
{
var sut = new DelegateOperation(default, default, default);
sut.ActionRequired += (_) => Assert.Fail();
sut.StatusChanged += (_) => Assert.Fail();
sut.Perform();
}
}
}

View file

@ -48,5 +48,14 @@ namespace SafeExamBrowser.Core.UnitTests.Operations
sut.Revert();
text.VerifyNoOtherCalls();
}
[TestMethod]
public void MustNotFireEvents()
{
sut.ActionRequired += (_) => Assert.Fail();
sut.StatusChanged += (_) => Assert.Fail();
sut.Perform();
}
}
}