Skip to content

Commit a6dadd6

Browse files
authored
Increasing code coverage (#56)
* Cover FTSearch * delete IndexIndexDataType * add TestQueryCommandBuilder * more cover to equal & ToString of graph data types * cover more equal/ToString/Hash functions * fix test * fix infinity * start covering command builder * Add TestInsertArgsError * Cover Reducer * Cover Document * Cover limit * Delete ExplainScore * Cover CuckooCommandBuilder * Cover TopK * Cover Search Query * Cover All search Query * Cover search schema * Cover FT._List * mark as Comment CallProcedureReadOnly * בםצצקמא ValueToStringNoQuotes * cover more from AddVectorField * More cover to timeSeries * Comment TsDuplicatePolicy AsPolicy * delete unnecessary code from graph * delete unnecessary code from search * delete unnecessary code from TimeSeries
1 parent 0aa7b92 commit a6dadd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+590
-448
lines changed

src/NRedisStack/Graph/DataTypes/Edge.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class Edge : GraphEntity
2626
/// <value></value>
2727
public long Destination { get; set; }
2828

29-
// TODO: check if this is needed:
3029
/// <summary>
3130
/// Overriden from the base `Equals` implementation. In addition to the expected behavior of checking
3231
/// reference equality, we'll also fall back and check to see if the: Source, Destination, and RelationshipType

src/NRedisStack/Graph/DataTypes/GraphEntity.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public abstract class GraphEntity
1212

1313
public IDictionary<string, object> PropertyMap = new Dictionary<string, object>();
1414

15-
// TODO: check if this is needed:
1615
/// <summary>
1716
/// Overriden Equals that considers the equality of the entity ID as well as the equality of the
1817
/// properties that each entity has.
@@ -49,7 +48,7 @@ public override int GetHashCode()
4948

5049
hash = hash * 31 + Id.GetHashCode();
5150

52-
foreach(var prop in PropertyMap)
51+
foreach (var prop in PropertyMap)
5352
{
5453
hash = hash * 31 + prop.Key.GetHashCode();
5554
hash = hash * 31 + prop.Value.GetHashCode();
@@ -59,23 +58,6 @@ public override int GetHashCode()
5958
}
6059
}
6160

62-
/// <summary>
63-
/// Overriden ToString that emits a string containing the ID and property map of the entity.
64-
/// </summary>
65-
/// <returns></returns>
66-
public override string ToString()
67-
{
68-
var sb = new StringBuilder();
69-
70-
sb.Append("GraphEntity{id=");
71-
sb.Append(Id);
72-
sb.Append(", propertyMap=");
73-
sb.Append(PropertyMap);
74-
sb.Append('}');
75-
76-
return sb.ToString();
77-
}
78-
7961
public string PropertyMapToString()
8062
{
8163
var sb = new StringBuilder();

src/NRedisStack/Graph/DataTypes/Node.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public Node()
1616
Labels = new List<string>();
1717
}
1818

19-
// TODO: check if this is needed:
2019
/// <summary>
2120
/// Overriden member that checks to see if the names of the labels of a node are equal
2221
/// (in addition to base `Equals` functionality).

src/NRedisStack/Graph/DataTypes/Path.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public Path(IList<Node> nodes, IList<Edge> edges)
2020
Edges = new ReadOnlyCollection<Edge>(edges);
2121
}
2222

23-
// TODO: check if this is needed:
2423
/// <summary>
2524
/// Overriden `Equals` method that will consider the equality of the Nodes and Edges between two paths.
2625
/// </summary>
@@ -68,7 +67,6 @@ public override int GetHashCode()
6867
}
6968
}
7069

71-
// TODO: check if this is needed:
7270
/// <summary>
7371
/// Overridden `ToString` method that will emit a string based on the string values of the nodes and edges
7472
/// on the path.

src/NRedisStack/Graph/GraphCacheList.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,4 @@ private void GetProcedureInfo()
5252
protected virtual ResultSet CallProcedure() =>
5353
graph.CallProcedure(GraphName, Procedure);
5454
}
55-
56-
internal class ReadOnlyGraphCacheList : GraphCacheList
57-
{
58-
internal ReadOnlyGraphCacheList(string graphName, string procedure, GraphCommands redisGraph) :
59-
base(graphName, procedure, redisGraph)
60-
{
61-
}
62-
63-
protected override ResultSet CallProcedure() =>
64-
graph.CallProcedureReadOnly(GraphName, Procedure);
65-
}
6655
}

src/NRedisStack/Graph/GraphCommandBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using NRedisStack.Literals;
22
using NRedisStack.RedisStackCommands;
3-
using static NRedisStack.Graph.RedisGraphUtilities;
43

54
namespace NRedisStack
65
{

src/NRedisStack/Graph/GraphCommands.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public async Task<ResultSet> RO_QueryAsync(string graphName, string query, long?
9797
internal static readonly Dictionary<string, List<string>> EmptyKwargsDictionary =
9898
new Dictionary<string, List<string>>();
9999

100-
// TODO: Check if needed
100+
// TODO: Check if this is needed:
101101
/// <inheritdoc/>
102102
public ResultSet CallProcedure(string graphName, string procedure) =>
103103
CallProcedure(graphName, procedure, Enumerable.Empty<string>(), EmptyKwargsDictionary);
@@ -147,32 +147,6 @@ public async Task<ResultSet> DeleteAsync(string graphName)
147147
return processedResult;
148148
}
149149

150-
// TODO: Check if this (CallProcedure) is needed
151-
/// <inheritdoc/>
152-
public ResultSet CallProcedureReadOnly(string graphName, string procedure) =>
153-
CallProcedureReadOnly(graphName, procedure, Enumerable.Empty<string>(), EmptyKwargsDictionary);
154-
155-
/// <inheritdoc/>
156-
public ResultSet CallProcedureReadOnly(string graphName, string procedure, IEnumerable<string> args) =>
157-
CallProcedureReadOnly(graphName, procedure, args, EmptyKwargsDictionary);
158-
159-
/// <inheritdoc/>
160-
public ResultSet CallProcedureReadOnly(string graphName, string procedure, IEnumerable<string> args, Dictionary<string, List<string>> kwargs)
161-
{
162-
args = args.Select(a => QuoteString(a));
163-
164-
var queryBody = new StringBuilder();
165-
166-
queryBody.Append($"CALL {procedure}({string.Join(",", args)})");
167-
168-
if (kwargs.TryGetValue("y", out var kwargsList))
169-
{
170-
queryBody.Append(string.Join(",", kwargsList));
171-
}
172-
173-
return RO_Query(graphName, queryBody.ToString());
174-
}
175-
176150
/// <inheritdoc/>
177151
public IReadOnlyList<string> Explain(string graphName, string query)
178152
{

src/NRedisStack/Graph/Header.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public enum ResultSetColumnTypes
2020
/// <summary>
2121
/// Collection of the schema types present in the header.
2222
/// </summary>
23-
// [Obsolete("SchemaType is no longer supported after RedisGraph 2.1 and will always return COLUMN_SCALAR")] // TODO: it's correct?
23+
[Obsolete("SchemaType is no longer supported after RedisGraph 2.1 and will always return COLUMN_SCALAR")]
2424
public List<ResultSetColumnTypes> SchemaTypes { get; }
2525

2626
/// <summary>
@@ -41,7 +41,6 @@ internal Header(RedisResult result)
4141
}
4242
}
4343

44-
// TODO: check if this is needed:
4544
public override bool Equals(object? obj)
4645
{
4746
if (obj == null) return this == null;

src/NRedisStack/Graph/IGraphCommands.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -133,34 +133,6 @@ public interface IGraphCommands
133133
/// <remarks><seealso href="https://redis.io/commands/graph.delete"/></remarks>
134134
Task<ResultSet> DeleteAsync(string graphName);
135135

136-
// TODO: Check if this (CallProcedure) is needed
137-
/// <summary>
138-
/// Call a saved procedure against a read-only node.
139-
/// </summary>
140-
/// <param name="graphName">The graph containing the saved procedure.</param>
141-
/// <param name="procedure">The procedure name.</param>
142-
/// <returns>A result set.</returns>
143-
ResultSet CallProcedureReadOnly(string graphName, string procedure);
144-
145-
/// <summary>
146-
/// Call a saved procedure with parameters against a read-only node.
147-
/// </summary>
148-
/// <param name="graphName">The graph containing the saved procedure.</param>
149-
/// <param name="procedure">The procedure name.</param>
150-
/// <param name="args">A collection of positional arguments.</param>
151-
/// <returns>A result set.</returns>
152-
ResultSet CallProcedureReadOnly(string graphName, string procedure, IEnumerable<string> args);
153-
154-
/// <summary>
155-
/// Call a saved procedure with parameters against a read-only node.
156-
/// </summary>
157-
/// <param name="graphName">The graph containing the saved procedure.</param>
158-
/// <param name="procedure">The procedure name.</param>
159-
/// <param name="args">A collection of positional arguments.</param>
160-
/// <param name="kwargs">A collection of keyword arguments.</param>
161-
/// <returns>A result set.</returns>
162-
ResultSet CallProcedureReadOnly(string graphName, string procedure, IEnumerable<string> args, Dictionary<string, List<string>> kwargs);
163-
164136
/// <summary>
165137
/// Constructs a query execution plan but does not run it. Inspect this execution plan to better understand how your
166138
/// query will get executed.

src/NRedisStack/Graph/Point.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public Point(List<double> values)
2323
this.longitude = values[1];
2424
}
2525

26-
// TODO: check if this is needed:
2726
public override bool Equals(object? obj)
2827
{
2928
if (obj == null) return this == null;

src/NRedisStack/Graph/Record.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ internal Record(List<string> header, List<object> values)
5858
/// </summary>
5959
public int Size => Header.Count;
6060

61-
// TODO: check if this is needed:
6261
public override bool Equals(object? obj)
6362
{
6463
if (obj == null) return this == null;

src/NRedisStack/Graph/RedisGraphUtilities.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,6 @@ internal static string PrepareQuery(string query, IDictionary<string, object> pa
2222
return preparedQuery.ToString();
2323
}
2424

25-
public static string ValueToStringNoQuotes(object value)
26-
{
27-
if (value == null)
28-
{
29-
return "null";
30-
}
31-
32-
if (value is IConvertible floatValue)
33-
{
34-
return ConvertibleToString(floatValue);
35-
}
36-
37-
return value.ToString();
38-
}
39-
4025
public static string ValueToString(object value)
4126
{
4227
if (value == null)

src/NRedisStack/Json/JsonCommandBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static SerializedCommand ArrPop(RedisKey key, string? path = null, long?
113113
throw new ArgumentException("index cannot be defined without path");
114114

115115
var args = AssembleNonNullArguments(key, path, index);
116-
return new SerializedCommand(JSON.ARRPOP, args)!; // TODO: understand the meaning of the '!' here
116+
return new SerializedCommand(JSON.ARRPOP, args)!;
117117
}
118118

119119
public static SerializedCommand ArrTrim(RedisKey key, string path, long start, long stop) =>

src/NRedisStack/Json/JsonCommands.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ public async Task<bool> SetAsync(RedisKey key, RedisValue path, RedisValue json,
250250
return (await _db.ExecuteAsync(JsonCommandBuilder.Set(key, path, json, when))).OKtoBoolean();
251251
}
252252

253-
/// <inheritdoc/> // TODO: check way asnyc methods dont have documenation
254253
public async Task<bool> SetFromFileAsync(RedisKey key, RedisValue path, string filePath, When when = When.Always)
255254
{
256255
if (!File.Exists(filePath))
@@ -262,7 +261,6 @@ public async Task<bool> SetFromFileAsync(RedisKey key, RedisValue path, string f
262261
return await SetAsync(key, path, fileContent, when);
263262
}
264263

265-
/// <inheritdoc/>
266264
public async Task<int> SetFromDirectoryAsync(RedisValue path, string filesPath, When when = When.Always)
267265
{
268266
int inserted = 0;
@@ -285,7 +283,6 @@ public async Task<int> SetFromDirectoryAsync(RedisValue path, string filesPath,
285283
return inserted;
286284
}
287285

288-
289286
public async Task<long?[]> StrAppendAsync(RedisKey key, string value, string? path = null)
290287
{
291288
return (await _db.ExecuteAsync(JsonCommandBuilder.StrAppend(key, value, path))).ToNullableLongArray();

src/NRedisStack/Search/AggregationRequest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ public AggregationRequest Limit(int offset, int count)
5252
return this;
5353
}
5454

55-
public AggregationRequest Limit(int count)
56-
{
57-
return Limit(0, count);
58-
}
55+
public AggregationRequest Limit(int count) => Limit(0, count);
56+
57+
public AggregationRequest SortBy(string property) => SortBy(SortedField.Asc(property));
5958

6059
public AggregationRequest SortBy(params SortedField[] Fields)
6160
{

src/NRedisStack/Search/AggregationResult.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
2626
{
2727
var key = (string)raw[j++];
2828
var val = raw[j++];
29-
if (val.Type != ResultType.MultiBulk)
30-
cur.Add(key, (RedisValue)val);
29+
if (val.Type == ResultType.MultiBulk)
30+
continue; // TODO: handle multi-bulk (maybe change to object?)
31+
cur.Add(key, (RedisValue)val);
3132
}
3233
_results[i - 1] = cur;
3334
}

src/NRedisStack/Search/DataTypes/InfoResult.cs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ public class InfoResult
99

1010
public string IndexName => GetString("index_name");
1111
public Dictionary<string, RedisResult> IndexOption => GetRedisResultDictionary("index_options");
12-
public Dictionary<string, RedisResult[]> IndexDefinition => GetRedisResultsDictionary("index_definition");
1312

14-
// public Dictionary<string, RedisResult[]> Attributes => GetRedisResultsDictionary("attributes"); // TODO: check if this is correct
15-
public Dictionary<string, RedisResult>[] Attributes => GetRedisResultDictionaryArray("attributes"); // TODO: check if this is correct
13+
public Dictionary<string, RedisResult>[] Attributes => GetRedisResultDictionaryArray("attributes");
1614

1715

1816
public long NumDocs => GetLong("num_docs");
@@ -122,25 +120,6 @@ private Dictionary<string, RedisResult> GetRedisResultDictionary(string key)
122120
}
123121
}
124122

125-
private Dictionary<string, RedisResult[]> GetRedisResultsDictionary(string key)
126-
{
127-
if (_all.TryGetValue(key, out var value))
128-
{
129-
var result = new Dictionary<string, RedisResult[]>();
130-
131-
foreach (RedisResult[] fv in (RedisResult[])value)
132-
{
133-
result.Add((string)fv[0], fv);
134-
}
135-
136-
return result;
137-
}
138-
else
139-
{
140-
return default;
141-
}
142-
}
143-
144123
private Dictionary<string, RedisResult>[] GetRedisResultDictionaryArray(string key)
145124
{
146125
if (_all.TryGetValue(key, out var value))
@@ -165,25 +144,5 @@ private Dictionary<string, RedisResult>[] GetRedisResultDictionaryArray(string k
165144
return default;
166145
}
167146
}
168-
// private Dictionary<string, RedisResult>[] GetRedisResultsDictionaryTry(string key)
169-
// {
170-
// if (_all.TryGetValue(key, out var value))
171-
// {
172-
// var result = new List<Dictionary<string, RedisResult>>();
173-
174-
// int i = 0;
175-
// foreach (RedisResult[] fv in (RedisResult[])value)
176-
// {
177-
// var res = GetRedisResultDictionary((string)fv[i++]);
178-
// result.Add(res);
179-
// }
180-
181-
// return result.ToArray();
182-
// }
183-
// else
184-
// {
185-
// return default;
186-
// }
187-
// }
188147
}
189148
}

src/NRedisStack/Search/DataTypes/SearchInformation.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)