Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leandro-cavalcante committed Sep 19, 2024
1 parent f8a6af9 commit ce064ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
16 changes: 5 additions & 11 deletions tests/database/PolicyHub.DbAccess.Tests/PolicyRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ public async Task GetPolicyTypes_ReturnsExpectedResult()
var result = await sut.GetPolicyTypes(null, null).ToListAsync();

// Assert
result.Should().NotBeEmpty().And.HaveCount(7).And.Satisfy(
result.Should().NotBeEmpty().And.HaveCount(5).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "FrameworkAgreement",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "UsagePurpose",
x => x.TechnicalKey == "Dismantler",
x => x.TechnicalKey == "ContractReference"
);
}
Expand All @@ -93,11 +91,9 @@ public async Task GetPolicyTypes_WithTypeFilter_ReturnsExpectedResult()
var result = await sut.GetPolicyTypes(PolicyTypeId.Access, null).ToListAsync();

// Assert
result.Should().NotBeEmpty().And.HaveCount(4).And.Satisfy(
result.Should().NotBeEmpty().And.HaveCount(2).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler.allowedBrands" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5
x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5
);
}

Expand All @@ -111,12 +107,10 @@ public async Task GetPolicyTypes_WithUseCase_ReturnsExpectedResult()
var result = await sut.GetPolicyTypes(null, UseCaseId.Quality).ToListAsync();

// Assert
result.Should().NotBeEmpty().And.HaveCount(5).And.Satisfy(
result.Should().NotBeEmpty().And.HaveCount(3).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Membership" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler.allowedBrands" && x.Attribute.Count() == 3 && x.Type.Count() == 2 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "FrameworkAgreement" && x.Attribute.Count() == 1 && x.Type.Count() == 1 && x.UseCase.Count() == 5,
x => x.TechnicalKey == "Dismantler" && x.Attribute.Count() == 1 && x.Type.Count() == 2 && x.UseCase.Count() == 5
x => x.TechnicalKey == "FrameworkAgreement" && x.Attribute.Count() == 1 && x.Type.Count() == 1 && x.UseCase.Count() == 5
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,11 @@ public async Task GetPolicyTypes_WithoutFilter_ReturnsExpected()

// Assert
policies.Should().NotBeNull()
.And.HaveCount(7).And.Satisfy(
.And.HaveCount(5).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "FrameworkAgreement",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "UsagePurpose",
x => x.TechnicalKey == "Dismantler",
x => x.TechnicalKey == "ContractReference"
);
}
Expand All @@ -97,11 +95,9 @@ public async Task GetPolicyTypes_WithTypeFilter_ReturnsExpected()

// Assert
policies.Should().NotBeNull()
.And.HaveCount(4).And.Satisfy(
.And.HaveCount(2).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "Dismantler"
x => x.TechnicalKey == "Membership"
);
}

Expand All @@ -113,13 +109,11 @@ public async Task GetPolicyTypes_WithUseCaseFilter_ReturnsExpected()

// Assert
policies.Should().NotBeNull()
.And.HaveCount(6).And.Satisfy(
.And.HaveCount(4).And.Satisfy(
x => x.TechnicalKey == "BusinessPartnerNumber",
x => x.TechnicalKey == "Membership",
x => x.TechnicalKey == "FrameworkAgreement",
x => x.TechnicalKey == "Dismantler.allowedBrands",
x => x.TechnicalKey == "UsagePurpose",
x => x.TechnicalKey == "Dismantler"
x => x.TechnicalKey == "UsagePurpose"
);
}

Expand Down Expand Up @@ -184,17 +178,14 @@ public async Task GetPolicyContent_UsageFrameworkEquals_ReturnsExpected()
}

[Fact]
public async Task GetPolicyContent_UsageDismantlerIn_ReturnsExpected()
public async Task GetPolicyContent_UsageDismantlerIn_ExceptionExpected()
{
// Act
var response = await _client.GetAsync($"{BaseUrl}/policy-content?type={PolicyTypeId.Usage}&policyName=Dismantler.allowedBrands&operatorType={OperatorId.In}");

// Assert
response.Should().NotBeNull();
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync())
.Should()
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]}}}}");
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}

[Fact]
Expand Down Expand Up @@ -225,7 +216,7 @@ public async Task GetPolicyContentWithFiltersAsync_TwoEqualsConstraintsAndOperan
new[]
{
new Constraints("FrameworkAgreement", OperatorId.Equals, "DataExchangeGovernance:1.0"),
new Constraints("Dismantler.allowedBrands", OperatorId.In, "Audi")
new Constraints("UsagePurpose", OperatorId.In, "cx.bpdm.pool:1")
});

// Act
Expand All @@ -236,7 +227,7 @@ public async Task GetPolicyContentWithFiltersAsync_TwoEqualsConstraintsAndOperan
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync())
.Should()
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:UsagePurpose\",\"operator\":\"in\",\"rightOperand\":[\"cx.circular.dpp:1\",\"cx.circular.smc:1\",\"cx.circular.marketplace:1\",\"cx.circular.materialaccounting:1\",\"cx.bpdm.gate.upload:1\",\"cx.bpdm.gate.download:1\",\"cx.bpdm.pool:1\",\"cx.bpdm.vas.dataquality.upload:1\",\"cx.bpdm.vas.dataquality.download:1\",\"cx.bpdm.vas.bdv.upload:1\",\"cx.bpdm.vas.bdv.download:1\",\"cx.bpdm.vas.fpd.upload:1\",\"cx.bpdm.vas.fpd.download:1\",\"cx.bpdm.vas.swd.upload:1\",\"cx.bpdm.vas.swd.download:1\",\"cx.bpdm.vas.nps.upload:1\",\"cx.bpdm.vas.nps.download:1\",\"cx.bpdm.vas.countryrisk:1\",\"cx.behaviortwin.base:1\",\"cx.core.digitalTwinRegistry:1\",\"cx.core.tractionbattery:1\",\"cx.core.industrycore:1\",\"cx.core.qualityNotifications:1\",\"cx.pcf.base:1\",\"cx.quality.base:1\",\"cx.dcm.base:1\",\"cx.puris.base:1\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
}

[Fact]
Expand Down Expand Up @@ -270,7 +261,6 @@ public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsAndO
new[]
{
new Constraints("FrameworkAgreement", OperatorId.Equals, "DataExchangeGovernance:1.0"),
new Constraints("Dismantler.allowedBrands", OperatorId.In, "Audi"),
new Constraints("BusinessPartnerNumber", OperatorId.Equals, "BPNL00000003CRHK")
});

Expand All @@ -282,7 +272,7 @@ public async Task GetPolicyContentWithFiltersAsync_MultipleConstraintsEqualsAndO
response.StatusCode.Should().Be(HttpStatusCode.OK);
(await response.Content.ReadAsStringAsync())
.Should()
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"},{\"leftOperand\":\"cx-policy:Dismantler.allowedBrands\",\"operator\":\"in\",\"rightOperand\":[\"BMW\",\"Audi\",\"VW\"]},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
.Be("{\"content\":{\"@context\":[\"https://www.w3.org/ns/odrl.jsonld\",{\"cx\":\"https://w3id.org/catenax/v0.0.1/ns/\"}],\"@type\":\"Offer\",\"@id\":\"....\",\"permission\":{\"action\":\"use\",\"constraint\":{\"odrl:and\":[{\"leftOperand\":\"cx-policy:BusinessPartnerNumber\",\"operator\":\"eq\",\"rightOperand\":\"BPNL00000003CRHK\"},{\"leftOperand\":\"cx-policy:FrameworkAgreement\",\"operator\":\"eq\",\"rightOperand\":\"DataExchangeGovernance:1.0\"}]}}}}");
}

#endregion
Expand Down

0 comments on commit ce064ab

Please sign in to comment.