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

RM-8406 Create a test infrastructure for interface mapping tests #776

Open
wants to merge 1 commit into
base: spike/RM-3369-Relations-To-Interfaces-Rebased-Reviewed
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// re-motion 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 Lesser General Public License
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using Remotion.Data.DomainObjects.Mapping;

namespace Remotion.Data.DomainObjects.UnitTests.Mapping.MappingReflectionIntegrationTests
{
public interface IReferenceTypeDefinitionBuilder
{
Type Type { get; }

TypeDefinition BuildTypeDefinition (ReferenceTypeDefinitionBuilderContext context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// re-motion 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 Lesser General Public License
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using Remotion.Data.DomainObjects.Mapping;

namespace Remotion.Data.DomainObjects.UnitTests.Mapping.MappingReflectionIntegrationTests
{
public interface IReferenceTypeDefinitionRelationBuilder
{
Type LeftType { get; }

Type RightType { get; }

RelationDefinition BuildRelationDefinition (ReferenceTypeDefinitionBuilderContext context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// re-motion 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 Lesser General Public License
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using NUnit.Framework;

namespace Remotion.Data.DomainObjects.UnitTests.Mapping.MappingReflectionIntegrationTests.InterfaceMapping.Properties
{
public class AttributeCanOnlyBeAppliedOnInterfacePropertyTest : ReferenceMappingTestBase
{
private interface IPerson : IDomainObject
{
[StringProperty(IsNullable = false)]
string FirstName { get; set; }

string LastName { get; set; }
}

[DBTable]
public class Person : DomainObject, IPerson
{
/// <summary>
/// Not-null because the interface property's attribute says so.
/// </summary>
public virtual string FirstName { get; set; }

/// <summary>
/// Nullable because the attribute on this property is not considered as it is an interface property.
/// </summary>
[StringProperty(IsNullable = false)]
public virtual string LastName { get; set; }
}

[Test]
public void Verify ()
{
RunVerificationAgainstReferenceTypeDefinitions();
}

/// <inheritdoc />
protected override void CreateReferenceTypeDefinitions (ReferenceTypeDefinitionCollectionBuilder builder)
{
builder.InterfaceDefinitionFor<IPerson>()
.PersistentProperty(e => e.FirstName)
.PersistentProperty(e => e.LastName, c => c.SetIsNullable());

builder.ClassDefinitionFor<Person>()
.Implements<IPerson>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// re-motion 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 Lesser General Public License
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using NUnit.Framework;

namespace Remotion.Data.DomainObjects.UnitTests.Mapping.MappingReflectionIntegrationTests.InterfaceMapping.Properties
{
public class InterfaceWithScalarPropertiesTest : ReferenceMappingTestBase
{
private interface INotInMapping
{
int Value1 { get; set; }

int Value2 { get; set; }
}

private interface IAgeable : IDomainObject
{
DateTime Birthday { get; set; }

[StorageClassNone]
int Age { get; set; }
}

private interface IPerson : IAgeable
{
string Name { get; set; }
}

private interface INumbered : IDomainObject
{
int Number { get; set; }

int Secret { get; set; }
}

[DBTable]
public class Person : DomainObject, IPerson, INumbered, INotInMapping
{
/// <summary>
/// No property in <see cref="Person"/> as it is implicitly implemented from <see cref="IPerson"/> and it declares the property.
/// </summary>
public virtual string Name { get; set; }

/// <summary>
/// No property in <see cref="Person"/> as it is implicitly implemented from <see cref="IAgeable"/> and it declares the property.
/// </summary>
public virtual DateTime Birthday { get; set; }

/// <summary>
/// No property in <see cref="Person"/> as it is excluded in the interface using the <see cref="StorageClassNoneAttribute"/> on <see cref="IAgeable"/>.
/// </summary>
public int Age { get; set; }

/// <summary>
/// No property in <see cref="Person"/> as it is implicitly implemented from <see cref="IPerson"/> and it declares the property.
/// </summary>
public virtual int Number { get; set; }

/// <summary>
/// No property in <see cref="Person"/> as it is explicitly implemented from <see cref="INumbered"/> and it declares the property.
/// </summary>
int INumbered.Secret { get; set; }

/// <summary>
/// Normal property in <see cref="Person"/>.
/// </summary>
public virtual int MyOwnProperty { get; set; }

/// <summary>
/// Normal property <see cref="Person"/> as it is implicitly implemented from an interface that is not mapped.
/// </summary>
public int Value1 { get; set; }

/// <summary>
/// No property in <see cref="Person"/> as it is explicitly implemented.
/// </summary>
int INotInMapping.Value2 { get; set; }
}

[Test]
public void Verify ()
{
RunVerificationAgainstReferenceTypeDefinitions();
}

/// <inheritdoc />
protected override void CreateReferenceTypeDefinitions (ReferenceTypeDefinitionCollectionBuilder builder)
{
builder.InterfaceDefinitionFor<IAgeable>()
.PersistentProperty(e => e.Birthday);

builder.InterfaceDefinitionFor<IPerson>()
.Extends<IAgeable>()
.PersistentProperty(e => e.Name, c => c.SetIsNullable());

builder.InterfaceDefinitionFor<INumbered>()
.PersistentProperty(e => e.Number)
.PersistentProperty(e => e.Secret);

builder.ClassDefinitionFor<Person>()
.Implements<IPerson>()
.Implements<IAgeable>()
.Implements<INumbered>()
.PersistentProperty(e => e.MyOwnProperty)
.PersistentProperty(e => e.Value1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// re-motion 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 Lesser General Public License
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using NUnit.Framework;

namespace Remotion.Data.DomainObjects.UnitTests.Mapping.MappingReflectionIntegrationTests.InterfaceMapping.Relations
{
public class UnidirectionalRelationsTest : ReferenceMappingTestBase
{
private interface IPerson : IDomainObject
{
IAddress Address { get; }
}

private interface IAddress : IDomainObject
{
}

[Test]
public void Verify ()
{
RunVerificationAgainstReferenceTypeDefinitions();
}

/// <inheritdoc />
protected override void CreateReferenceTypeDefinitions (ReferenceTypeDefinitionCollectionBuilder builder)
{
builder.InterfaceDefinitionFor<IPerson>()
.PersistentProperty(e => e.Address, c => c.SetIsNullable());

builder.InterfaceDefinitionFor<IAddress>();

builder.UnidirectionalRelationBetween<IPerson, IAddress>(e => e.Address);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This file is part of the re-motion Core Framework (www.re-motion.org)
// Copyright (c) rubicon IT GmbH, www.rubicon.eu
//
// The re-motion Core Framework is free software; you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// re-motion 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 Lesser General Public License
// along with re-motion; if not, see http://www.gnu.org/licenses.
//
using System;
using NUnit.Framework;

namespace Remotion.Data.DomainObjects.UnitTests.Mapping.MappingReflectionIntegrationTests.InterfaceMapping.Relations
{
public class VirtualCollectionRelationTest : ReferenceMappingTestBase
{
private interface IOrder : IDomainObject
{
[DBBidirectionalRelation("Order", SortExpression = "ItemNumber asc")]
IObjectList<IOrderItem> Items { get; set; }
}

private interface IOrderItem : IDomainObject
{
int ItemNumber { get; }

[DBBidirectionalRelation("Items")]
IOrder Order { get; set; }
}


[Test]
public void Verify ()
{
RunVerificationAgainstReferenceTypeDefinitions();
}

/// <inheritdoc />
protected override void CreateReferenceTypeDefinitions (ReferenceTypeDefinitionCollectionBuilder builder)
{
builder.InterfaceDefinitionFor<IOrder>();

builder.InterfaceDefinitionFor<IOrderItem>()
.PersistentProperty(e => e.ItemNumber)
.PersistentProperty(e => e.Order, c => c.SetIsNullable());

builder.BidirectionalVirtualCollectionRelationBetween<IOrder, IOrderItem>(
e => e.Items,
e => e.Order,
e => e.Ascending("ItemNumber"));
}
}
}
Loading