Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moq -> Nsubstitute #410

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
279 changes: 131 additions & 148 deletions test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs

Large diffs are not rendered by default.

389 changes: 194 additions & 195 deletions test/Redis.OM.Unit.Tests/RediSearchTests/ApplyFunctionTests.cs

Large diffs are not rendered by default.

81 changes: 40 additions & 41 deletions test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Moq;
using System;
using System;
using System.Linq;
using NSubstitute;
using Redis.OM.Aggregation;
using Redis.OM.Aggregation.AggregationPredicates;
using Redis.OM.Contracts;
using Redis.OM;
using Redis.OM.Modeling;
using Xunit;

namespace Redis.OM.Unit.Tests.RediSearchTests
{
public class FilterPredicateTest
{
Mock<IRedisConnection> _mock = new Mock<IRedisConnection>();
RedisReply _mockReply = new RedisReply[]
private readonly IRedisConnection _substitute = Substitute.For<IRedisConnection>();
RedisReply _mockReply = new []
{
new RedisReply(1),
new RedisReply(new RedisReply[]
Expand All @@ -27,14 +26,14 @@ public class FilterPredicateTest
public void TestBasicFilter()
{
var expectedPredicate = "5 < 6";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var five = 5;
var six = 6;
Expand All @@ -48,75 +47,75 @@ public void TestBasicFilter()
public void TestBasicFilterString()
{
var expectedPredicate = "@Name == 'steve'";
_mock.Setup(x => x.Execute(
"FT.AGGREGATE",It.IsAny<string[]>()
))
_substitute.Execute(
"FT.AGGREGATE",Arg.Any<string[]>()
)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x=>x.RecordShell.Name == "steve").ToArray();

_mock.Verify(x=>x.Execute("FT.AGGREGATE",
_substitute.Received().Execute("FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate));
expectedPredicate);
Assert.Equal("Blah", res[0]["FakeResult"]);
}

[Fact]
public void TestBasicFilterStringUnpackedFromVariable()
{
var expectedPredicate = "@Name == 'steve'";
_mock.Setup(x => x.Execute(
"FT.AGGREGATE",It.IsAny<string[]>()
))
_substitute.Execute(
"FT.AGGREGATE",Arg.Any<string[]>()
)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var steve = "steve";
var res = collection.Filter(x=>x.RecordShell.Name == steve).ToArray();

_mock.Verify(x=>x.Execute("FT.AGGREGATE",
_substitute.Received().Execute("FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate));
expectedPredicate);
Assert.Equal("Blah", res[0]["FakeResult"]);
}

[Fact]
public void TestBasicFilterNullableString()
{
var expectedPredicate = "@NullableStringField == 'steve'";
_mock.Setup(x => x.Execute(
"FT.AGGREGATE",It.IsAny<string[]>()
))
_substitute.Execute(
"FT.AGGREGATE",Arg.Any<string[]>()
)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x=>x.RecordShell.NullableStringField == "steve").ToArray();

_mock.Verify(x=>x.Execute("FT.AGGREGATE",
_substitute.Received().Execute("FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate));
expectedPredicate);
Assert.Equal("Blah", res[0]["FakeResult"]);
}

[Fact]
public void TestFilterSingleIdentifier()
{
var expectedPredicate = "@Age < 6";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x => x.RecordShell.Age < 6).ToArray();

Expand All @@ -127,14 +126,14 @@ public void TestFilterSingleIdentifier()
public void TestFilterMathFunctions()
{
var expectedPredicate = "abs(@Age) < 6";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x => Math.Abs((int)x.RecordShell.Age) < 6).ToArray();

Expand All @@ -145,14 +144,14 @@ public void TestFilterMathFunctions()
public void TestFilterGeoFunctions()
{
var expectedPredicate = "geodistance(@Home,@Work) < 6";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x => ApplyFunctions.GeoDistance((GeoLoc)x.RecordShell.Home, (GeoLoc)x.RecordShell.Work) < 6).ToArray();

Expand All @@ -163,14 +162,14 @@ public void TestFilterGeoFunctions()
public void TestFilterStringFunction()
{
var expectedPredicate = "contains(@Name,\"ste\")";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x => x.RecordShell.Name.Contains("ste")).ToArray();

Expand All @@ -181,14 +180,14 @@ public void TestFilterStringFunction()
public void TestFilterDatetimeFunction()
{
var expectedPredicate = "dayofweek(@LastTimeOnline) < 6";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"FILTER",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.Filter(x => ApplyFunctions.DayOfWeek((long)x.RecordShell.LastTimeOnline) < 6).ToArray();

Expand Down
62 changes: 28 additions & 34 deletions test/Redis.OM.Unit.Tests/RediSearchTests/GroupByTests.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
using NSubstitute;
using Redis.OM.Aggregation;
using Redis.OM.Contracts;
using Redis.OM;
using Xunit;

namespace Redis.OM.Unit.Tests.RediSearchTests
{
public class GroupByTests
{
Mock<IRedisConnection> _mock = new Mock<IRedisConnection>();
RedisReply _mockReply = new RedisReply[]
private readonly IRedisConnection _substitute = Substitute.For<IRedisConnection>();
private readonly RedisReply _mockReply = new []
{
new RedisReply(1),
new RedisReply(new RedisReply[]
Expand All @@ -28,15 +23,15 @@ public class GroupByTests
public void TestSimpleGroupBy()
{
var expectedPredicate = "@Name";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"1",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.GroupBy(x=>x.RecordShell.Name).ToArray();

Expand All @@ -46,15 +41,14 @@ public void TestSimpleGroupBy()
[Fact]
public void TestSimpleGroupBy0()
{
var expectedPredicate = "@Name";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"0"))
"0")
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.GroupBy(x=>new{}).ToArray();

Expand All @@ -65,15 +59,15 @@ public void TestSimpleGroupBy0()
public void TestSimpleGroupByCloseGroup()
{
var expectedPredicate = "@Name";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"1",
expectedPredicate))
expectedPredicate)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection.GroupBy(x=>x.RecordShell.Name).CloseGroup().ToArray();

Expand All @@ -85,16 +79,16 @@ public void TestGrouby2Fields()
{
var expectedPredicate1 = "@Name";
var expectedPredicate2 = "@Age";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"2",
expectedPredicate1,
expectedPredicate2))
expectedPredicate2)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection
.GroupBy(x => x.RecordShell.Name)
Expand All @@ -105,20 +99,20 @@ public void TestGrouby2Fields()
}

[Fact]
public void TestGrouby2FieldsAnon()
public void TestGroupby2FieldsAnon()
{
var expectedPredicate1 = "@Name";
var expectedPredicate2 = "@Age";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"2",
expectedPredicate1,
expectedPredicate2))
expectedPredicate2)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection
.GroupBy(x => new {x.RecordShell.Name, x.RecordShell.Age})
Expand All @@ -128,20 +122,20 @@ public void TestGrouby2FieldsAnon()
}

[Fact]
public void TestGrouby2FieldsAnonAggregation()
public void TestGroupby2FieldsAnonAggregation()
{
var expectedPredicate1 = "@Name";
var expectedPredicate2 = "@AggAge";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"2",
expectedPredicate1,
expectedPredicate2))
expectedPredicate2)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection
.GroupBy(x => new {x.RecordShell.Name, AggAge = x["AggAge"]})
Expand All @@ -151,20 +145,20 @@ public void TestGrouby2FieldsAnonAggregation()
}

[Fact]
public void TestGrouby2FieldsOneFromPipeline()
public void TestGroupby2FieldsOneFromPipeline()
{
var expectedPredicate1 = "@Name";
var expectedPredicate2 = "@blah";
_mock.Setup(x => x.Execute(
_substitute.Execute(
"FT.AGGREGATE",
"person-idx",
"*",
"GROUPBY",
"2",
expectedPredicate1,
expectedPredicate2))
expectedPredicate2)
.Returns(_mockReply);
var collection = new RedisAggregationSet<Person>(_mock.Object);
var collection = new RedisAggregationSet<Person>(_substitute);

var res = collection
.GroupBy(x => x.RecordShell.Name)
Expand Down
Loading
Loading