Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking with identical PublishName #251

Closed
wants to merge 12 commits into from
19 changes: 19 additions & 0 deletions NewPlatform.Flexberry.ORM.ODataService/Model/DataObjectEdmModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ private void BuildTypeHierarchy()

private void BuildEdmEntityTypes()
{
// Collection for storing FullNames.
IDictionary<string, Type> collectionFullNames = new Dictionary<string, Type>();

foreach (Type dataObjectType in _metadata.Types)
{
Type baseType = dataObjectType.BaseType;
Expand All @@ -186,6 +189,22 @@ private void BuildEdmEntityTypes()
dataObjectType.IsAbstract,
!dataObjectType.IsSealed);

// Check if the FullName already contains.
if (collectionFullNames.ContainsKey(edmEntityType.FullName))
{
if (edmEntityType.Namespace.Length == 0)
{
throw new Exception($"The class with PublishName {edmEntityType.Name} is already added. " +
$"PublishName {edmEntityType.Name} repeated in classes {dataObjectType.Name} and {collectionFullNames[edmEntityType.FullName].Name}.");
}
else
{
throw new Exception($"Class named {edmEntityType.Name} has already been added.");
}
}

collectionFullNames.Add(edmEntityType.FullName, dataObjectType);

BuildOwnProperties(edmEntityType, dataObjectType);

_registeredEdmEntityTypes[dataObjectType] = edmEntityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@
using NewPlatform.Flexberry.ORM.ODataService.Model;
using NewPlatform.Flexberry.ORM.ODataService.Tests;


public class DataObjectEdmModelTest
public class DataObjectEdmModelTest : BaseODataServiceIntegratedTest
{
#if NETCOREAPP
/// <summary>
/// Конструктор по-умолчанию.
/// </summary>
/// <param name="factory">Фабрика для приложения.</param>
/// <param name="output">Вывод отладочной информации.</param>
public DataObjectEdmModelTest(CustomWebApplicationFactory<ODataServiceSample.AspNetCore.Startup> factory, Xunit.Abstractions.ITestOutputHelper output)
: base(factory, output)
{
}
#endif

[Fact]
public void TestGetDerivedTypes()
{
Expand All @@ -23,5 +34,21 @@ public void TestGetDerivedTypes()
Assert.Equal(1, derivedTypes.Count);
Assert.Equal(typeof(Лес), derivedTypes.First());
}

/// <summary>
/// Checks for an exception that occurs when the PublishName are the same.
/// </summary>
[Fact(Skip = "Test will pass if two objects have the same PublishName.")]
public void TestCheckIdenticalPublishName()
{
// Arrange
var expectedException = typeof(Exception);

// Act
var exception = Assert.Throws<Exception>(() => ActODataService(args => { }));

// Assert
Assert.Equal(exception.GetType(), expectedException);
}
}
}