Skip to content

Commit

Permalink
Validate OrderedItemList<T> for uniqueness of keys and values
Browse files Browse the repository at this point in the history
* Validate OrderedItemList<T> for uniqueness of keys and values
  • Loading branch information
lxatstariongroup authored Nov 22, 2022
1 parent 34933fe commit f3a7e6c
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CDP4Orm.Tests/CDP4Orm.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CDP4JsonSerializer-CE" Version="8.1.0" />
<PackageReference Include="CDP4JsonSerializer-CE" Version="9.0.0" />
<PackageReference Include="Npgsql" Version="4.1.3.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
Expand Down
4 changes: 2 additions & 2 deletions CDP4Orm/CDP4Orm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Company>RHEA System S.A.</Company>
<Title>CDP4Orm-CE</Title>
<Version>7.0.3</Version>
<Version>7.1.0</Version>
<Description>COMET Data-Model Object Relational Mapping</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander</Authors>
Expand Down Expand Up @@ -54,7 +54,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CDP4JsonSerializer-CE" Version="8.1.0" />
<PackageReference Include="CDP4JsonSerializer-CE" Version="9.0.0" />
<PackageReference Include="Npgsql" Version="4.1.3.1" />
</ItemGroup>

Expand Down
12 changes: 6 additions & 6 deletions CDP4WebServer.IIS/CDP4WebServer.IIS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
<Reference Include="BouncyCastle.Crypto, Version=1.8.5.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
<HintPath>..\packages\Portable.BouncyCastle.1.8.5\lib\net40\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="CDP4Common, Version=8.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CDP4Common-CE.8.1.0\lib\net472\CDP4Common.dll</HintPath>
<Reference Include="CDP4Common, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CDP4Common-CE.9.0.0\lib\net472\CDP4Common.dll</HintPath>
</Reference>
<Reference Include="CDP4JsonSerializer, Version=8.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CDP4JsonSerializer-CE.8.1.0\lib\net472\CDP4JsonSerializer.dll</HintPath>
<Reference Include="CDP4JsonSerializer, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CDP4JsonSerializer-CE.9.0.0\lib\net472\CDP4JsonSerializer.dll</HintPath>
</Reference>
<Reference Include="DotNetZip, Version=1.14.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.14.0\lib\net40\DotNetZip.dll</HintPath>
Expand Down Expand Up @@ -120,12 +120,12 @@
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
</Reference>
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
Expand Down
2 changes: 1 addition & 1 deletion CDP4WebServer.IIS/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<configuration>
<appSettings>
<!-- OWIN is used, so all calls should be handled by OWIN -->
<add key="owin:HandleAllRequests" value="true"/>
<add key="owin:HandleAllRequests" value="true" />
<add key="owin:appStartup" value="CDP4WebServer.IIS.Startup, CDP4WebServer.IIS" />
</appSettings>
<system.web>
Expand Down
10 changes: 5 additions & 5 deletions CDP4WebServer.IIS/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net472" />
<package id="CDP4Common-CE" version="8.1.0" targetFramework="net472" />
<package id="CDP4JsonSerializer-CE" version="8.1.0" targetFramework="net472" />
<package id="CDP4Common-CE" version="9.0.0" targetFramework="net472" />
<package id="CDP4JsonSerializer-CE" version="9.0.0" targetFramework="net472" />
<package id="DotNetZip" version="1.14.0" targetFramework="net472" />
<package id="Hangfire" version="1.7.19" targetFramework="net472" />
<package id="Hangfire.Autofac" version="2.3.1" targetFramework="net472" />
Expand All @@ -11,6 +11,7 @@
<package id="Hangfire.SqlServer" version="1.7.19" targetFramework="net472" />
<package id="MailKit" version="2.8.0" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net472" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
<package id="Microsoft.Owin" version="4.2.0" targetFramework="net472" />
<package id="Microsoft.Owin.Host.SystemWeb" version="4.2.0" targetFramework="net472" />
<package id="MimeKit" version="2.9.1" targetFramework="net472" />
Expand All @@ -22,8 +23,8 @@
<package id="Npgsql" version="4.1.3.1" targetFramework="net472" />
<package id="Owin" version="1.0" targetFramework="net472" />
<package id="Portable.BouncyCastle" version="1.8.5" targetFramework="net472" />
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Resources.Extensions" version="4.6.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net472" />
Expand All @@ -32,5 +33,4 @@
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
<package id="System.Xml.XmlSerializer" version="4.3.0" targetFramework="net472" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
</packages>
2 changes: 1 addition & 1 deletion CDP4WebServer/CDP4WebServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Exe</OutputType>
<Company>RHEA System S.A.</Company>
<Title>CDP4WebServer-CE</Title>
<Version>7.0.7</Version>
<Version>7.1.0</Version>
<Description>CDP4 Services Host</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander</Authors>
Expand Down
2 changes: 1 addition & 1 deletion CDP4WebServices.API.Tests/CDP4WebServices.API.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CDP4JsonSerializer-CE" Version="8.1.0" />
<PackageReference Include="CDP4JsonSerializer-CE" Version="9.0.0" />
<PackageReference Include="DotNetZip" Version="1.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Nancy" Version="1.4.5" />
Expand Down
121 changes: 120 additions & 1 deletion CDP4WebServices.API.Tests/OperationProcessorTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OperationProcessorTestFixture.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2021 RHEA System S.A.
// Copyright (c) 2015-2022 RHEA System S.A.
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski
//
Expand Down Expand Up @@ -44,6 +44,7 @@ namespace CDP4WebServices.API.Tests

using CDP4Orm.Dao;

using CDP4WebServices.API.Exceptions;
using CDP4WebServices.API.Services;
using CDP4WebServices.API.Services.Operations;
using CDP4WebServices.API.Services.Operations.SideEffects;
Expand Down Expand Up @@ -246,6 +247,124 @@ public void VerifyTopContainerCreationNotAllowedValidation()
() => this.operationProcessor.ValidateCreateOperations(postOperation, this.fileStore));
}

[Test]
public void VerifyOrderedItemListValidationForCorrectValues()
{
var updatedItem = new CDP4Common.DTO.PossibleFiniteStateList();

updatedItem.PossibleState.Add(
new OrderedItem
{
K=1,
V=Guid.NewGuid()
});

updatedItem.PossibleState.Add(
new OrderedItem
{
K=2,
V=Guid.NewGuid()
});

updatedItem.PossibleState.Add(
new OrderedItem
{
K=3,
V=Guid.NewGuid()
});

var metaInfo = new PossibleFiniteStateListMetaInfo();

Assert.DoesNotThrow(
() => this.operationProcessor.OrderedItemListValidation(
null,
updatedItem,
new List<string> {"PossibleState"},
metaInfo
)
);
}

[Test]
public void VerifyOrderedItemListValidationForKeys()
{
var updatedItem = new CDP4Common.DTO.PossibleFiniteStateList();

updatedItem.PossibleState.Add(
new OrderedItem
{
K=0,
V=Guid.NewGuid()
});

updatedItem.PossibleState.Add(
new OrderedItem
{
K=0,
V=Guid.NewGuid()
});

updatedItem.PossibleState.Add(
new OrderedItem
{
K=1,
V=Guid.NewGuid()
});

var metaInfo = new PossibleFiniteStateListMetaInfo();

var exception = Assert.Throws<BadRequestException>(
() => this.operationProcessor.OrderedItemListValidation(
null,
updatedItem,
new List<string> {"PossibleState"},
metaInfo
)
);

Assert.That(exception.Message, Contains.Substring("contains duplicate keys"));
}

[Test]
public void VerifyOrderedItemListValidationForValues()
{
var updatedItem = new CDP4Common.DTO.PossibleFiniteStateList();

updatedItem.PossibleState.Add(
new OrderedItem
{
K=1,
V=Guid.Parse("2cfad1a6-87a4-412e-bcaa-655782cb60cf")
});

updatedItem.PossibleState.Add(
new OrderedItem
{
K=2,
V=Guid.Parse("2cfad1a6-87a4-412e-bcaa-655782cb60cf")
});

updatedItem.PossibleState.Add(
new OrderedItem
{
K=3,
V=Guid.NewGuid()
});

var metaInfo = new PossibleFiniteStateListMetaInfo();

var exception = Assert.Throws<BadRequestException>(
() => this.operationProcessor.OrderedItemListValidation(
null,
updatedItem,
new List<string> {"PossibleState"},
metaInfo
)
);

Assert.That(exception.Message, Contains.Substring("contains duplicate values"));
}

[Test]
public void VerifyCreateWithoutContainerUpdateValidation()
{
Expand Down
10 changes: 2 additions & 8 deletions CDP4WebServices.API/CDP4WebServices.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net472</TargetFramework>
<Company>RHEA System S.A.</Company>
<Title>CDP4WebServices-CE.API</Title>
<Version>7.0.7</Version>
<Version>7.1.0</Version>
<Description>Library that contains the CDP4 Services API</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander</Authors>
Expand All @@ -13,12 +13,6 @@
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Exceptions\**" />
<EmbeddedResource Remove="Exceptions\**" />
<None Remove="Exceptions\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\COMET-Community-Edition.png" />
<None Remove="Resources\comet.ico" />
Expand All @@ -27,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CDP4JsonSerializer-CE" Version="8.1.0" />
<PackageReference Include="CDP4JsonSerializer-CE" Version="9.0.0" />
<PackageReference Include="DotNetZip" Version="1.14.0" />
<PackageReference Include="Hangfire" Version="1.7.19" />
<PackageReference Include="HangFire.Autofac" Version="2.3.1" />
Expand Down
82 changes: 82 additions & 0 deletions CDP4WebServices.API/Exceptions/BadRequestException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OperationProcessor.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2021 RHEA System S.A.
//
// Author: Sam Gerené, Merlin Bieze, Alex Vorobiev, Naron Phou, Alexander van Delft, Nathanael Smiechowski
//
// This file is part of COMET Web Services Community Edition.
// The COMET Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C.
//
// The COMET Web Services Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The COMET Web Services Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4WebServices.API.Exceptions
{
using System;
using System.Runtime.Serialization;

/// <summary>
/// The BAdRequestException error exception is an exception that indicates that a bas request was send.
/// </summary>
[Serializable]
public class BadRequestException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="BadRequestException"/> class.
/// </summary>
public BadRequestException()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BadRequestException"/> class.
/// </summary>
/// <param name="message">
/// The exception message
/// </param>
public BadRequestException(string message)
: base(message)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BadRequestException"/> class.
/// </summary>
/// <param name="message">
/// The exception message
/// </param>
/// <param name="innerException">
/// A reference to the inner <see cref="Exception"/>
/// </param>
public BadRequestException(string message, Exception innerException)
: base(message, innerException)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BadRequestException"/> class.
/// </summary>
/// <param name="info">
/// The serialization data
/// </param>
/// <param name="context">
/// The <see cref="StreamingContext"/>
/// </param>
protected BadRequestException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Loading

0 comments on commit f3a7e6c

Please sign in to comment.