Skip to content

Commit

Permalink
Merge pull request #73 from jfhs/fix-multirelationship-save
Browse files Browse the repository at this point in the history
fix(RelationshipAttribute): correct Equals and ToString
  • Loading branch information
jaredcnance authored Mar 23, 2017
2 parents 2c7d07f + 4cc1000 commit 2a8c633
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
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);
}
}
}

0 comments on commit 2a8c633

Please sign in to comment.