Skip to content

Commit 043dd5d

Browse files
committed
added another tests
tests
1 parent 0959f95 commit 043dd5d

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using CodeBug.CountryProvider.Constants;
2+
using CodeBug.CountryProvider.Interfaces;
3+
using CodeBug.CountryProvider.Services;
4+
using CodeBug.CountryProvider.Tests.Generator;
5+
using CodeBug.CountryProvider.Utils;
6+
using NSubstitute;
7+
using NUnit.Framework;
8+
using System;
9+
10+
namespace CodeBug.CountryProvider.Tests.Utils
11+
{
12+
public class CountryQueryVisitorTests
13+
{
14+
[Test]
15+
public void Visit_NullSent_ThrowsException()
16+
{
17+
var queryValidator = Substitute.For<IQueryValidator>();
18+
var countryQueryVistor = new CountryQueryVisitor(queryValidator);
19+
Assert.Throws<ArgumentNullException>(() => countryQueryVistor.Visit(null));
20+
}
21+
22+
[Test]
23+
public void Visit_CorrectQueryGiven_SearchingByFieldPopulated()
24+
{
25+
var query = QueryExpressionGenerator.GenerateQueryExpressionWithCorrectCondtion();
26+
var queryValidator = Substitute.For<IQueryValidator>();
27+
var countryQueryVisitor = new CountryQueryVisitor(queryValidator);
28+
29+
queryValidator.Validate().Returns(true);
30+
31+
countryQueryVisitor.Visit(query);
32+
33+
Assert.IsNotNull(countryQueryVisitor.SearchingBy);
34+
Assert.IsNotNull(countryQueryVisitor.SearchedTerm);
35+
Assert.IsTrue(countryQueryVisitor.SearchingBy == CountrySchemaNames.Region);
36+
Assert.IsTrue(countryQueryVisitor.SearchedTerm == "Hello");
37+
}
38+
39+
[Test]
40+
public void Visit_CorrectQueryGiven_SearchingByFieldHasDefault()
41+
{
42+
var query = QueryExpressionGenerator.GenerateQueryExpressionWithMultipleCondition();
43+
var queryValidator = Substitute.For<IQueryValidator>();
44+
var countryQueryVisitor = new CountryQueryVisitor(queryValidator);
45+
46+
queryValidator.Validate().Returns(false);
47+
48+
countryQueryVisitor.Visit(query);
49+
50+
Assert.IsTrue(countryQueryVisitor.SearchingBy == "all");
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)