SEBWIN-893, #883: Implemented unit test for concurrency issue resolution.
This commit is contained in:
parent
0fb7f23bcb
commit
58c8e69716
2 changed files with 63 additions and 0 deletions
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2024 ETH Zürich, IT Services
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Moq;
|
||||
using SafeExamBrowser.Configuration.Contracts;
|
||||
using SafeExamBrowser.Configuration.Contracts.Integrity;
|
||||
using SafeExamBrowser.Configuration.Cryptography;
|
||||
using SafeExamBrowser.Logging.Contracts;
|
||||
|
||||
namespace SafeExamBrowser.Configuration.UnitTests.Cryptography
|
||||
{
|
||||
[TestClass]
|
||||
public class KeyGeneratorTests
|
||||
{
|
||||
private AppConfig appConfig;
|
||||
private Mock<IIntegrityModule> integrityModule;
|
||||
private Mock<ILogger> logger;
|
||||
private KeyGenerator sut;
|
||||
|
||||
[TestInitialize]
|
||||
public void Initialize()
|
||||
{
|
||||
appConfig = new AppConfig();
|
||||
integrityModule = new Mock<IIntegrityModule>();
|
||||
logger = new Mock<ILogger>();
|
||||
|
||||
sut = new KeyGenerator(appConfig, integrityModule.Object, logger.Object);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
|
||||
public void CalculateBrowserExamKeyHash_MustFailWithoutUrl()
|
||||
{
|
||||
sut.CalculateBrowserExamKeyHash(default, default, default);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Exception), AllowDerivedTypes = true)]
|
||||
public void CalculateConfigurationKeyHash_MustFailWithoutUrl()
|
||||
{
|
||||
sut.CalculateConfigurationKeyHash(default, default);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MustAllowForConcurrentKeyHashCalculation()
|
||||
{
|
||||
Parallel.For(0, 1000, (_) =>
|
||||
{
|
||||
sut.CalculateBrowserExamKeyHash(default, default, "https://www.safeexambrowser.org");
|
||||
sut.CalculateConfigurationKeyHash(default, "https://www.safeexambrowser.org");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -148,6 +148,7 @@
|
|||
<Compile Include="Cryptography\PasswordEncryptionTests.cs" />
|
||||
<Compile Include="Cryptography\PublicKeyEncryptionTests.cs" />
|
||||
<Compile Include="Cryptography\PublicKeySymmetricEncryptionTests.cs" />
|
||||
<Compile Include="Cryptography\KeyGeneratorTests.cs" />
|
||||
<Compile Include="DataCompression\GZipCompressorTests.cs" />
|
||||
<Compile Include="DataFormats\BinaryParserTests.cs" />
|
||||
<Compile Include="DataFormats\BinarySerializerTests.cs" />
|
||||
|
|
Loading…
Add table
Reference in a new issue