Skip to content

Commit

Permalink
cleanup + unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Feb 9, 2024
1 parent 184b83e commit 08ff419
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
using System.Text.Json.Serialization;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;

/// <summary>
/// Model for CompanyCertificateTypeData
/// </summary>]
/// <param name="companyCertificateId">CompanyCertificate Type Id</param>
/// <param name="description">description</param>
/// <param name="CompanyCertificateTypeId">CompanyCertificate Type Id</param>
/// <param name="Description">description</param>
/// <returns></returns>
public record CompanyCertificateTypeData(CompanyCertificateTypeId companyCertificateId, IEnumerable<CertificateTypeDescription> description);
public record CompanyCertificateTypeData(
[property: JsonPropertyName("certificateType")] CompanyCertificateTypeId CompanyCertificateTypeId,
IEnumerable<CertificateTypeDescription> Description);

/// <summary>
/// Model for CertificateTypeDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public IAsyncEnumerable<LicenseTypeData> GetLicenseTypeData() =>
///<inheritdoc />
public IAsyncEnumerable<CompanyCertificateTypeData> GetCertificateTypes() =>
_dbContext.CompanyCertificateTypes.AsNoTracking()
.Select(certificate => new CompanyCertificateTypeData
.Where(type => type.CompanyCertificateTypeAssignedStatus!.CompanyCertificateTypeStatusId == CompanyCertificateTypeStatusId.ACTIVE)
.Select(type => new CompanyCertificateTypeData
(
certificate.Id,
certificate.CompanyCertificateTypeDescriptions
.Where(y => y.CompanyCertificateType.CompanyCertificateTypeAssignedStatus.CompanyCertificateTypeStatusId == CompanyCertificateTypeStatusId.ACTIVE)
.Select(x => new CertificateTypeDescription(x.LanguageShortName, x.Description))
type.Id,
type.CompanyCertificateTypeDescriptions
.Select(x => new CertificateTypeDescription(x.LanguageShortName, x.Description))
))
.AsAsyncEnumerable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CompanyCertificateStatus
private CompanyCertificateStatus()
{
Label = null!;
CompanyCertificates = new HashSet<CompanyCertificate>();
}

public CompanyCertificateStatus(CompanyCertificateStatusId certificateStatusId) : this()
Expand All @@ -39,4 +40,8 @@ public CompanyCertificateStatus(CompanyCertificateStatusId certificateStatusId)

[MaxLength(255)]
public string Label { get; private set; }

// Navigation Properties

public virtual ICollection<CompanyCertificate> CompanyCertificates { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private CompanyCertificateType()
{
Label = null!;
CompanyCertificates = new HashSet<CompanyCertificate>();
CompanyCertificateTypeDescriptions = new HashSet<CompanyCertificateTypeDescription>();
}

public CompanyCertificateType(CompanyCertificateTypeId companyCertificateTypeId) : this()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class CompanyCertificateTypeStatus
private CompanyCertificateTypeStatus()
{
Label = null!;
CompanyCertificateTypeAssignedStatuses = new HashSet<CompanyCertificateTypeAssignedStatus>();
}

public CompanyCertificateTypeStatus(CompanyCertificateTypeStatusId companyCertificateTypeStatusId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Tests.Setup;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Xunit.Extensions.AssemblyFixture;

Expand Down Expand Up @@ -171,6 +172,33 @@ public async Task GetCertificateTypes_ReturnsExpectedResult()
results.Should().HaveCount(12);
}

[Fact]
public async Task GetCertificateTypes_WithInactiveCertificateType_ReturnsExpectedResult()
{
// Arrange
var (context, sut) = await CreateSutWithContext().ConfigureAwait(false);
var active = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.ACTIVE);
var inactive = new CompanyCertificateTypeAssignedStatus(CompanyCertificateTypeId.ISO_15504_SPICE, CompanyCertificateTypeStatusId.INACTVIE);
context.Remove(active);
context.Add(inactive);
await context.SaveChangesAsync().ConfigureAwait(false);

try
{
// Act
var results = await sut.GetCertificateTypes().ToListAsync().ConfigureAwait(false);

// Assert
results.Should().HaveCount(11);
}
finally
{
context.Remove(inactive);
context.Add(active);
await context.SaveChangesAsync().ConfigureAwait(false);
}
}

#endregion

#region setup
Expand All @@ -182,5 +210,12 @@ private async Task<StaticDataRepository> CreateSut()
return sut;
}

private async Task<(PortalDbContext, StaticDataRepository)> CreateSutWithContext()
{
var context = await _dbTestDbFixture.GetPortalDbContext().ConfigureAwait(false);
var sut = new StaticDataRepository(context);
return (context, sut);
}

#endregion
}

0 comments on commit 08ff419

Please sign in to comment.