Skip to content

Commit 939f399

Browse files
sbellonehognevevle
andauthored
feat: support long in IncrementSet/IncrementFrom (#799)
Co-authored-by: Hogne Vevle <[email protected]>
1 parent cbafb8f commit 939f399

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

src/Algolia.Search.Test/Serializer/SerializerTest.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ public void TestPartialUpdateOperation_Increment()
679679

680680
[Test]
681681
[Parallelizable]
682-
public void TestPartialUpdateOperation_IncrementFrom()
682+
public void TestPartialUpdateOperation_IncrementFrom_int()
683683
{
684684
RecordWithPartialUpdateOperation<int> record = new RecordWithPartialUpdateOperation<int>
685685
{
@@ -693,7 +693,21 @@ public void TestPartialUpdateOperation_IncrementFrom()
693693

694694
[Test]
695695
[Parallelizable]
696-
public void TestPartialUpdateOperation_IncrementSet()
696+
public void TestPartialUpdateOperation_IncrementFrom_long()
697+
{
698+
RecordWithPartialUpdateOperation<long> record = new RecordWithPartialUpdateOperation<long>
699+
{
700+
ObjectID = "myID",
701+
Update = PartialUpdateOperation<long>.IncrementFrom((long)2),
702+
};
703+
704+
string json = JsonConvert.SerializeObject(record, JsonConfig.AlgoliaJsonSerializerSettings);
705+
Assert.AreEqual(json, "{\"objectID\":\"myID\",\"update\":{\"_operation\":\"IncrementFrom\",\"value\":2}}");
706+
}
707+
708+
[Test]
709+
[Parallelizable]
710+
public void TestPartialUpdateOperation_IncrementSet_int()
697711
{
698712
RecordWithPartialUpdateOperation<int> record = new RecordWithPartialUpdateOperation<int>
699713
{
@@ -705,6 +719,20 @@ public void TestPartialUpdateOperation_IncrementSet()
705719
Assert.AreEqual(json, "{\"objectID\":\"myID\",\"update\":{\"_operation\":\"IncrementSet\",\"value\":2}}");
706720
}
707721

722+
[Test]
723+
[Parallelizable]
724+
public void TestPartialUpdateOperation_IncrementSet_long()
725+
{
726+
RecordWithPartialUpdateOperation<long> record = new RecordWithPartialUpdateOperation<long>
727+
{
728+
ObjectID = "myID",
729+
Update = PartialUpdateOperation<long>.IncrementSet((long)2),
730+
};
731+
732+
string json = JsonConvert.SerializeObject(record, JsonConfig.AlgoliaJsonSerializerSettings);
733+
Assert.AreEqual(json, "{\"objectID\":\"myID\",\"update\":{\"_operation\":\"IncrementSet\",\"value\":2}}");
734+
}
735+
708736
[Test]
709737
[Parallelizable]
710738
public void TestPartialUpdateOperation_Decrement()

src/Algolia.Search/Models/Search/PartialUpdateOperation.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public static PartialUpdateOperation<int> IncrementFrom(int value)
6767
};
6868
}
6969

70+
///<inheritdoc cref="IncrementFrom(int)"/>
71+
public static PartialUpdateOperation<long> IncrementFrom(long value)
72+
{
73+
return new PartialUpdateOperation<long>
74+
{
75+
Operation = PartialUpdateOperationType.IncrementFrom,
76+
Value = value,
77+
};
78+
}
79+
7080
/// <summary>
7181
/// Increment a numeric integer attribute only if the provided value is greater than the current value, and otherwise ignore the whole object update
7282
/// </summary>
@@ -81,6 +91,16 @@ public static PartialUpdateOperation<int> IncrementSet(int value)
8191
};
8292
}
8393

94+
///<inheritdoc cref="IncrementSet(int)"/>
95+
public static PartialUpdateOperation<long> IncrementSet(long value)
96+
{
97+
return new PartialUpdateOperation<long>
98+
{
99+
Operation = PartialUpdateOperationType.IncrementSet,
100+
Value = value,
101+
};
102+
}
103+
84104
/// <summary>
85105
/// Decrement by an integer value
86106
/// </summary>

0 commit comments

Comments
 (0)