Skip to content

Commit

Permalink
[Remove] locally defined ThingNotFoundException and use the same exce…
Browse files Browse the repository at this point in the history
…ption from the CDP4-SDK
  • Loading branch information
samatrhea committed Dec 30, 2023
1 parent df7c243 commit 223c6a3
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ public void VerifyCheckAllowedAccordingToIsHidden()
Assert.DoesNotThrow(() => this.domainFileStoreService.CheckAllowedAccordingToIsHidden(this.transaction.Object, domainFileStore));

this.permissionService.Setup(x => x.IsOwner(It.IsAny<NpgsqlTransaction>(), domainFileStore)).Returns(false);
Assert.Throws<CometServer.Exceptions.ThingNotFoundException >(() => this.domainFileStoreService.CheckAllowedAccordingToIsHidden(this.transaction.Object, domainFileStore));
Assert.That(() => this.domainFileStoreService.CheckAllowedAccordingToIsHidden(this.transaction.Object, domainFileStore), Throws.TypeOf<ThingNotFoundException>());

domainFileStore.IsHidden = false;
Assert.DoesNotThrow(() => this.domainFileStoreService.CheckAllowedAccordingToIsHidden(this.transaction.Object, domainFileStore));
Assert.That(() => this.domainFileStoreService.CheckAllowedAccordingToIsHidden(this.transaction.Object, domainFileStore), Throws.Nothing);
}

[Test]
Expand All @@ -173,10 +173,10 @@ public void VerifyHasReadAccess<T>(T thing, bool shouldFail) where T : Thing
{
if (shouldFail)
{
Assert.Throws<Cdp4ModelValidationException>(() => this.domainFileStoreService.HasReadAccess(
Assert.That(() => this.domainFileStoreService.HasReadAccess(
thing,
this.transaction.Object,
this.iterationPartitionName));
this.iterationPartitionName), Throws.TypeOf<Cdp4ModelValidationException>());
}
else
{
Expand Down Expand Up @@ -214,38 +214,38 @@ public void VerifyCheckSecurity<T>(T thing, bool shouldFail) where T : Thing
{
if (shouldFail)
{
Assert.Throws<SecurityException>(() => this.domainFileStoreService.HasWriteAccess(
Assert.That(() => this.domainFileStoreService.HasWriteAccess(
thing,
this.transaction.Object,
this.iterationPartitionName));
this.iterationPartitionName), Throws.TypeOf<SecurityException>());

this.permissionService.Setup(x => x.IsOwner(It.IsAny<NpgsqlTransaction>(), It.IsAny<ElementDefinition>())).Returns(true);

Assert.Throws<Cdp4ModelValidationException>(() => this.domainFileStoreService.HasWriteAccess(
Assert.That(() => this.domainFileStoreService.HasWriteAccess(
thing,
this.transaction.Object,
this.iterationPartitionName));
this.iterationPartitionName), Throws.TypeOf<Cdp4ModelValidationException>());
}
else
{
Assert.DoesNotThrow(() => this.domainFileStoreService.HasWriteAccess(
Assert.That(() => this.domainFileStoreService.HasWriteAccess(
thing,
this.transaction.Object,
this.iterationPartitionName));
this.iterationPartitionName), Throws.Nothing);

domainFileStore.IsHidden = true;

Assert.DoesNotThrow(() => this.domainFileStoreService.HasWriteAccess(
Assert.That(() => this.domainFileStoreService.HasWriteAccess(
thing,
this.transaction.Object,
this.iterationPartitionName));
this.iterationPartitionName), Throws.Nothing);

this.permissionService.Setup(x => x.IsOwner(It.IsAny<NpgsqlTransaction>(), thing)).Returns(false);

Assert.Throws<SecurityException>(() => this.domainFileStoreService.HasWriteAccess(
Assert.That(() => this.domainFileStoreService.HasWriteAccess(
thing,
this.transaction.Object,
this.iterationPartitionName));
this.iterationPartitionName), Throws.TypeOf<SecurityException>());
}
}

Expand Down
67 changes: 0 additions & 67 deletions CometServer/Exceptions/ThingNotFoundException.cs

This file was deleted.

3 changes: 2 additions & 1 deletion CometServer/Modules/10-25/EngineeringModelApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace CometServer.Modules
using Carter.Response;

using CDP4Common.DTO;
using CDP4Common.Exceptions;

using CDP4JsonSerializer;

Expand Down Expand Up @@ -486,7 +487,7 @@ protected async Task GetResponseData(HttpRequest httpRequest, HttpResponse httpR
}

/// <summary>
/// Cherry Picks <see cref="Thing" />s inside read <see cref="Thing"/>s based on provided <see cref="ClassKind"/> and <see cref="Category"/> filters
/// Cherry Picks <see cref="Thing" />s inside read <see cref="Thing"/>s based on provided <see cref="CDP4Common.CommonData.ClassKind"/> and <see cref="Category"/> filters
/// </summary>
/// <param name="resourceResponse">A collection of read <see cref="Thing"/>s</param>
/// <param name="requestUtils">
Expand Down
1 change: 1 addition & 0 deletions CometServer/Modules/10-25/SiteDirectoryApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace CometServer.Modules
using Carter.Response;

using CDP4Common.DTO;
using CDP4Common.Exceptions;

using CDP4JsonSerializer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace CometServer.Services

using CDP4Common.Comparers;
using CDP4Common.DTO;
using CDP4Common.Exceptions;

using CometServer.Authorization;
using CometServer.Exceptions;
Expand Down
1 change: 1 addition & 0 deletions CometServer/Services/ResourceProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace CometServer.Services
using System.Linq;

using CDP4Common.DTO;
using CDP4Common.Exceptions;
using CDP4Common.Types;

using CometServer.Exceptions;
Expand Down
2 changes: 0 additions & 2 deletions CometServer/Services/Supplemental/DomainFileStoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ namespace CometServer.Services

using Npgsql;

using ThingNotFoundException = Exceptions.ThingNotFoundException;

/// <summary>
/// The handcoded part of the <see cref="DomainFileStore"/> Service which uses the ORM layer to interact with the data model.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions CometServer/Services/Supplemental/IterationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace CometServer.Services
using Authorization;

using CDP4Common.DTO;
using CDP4Common.Exceptions;

using CometServer.Exceptions;

Expand Down

0 comments on commit 223c6a3

Please sign in to comment.