Skip to content

fix(RelationshipAttribute): correct Equals and ToString #73

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

Merged
merged 2 commits into from
Mar 23, 2017
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ Install-Package JsonApiDotnetCore

- project.json
```json
"JsonApiDotNetCore": "1.2.0"
"JsonApiDotNetCore": "1.2.1"
```

- *.csproj
```xml
<ItemGroup>
<!-- ... -->
<PackageReference Include="JsonApiDotNetCore" Version="1.2.0" />
<PackageReference Include="JsonApiDotNetCore" Version="1.2.1" />
</ItemGroup>
```

Expand Down
2 changes: 1 addition & 1 deletion src/JsonApiDotNetCore/JsonApiDotNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.2.0</VersionPrefix>
<VersionPrefix>1.2.1</VersionPrefix>
<TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>JsonApiDotNetCore</AssemblyName>
<PackageId>JsonApiDotNetCore</PackageId>
Expand Down
15 changes: 15 additions & 0 deletions src/JsonApiDotNetCore/Models/RelationshipAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,20 @@ protected RelationshipAttribute(string publicName)
public bool IsHasOne { get { return this.GetType() == typeof(HasOneAttribute); } }

public abstract void SetValue(object entity, object newValue);

public override string ToString()
{
return base.ToString() + ":" + PublicRelationshipName;
}

public override bool Equals(object obj)
{
RelationshipAttribute attr = obj as RelationshipAttribute;
if (attr == null)
{
return false;
}
return IsHasMany == attr.IsHasMany && PublicRelationshipName.Equals(attr.PublicRelationshipName);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using JsonApiDotNetCore.Models;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace JsonApiDotNetCoreExampleTests.Unit.Models
{
public class AttributesEqualsTests
{
[Fact]
public void HasManyAttribute_Equals_Returns_True_When_Same_Name()
{
var a = new HasManyAttribute("test");
var b = new HasManyAttribute("test");

Assert.Equal(a, b);
}

[Fact]
public void HasManyAttribute_Equals_Returns_False_When_Different_Name()
{
var a = new HasManyAttribute("test");
var b = new HasManyAttribute("test2");

Assert.NotEqual(a, b);
}

[Fact]
public void HasOneAttribute_Equals_Returns_True_When_Same_Name()
{
var a = new HasOneAttribute("test");
var b = new HasOneAttribute("test");

Assert.Equal(a, b);
}

[Fact]
public void HasOneAttribute_Equals_Returns_False_When_Different_Name()
{
var a = new HasOneAttribute("test");
var b = new HasOneAttribute("test2");

Assert.NotEqual(a, b);
}

[Fact]
public void AttrAttribute_Equals_Returns_True_When_Same_Name()
{
var a = new AttrAttribute("test");
var b = new AttrAttribute("test");

Assert.Equal(a, b);
}

[Fact]
public void AttrAttribute_Equals_Returns_False_When_Different_Name()
{
var a = new AttrAttribute("test");
var b = new AttrAttribute("test2");

Assert.NotEqual(a, b);
}

[Fact]
public void HasManyAttribute_Doesnt_Equal_HasOneAttribute_With_Same_Name()
{
RelationshipAttribute a = new HasManyAttribute("test");
RelationshipAttribute b = new HasOneAttribute("test");

Assert.NotEqual(a, b);
Assert.NotEqual(b, a);
}
}
}