1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Added Services and Utilities Tests to Core.Test project (#1068)

* Sorted usings

* Added CoreHelpersTests

* Added CloneObject test

* Added comments to SelfHostedAttributeTests

* Changed private variable declaration to be inline with the rest of the project

* Changed to SUT naming scheme

* Scaffolded AppleIapServiceTests

* Scaffolded I18nServiceTests.cs

* Scaffolded I18nViewLocalizerTests

* Scaffolded LocalSendStorageServiceTests

* Added tests to ReadableBytesSize_Success

* Add more CleanCertificateThumbprint tests

* Added more tests for the ExtendQuery method

* Removed AppleIapServiceTests

* Removed I18nServiceTests

* Removed I18nViewLocalizerTests

* Removed LocalSendStorageServiceTests

* Converted Batch_Success to theory with InlineData

* Simplified Batch_Success so there is less branching and more accuracy

* Switched to using size variable to format readable bytes for any number lower than 1024

* Fixed test data to work in all locales
This commit is contained in:
Justin Baur
2021-01-06 13:49:28 -05:00
committed by GitHub
parent d96da37e2a
commit aad36496e4
4 changed files with 250 additions and 17 deletions

View File

@ -1,15 +1,14 @@
using Bit.Core.Utilities;
using System.Collections.Generic;
using Bit.Core.Exceptions;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Xunit;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Mvc.Abstractions;
namespace Bit.Core.Test.Utilities
{
@ -18,33 +17,47 @@ namespace Bit.Core.Test.Utilities
[Fact]
public void NotSelfHosted_Throws_When_SelfHosted()
{
// Arrange
var sha = new SelfHostedAttribute { NotSelfHostedOnly = true };
// Act & Assert
Assert.Throws<BadRequestException>(() => sha.OnActionExecuting(GetContext(selfHosted: true)));
}
[Fact]
public void NotSelfHosted_Success_When_NotSelfHosted()
{
// Arrange
var sha = new SelfHostedAttribute { NotSelfHostedOnly = true };
// Act
sha.OnActionExecuting(GetContext(selfHosted: false));
// Assert
// The Assert here is just NOT throwing an exception
}
[Fact]
public void SelfHosted_Success_When_SelfHosted()
{
// Arrange
var sha = new SelfHostedAttribute { SelfHostedOnly = true };
// Act
sha.OnActionExecuting(GetContext(selfHosted: true));
// Assert
// The Assert here is just NOT throwing an exception
}
[Fact]
public void SelfHosted_Throws_When_NotSelfHosted()
{
// Arrange
var sha = new SelfHostedAttribute { SelfHostedOnly = true };
// Act & Assert
Assert.Throws<BadRequestException>(() => sha.OnActionExecuting(GetContext(selfHosted: false)));
}