Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Implemented 'Extras' to 'User' #32

Merged
merged 6 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions src/Sentry.Protocol/User.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Sentry.Protocol
Expand Down Expand Up @@ -45,6 +47,15 @@ public class User
[DataMember(Name = "username", EmitDefaultValue = false)]
public string Username { get; set; }

/// <summary>
/// Additional informations about the user
/// </summary>
/// <value>
/// Additional informations about the user
/// </value>
[DataMember(Name = "extras", EmitDefaultValue = false)]
wuh95 marked this conversation as resolved.
Show resolved Hide resolved
public Dictionary<string, string> Extras { get; set; }
wuh95 marked this conversation as resolved.
Show resolved Hide resolved

public User Clone()
{
var user = new User();
Expand Down Expand Up @@ -80,6 +91,12 @@ internal void CopyTo(User user)
{
user.IpAddress = IpAddress;
}

if (user.Extras == null)
wuh95 marked this conversation as resolved.
Show resolved Hide resolved
{
user.Extras = Extras?.ToDictionary(entry => entry.Key,
entry => entry.Value);
}
}
}
}
22 changes: 19 additions & 3 deletions test/Sentry.Protocol.Tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
Id = "user-id",
Email = "test@sentry.io",
IpAddress = "::1",
Username = "user-name"
Username = "user-name",
Extras = new Dictionary<string, string>
{
{"testCustomValueKey", "testCustomValue"}
}
};

var actual = JsonSerializer.SerializeObject(sut);

Assert.Equal("{\"email\":\"test@sentry.io\","
+ "\"id\":\"user-id\","
+ "\"ip_address\":\"::1\","
+ "\"username\":\"user-name\"}",
+ "\"username\":\"user-name\","
+ "\"extras\":{\"testCustomValueKey\":\"testCustomValue\"}}",
actual);
}

Expand All @@ -33,7 +38,11 @@ public void Clone_CopyValues()
Id = "id",
Email = "emal@sentry.io",
IpAddress = "::1",
Username = "user"
Username = "user",
Extras = new Dictionary<string, string>
{
{"testCustomValueKey", "testCustomValue"}
}
};

var clone = sut.Clone();
Expand All @@ -42,6 +51,7 @@ public void Clone_CopyValues()
Assert.Equal(sut.Email, clone.Email);
Assert.Same(sut.IpAddress, clone.IpAddress);
Assert.Equal(sut.Username, clone.Username);
Assert.Equal(sut.Extras, clone.Extras);
}

[Theory]
Expand All @@ -60,6 +70,12 @@ public static IEnumerable<object[]> TestCases()
yield return new object[] { (new User { Email = "some email" }, "{\"email\":\"some email\"}") };
yield return new object[] { (new User { IpAddress = "some ipAddress" }, "{\"ip_address\":\"some ipAddress\"}") };
yield return new object[] { (new User { Username = "some username" }, "{\"username\":\"some username\"}") };
yield return new object[] { (new User {Extras = new Dictionary<string, string>
{
{"testCustomValueKey", "testCustomValue"}
}

}, "{\"extras\":{\"testCustomValueKey\":\"testCustomValue\"}}") };
}
}
}