Skip to content

Commit

Permalink
Improve User Object tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Feb 16, 2024
1 parent 1708c22 commit 3bda929
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/ConfigCat.Client.Tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public void CreateUser_WithIdAndEmailAndCountry_AllAttributesShouldContainsPasse
var user = new User("id")
{
Email = "[email protected]",

Country = "US"
};

Expand All @@ -25,12 +24,17 @@ public void CreateUser_WithIdAndEmailAndCountry_AllAttributesShouldContainsPasse

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Email), out var s));
Assert.AreEqual("[email protected]", s);
Assert.AreEqual("[email protected]", user.GetAttribute(nameof(User.Email)));

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Country), out s));
Assert.AreEqual("US", s);
Assert.AreEqual("US", user.GetAttribute(nameof(User.Country)));

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Identifier), out s));
Assert.AreEqual("id", s);
Assert.AreEqual("id", user.GetAttribute(nameof(User.Identifier)));

Assert.AreEqual(3, actualAttributes.Count);
}

[TestMethod]
Expand All @@ -41,9 +45,7 @@ public void UseWellKnownAttributesAsCustomProperties_ShouldNotAppendAllAttribute
var user = new User("id")
{
Email = "[email protected]",

Country = "US",

Custom =
{
{ "myCustomAttribute", "myCustomAttributeValue"},
Expand All @@ -59,13 +61,17 @@ public void UseWellKnownAttributesAsCustomProperties_ShouldNotAppendAllAttribute

// Assert

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Identifier), out var s));
Assert.AreEqual("id", s);
Assert.AreNotEqual("myIdentifier", s);
Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Email), out var s));
Assert.AreEqual("id@example.com", s);
Assert.AreEqual("[email protected]", user.GetAttribute(nameof(User.Email)));

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Country), out s));
Assert.AreEqual("US", s);
Assert.AreNotEqual("United States", s);
Assert.AreEqual("US", user.GetAttribute(nameof(User.Country)));

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Identifier), out s));
Assert.AreEqual("id", s);
Assert.AreEqual("id", user.GetAttribute(nameof(User.Identifier)));

Assert.IsTrue(actualAttributes.TryGetValue(nameof(User.Email), out s));
Assert.AreEqual("[email protected]", s);
Expand All @@ -89,9 +95,7 @@ public void UseWellKnownAttributesAsCustomPropertiesWithDifferentNames_ShouldApp
var user = new User("id")
{
Email = "[email protected]",

Country = "US",

Custom =
{
{ attributeName, attributeValue}
Expand All @@ -108,6 +112,7 @@ public void UseWellKnownAttributesAsCustomPropertiesWithDifferentNames_ShouldApp

Assert.IsTrue(actualAttributes.TryGetValue(attributeName, out var s));
Assert.AreEqual(attributeValue, s);
Assert.AreEqual(attributeValue, user.GetAttribute(attributeName));
}

[DataTestMethod()]
Expand All @@ -122,5 +127,6 @@ public void CreateUser_ShouldSetIdentifier(string identifier, string expectedVal

Assert.AreEqual(expectedValue, user.Identifier);
Assert.AreEqual(expectedValue, user.GetAllAttributes()[nameof(User.Identifier)]);
Assert.AreEqual(expectedValue, user.GetAttribute(nameof(User.Identifier)));
}
}

0 comments on commit 3bda929

Please sign in to comment.