Skip to content

Commit 4e6a867

Browse files
authored
feat: add overload for setdata (#68)
1 parent b16d7b9 commit 4e6a867

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

src/stream-net-tests/IntegrationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,18 +1575,18 @@ public async Task TestCollectionsSelect()
15751575
id2 = System.Guid.NewGuid().ToString();
15761576
var data1 = new CollectionObject(id1);
15771577
data1.SetData("hobbies", new List<string> { "eating", "coding" });
1578+
data1.SetData(new Dictionary<string, object> { ["name"] = "John" });
15781579
var data2 = new CollectionObject(id2);
15791580
data2.SetData("vacation", new List<string> { "Spain", "Iceland" });
15801581

1581-
var data = new List<CollectionObject> { data1, data2 };
1582-
1583-
await this._client.Collections.UpsertMany("people", data);
1582+
await this._client.Collections.UpsertMany("people", new[] { data1, data2 });
15841583

15851584
var result = await this._client.Collections.Select("people", id1);
15861585

15871586
Assert.NotNull(result);
15881587
Assert.AreEqual(data1.ID, result.ID);
15891588
Assert.AreEqual(data1.GetData<List<string>>("hobbies"), result.GetData<List<string>>("hobbies"));
1589+
Assert.AreEqual(data1.GetData<string>("name"), result.GetData<string>("name"));
15901590
}
15911591

15921592
[Test]

src/stream-net/Activity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public T GetData<T>(string name)
8585

8686
public void SetData<T>(string name, T data) => SetData(name, data, null);
8787

88+
public void SetData(IEnumerable<KeyValuePair<string, object>> data) => data.ForEach(x => SetData(x.Key, x.Value, null));
89+
8890
public void SetData<T>(string name, T data, JsonSerializer serializer)
8991
{
9092
if (serializer != null)

src/stream-net/Collections.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,15 @@ public CollectionObject(string id)
2121
ID = id;
2222
}
2323

24-
public T GetData<T>(string name)
25-
{
26-
return this._data.GetData<T>(name);
27-
}
24+
public T GetData<T>(string name) => _data.GetData<T>(name);
2825

29-
public void SetData<T>(string name, T data)
30-
{
31-
this._data.SetData<T>(name, data);
32-
}
26+
public void SetData<T>(string name, T data) => _data.SetData<T>(name, data);
3327

34-
public void SetData<T>(string name, T data, JsonSerializer serializer)
35-
{
36-
this._data.SetData<T>(name, data, serializer);
37-
}
28+
public void SetData(IEnumerable<KeyValuePair<string, object>> data) => data.ForEach(x => SetData(x.Key, x.Value, null));
3829

39-
public string Ref(string collectionName)
40-
{
41-
return Collections.Ref(collectionName, this);
42-
}
30+
public void SetData<T>(string name, T data, JsonSerializer serializer) => _data.SetData<T>(name, data, serializer);
31+
32+
public string Ref(string collectionName) => Collections.Ref(collectionName, this);
4333

4434
internal JObject ToJObject()
4535
{

src/stream-net/EnrichedActivity.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public T GetData<T>(string name)
7878

7979
public void SetData<T>(string name, T data) => SetData(name, data, null);
8080

81+
public void SetData(IEnumerable<KeyValuePair<string, object>> data) => data.ForEach(x => SetData(x.Key, x.Value, null));
82+
8183
public void SetData<T>(string name, T data, JsonSerializer serializer)
8284
{
8385
if (serializer != null)

src/stream-net/GenericData.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public T GetData<T>(string name)
2020

2121
public void SetData<T>(string name, T data) => SetData(name, data, null);
2222

23+
public void SetData(IEnumerable<KeyValuePair<string, object>> data) => data.ForEach(x => SetData(x.Key, x.Value, null));
24+
2325
public void SetData<T>(string name, T data, JsonSerializer serializer)
2426
{
2527
if (serializer != null)

0 commit comments

Comments
 (0)