Skip to content

Commit

Permalink
Update test according to tips from xUnit Analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
gjunge committed Jan 24, 2018
1 parent 9e020eb commit 32ae2ad
Show file tree
Hide file tree
Showing 32 changed files with 147 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void Clear() {
var inst2 = new ServiceImpl();
container.Register<IService>(c => inst2);
container.Clear();
Assert.Equal(0, container.GetAllInstances<IService>().ToArray().Length);
Assert.Empty(container.GetAllInstances<IService>().ToArray());
}

protected override IServiceLocator CreateServiceLocator() {
Expand Down
4 changes: 2 additions & 2 deletions CommonServiceLocator.SolrNet.Tests/ServiceLocatorTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public void AskingForInvalidComponentShouldRaiseActivationException() {
[Fact]
public void GetNamedInstance() {
var instance = locator.GetInstance<ILogger>(typeof (AdvancedLogger).FullName);
Assert.IsType(typeof (AdvancedLogger), instance);
Assert.IsType<AdvancedLogger>(instance);
}

[Fact]
public void GetNamedInstance2() {
var instance = locator.GetInstance<ILogger>(typeof (SimpleLogger).FullName);
Assert.IsType(typeof (SimpleLogger), instance);
Assert.IsType<SimpleLogger>(instance);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void ResolveSolrAbstractResponseParsersViaEnumerable()
//MS Dependency injection doesn't support
var result = DefaultServiceProvider.GetRequiredService<IEnumerable<ISolrAbstractResponseParser<Entity>>>();
Assert.NotNull(result);
Assert.Equal(result.Count(), 1);
Assert.Single(result);

}

Expand All @@ -109,4 +109,4 @@ public void ResolveSolrOperations()

public class Entity { }
}
}
}
3 changes: 1 addition & 2 deletions SolrNet.Cloud.Tests/CollectionsAdminTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public async Task ModifyCollection()
Assert.True(response.Status == 0);
}

//[Fact]
// causes internal server error (one shard, two shards - doesn't matter)
[Fact(Skip = "causes internal server error (one shard, two shards - doesn't matter)")]
public async Task SplitShard()
{
RemoveCollectionIfExists(collections, COLLECTION_NAME);
Expand Down
2 changes: 1 addition & 1 deletion SolrNet.Cloud.Tests/SolrCloudOperationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void ShouldRedirectToProvidedOperations() {
var provider = new FakeProvider();
var operations = new SolrCloudOperations<FakeEntity>(provider, provider);
operations.Commit();
Assert.Equal(provider.LastOperation , "Commit");
Assert.Equal("Commit", provider.LastOperation );
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions SolrNet.Cloud.Tests/SolrClusterStateParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public void ShouldProduceNotEmptyStateFromNotEmptyJson() {
Assert.True(collections.Any());
var shards = collections.SelectMany(collection => collection.Shards.Values).ToList();
Assert.True(shards.Any());
Assert.True(shards.Any(shard => shard.IsActive));
Assert.Contains(shards, shard => shard.IsActive);
var replicas = shards.SelectMany(shard => shard.Replicas.Values).ToList();
Assert.True(replicas.Any());
Assert.True(replicas.Any(replica => replica.IsActive));
Assert.True(replicas.Any(replica => replica.IsLeader));
Assert.Contains(replicas, replica => replica.IsActive);
Assert.Contains(replicas, replica => replica.IsLeader);
}

[Fact]
Expand All @@ -55,4 +55,4 @@ public void ShouldProduceMergedStateFromSeveralJson() {
Assert.Equal(zkState.Collections.Count, totalCollectionsCount);
}
}
}
}
20 changes: 10 additions & 10 deletions SolrNet.Tests.Integration/IntegrationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void Add_then_query() {

solr.Query(new SolrQueryByField("name", @"3;Furniture"));
var products = solr.Query(new SolrQueryByRange<decimal>("price", 10m, 100m).Boost(2));
Assert.Equal(1, products.Count);
Assert.Single(products);
Assert.Equal(name, products[0].Name);
Assert.Equal("SP2514N", products[0].Id);
Assert.Equal(guid, products[0].Guid);
Expand Down Expand Up @@ -192,7 +192,7 @@ public void DeleteByIdAndOrQuery() {
solr.Commit();
var productsAfterDelete = solr.Query(SolrQuery.All);

Assert.Equal(0, productsAfterDelete.Count);
Assert.Empty(productsAfterDelete);
}


Expand Down Expand Up @@ -391,7 +391,7 @@ public void LocalParams() {
Add_then_query();
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = solr.Query(new LocalParams {{"q.op", "AND"}} + "solr ipod");
Assert.Equal(0, results.Count);
Assert.Empty(results);
}

[Fact]
Expand Down Expand Up @@ -477,7 +477,7 @@ public void FieldGrouping()

Console.WriteLine("Group.Count {0}", results.Grouping.Count);
Assert.Equal(1, results.Grouping.Count);
Assert.Equal(true, results.Grouping.ContainsKey("manu_exact"));
Assert.True(results.Grouping.ContainsKey("manu_exact"));
Assert.True(results.Grouping["manu_exact"].Groups.Count>=1);
}

Expand All @@ -497,8 +497,8 @@ public void QueryGrouping()

Console.WriteLine("Group.Count {0}", results.Grouping.Count);
Assert.Equal(2, results.Grouping.Count);
Assert.Equal(true, results.Grouping.ContainsKey("manu_exact"));
Assert.Equal(true, results.Grouping.ContainsKey("name"));
Assert.True(results.Grouping.ContainsKey("manu_exact"));
Assert.True(results.Grouping.ContainsKey("name"));
Assert.True (results.Grouping["manu_exact"].Groups.Count >= 1);
Assert.True(results.Grouping["name"].Groups.Count >= 1);
}
Expand All @@ -515,7 +515,7 @@ public void SemiLooseMapping() {
var _ = initLoose.Value;
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<ProductLoose>>();
var products = solr.Query(SolrQuery.All, new QueryOptions {Fields = new[] {"*", "score"}});
Assert.Equal(1, products.Count);
Assert.Single(products);
var product = products[0];
Assert.Equal("SP2514N", product.Id);
Assert.True(product.Score.HasValue);
Expand All @@ -526,9 +526,9 @@ public void SemiLooseMapping() {
Console.WriteLine(product.OtherFields.Count);
foreach (var field in product.OtherFields)
Console.WriteLine("{0}: {1} ({2})", field.Key, field.Value, TypeOrNull(field.Value));
Assert.IsType(typeof(DateTime), product.OtherFields["timestamp"]);
Assert.IsType<DateTime>(product.OtherFields["timestamp"]);
Assert.Equal(new DateTime(1,1,1), product.OtherFields["timestamp"]);
Assert.IsAssignableFrom(typeof(ICollection), product.OtherFields["features"]);
Assert.IsAssignableFrom<ICollection>(product.OtherFields["features"]);
product.OtherFields["timestamp"] = new DateTime(2010, 1, 1);
product.OtherFields["features"] = new[] {"a", "b", "c"};
product.OtherFields.Remove("_version_"); // avoid optimistic locking for now https://issues.apache.org/jira/browse/SOLR-3178
Expand Down Expand Up @@ -610,4 +610,4 @@ public void AtomicUpdate()
Assert.False(productAfterUpdate.Features.Contains("hard drive"));
}
}
}
}
20 changes: 10 additions & 10 deletions SolrNet.Tests.Integration/IntegrationFixtureAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task Add_then_queryAsync()

await solr.QueryAsync(new SolrQueryByField("name", @"3;Furniture"));
var products = await solr.QueryAsync(new SolrQueryByRange<decimal>("price", 10m, 100m).Boost(2));
Assert.Equal(1, products.Count);
Assert.Single(products);
Assert.Equal(name, products[0].Name);
Assert.Equal("SP2514N", products[0].Id);
Assert.Equal(guid, products[0].Guid);
Expand Down Expand Up @@ -200,7 +200,7 @@ public async Task DeleteByIdAndOrQueryAsync()
await solr.CommitAsync();
var productsAfterDelete = await solr.QueryAsync(SolrQuery.All);

Assert.Equal(0, productsAfterDelete.Count);
Assert.Empty(productsAfterDelete);
}


Expand Down Expand Up @@ -435,7 +435,7 @@ public async Task LocalParamsAsync()
await Add_then_queryAsync();
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = await solr.QueryAsync(new LocalParams { { "q.op", "AND" } } + "solr ipod");
Assert.Equal(0, results.Count);
Assert.Empty(results);
}

[Fact]
Expand Down Expand Up @@ -531,7 +531,7 @@ public async Task FieldGroupingAsync()

Console.WriteLine("Group.Count {0}", results.Grouping.Count);
Assert.Equal(1, results.Grouping.Count);
Assert.Equal(true, results.Grouping.ContainsKey("manu_exact"));
Assert.True(results.Grouping.ContainsKey("manu_exact"));
Assert.True(results.Grouping["manu_exact"].Groups.Count >= 1);
}

Expand All @@ -551,8 +551,8 @@ public async Task QueryGroupingAsync()

Console.WriteLine("Group.Count {0}", results.Grouping.Count);
Assert.Equal(2, results.Grouping.Count);
Assert.Equal(true, results.Grouping.ContainsKey("manu_exact"));
Assert.Equal(true, results.Grouping.ContainsKey("name"));
Assert.True(results.Grouping.ContainsKey("manu_exact"));
Assert.True(results.Grouping.ContainsKey("name"));
Assert.True(results.Grouping["manu_exact"].Groups.Count >= 1);
Assert.True(results.Grouping["name"].Groups.Count >= 1);
}
Expand All @@ -571,7 +571,7 @@ public async Task SemiLooseMappingAsync()
var _ = initLoose.Value;
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<ProductLoose>>();
var products = await solr.QueryAsync(SolrQuery.All, new QueryOptions { Fields = new[] { "*", "score" } });
Assert.Equal(1, products.Count);
Assert.Single(products);
var product = products[0];
Assert.Equal("SP2514N", product.Id);
Assert.True(product.Score.HasValue);
Expand All @@ -582,9 +582,9 @@ public async Task SemiLooseMappingAsync()
Console.WriteLine(product.OtherFields.Count);
foreach (var field in product.OtherFields)
Console.WriteLine("{0}: {1} ({2})", field.Key, field.Value, TypeOrNull(field.Value));
Assert.IsType(typeof(DateTime), product.OtherFields["timestamp"]);
Assert.IsType<DateTime>(product.OtherFields["timestamp"]);
Assert.Equal(new DateTime(1, 1, 1), product.OtherFields["timestamp"]);
Assert.IsAssignableFrom(typeof(ICollection), product.OtherFields["features"]);
Assert.IsAssignableFrom<ICollection>(product.OtherFields["features"]);
product.OtherFields["timestamp"] = new DateTime(2010, 1, 1);
product.OtherFields["features"] = new[] { "a", "b", "c" };
product.OtherFields.Remove("_version_"); // avoid optimistic locking for now https://issues.apache.org/jira/browse/SOLR-3178
Expand Down Expand Up @@ -647,4 +647,4 @@ public async Task MoreLikeThisHandlerAsync()

}
}
}
}
14 changes: 7 additions & 7 deletions SolrNet.Tests.Integration/SolrCoreAdminFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void Create() {
} catch (ArgumentException) {
// Should get an Exception here because instance directory was not specified.
var createResponseHeader = solrCoreAdmin.Create(coreName, instanceDir);
Assert.Equal(createResponseHeader.Status, 0);
Assert.Equal(0, createResponseHeader.Status);
}

var result = solrCoreAdmin.Status(coreName);
Expand All @@ -85,7 +85,7 @@ public void ReloadCore() {
var solrCoreAdmin = new SolrCoreAdmin( new SolrConnection( solrUrl ), GetHeaderParser(), GetStatusResponseParser() );

var reloadResponseHeader = solrCoreAdmin.Reload(coreName);
Assert.Equal(reloadResponseHeader.Status, 0);
Assert.Equal(0, reloadResponseHeader.Status);
}

[Fact(Skip = "Our version of solr doesn't support this") ]
Expand All @@ -94,7 +94,7 @@ public void Alias() {
var solrCoreAdmin = new SolrCoreAdmin( new SolrConnection( solrUrl ), GetHeaderParser(), GetStatusResponseParser() );

var aliasResponseHeader = solrCoreAdmin.Alias(coreName, "corefoo");
Assert.Equal(aliasResponseHeader.Status, 0);
Assert.Equal(0, aliasResponseHeader.Status);
}

[Fact]
Expand All @@ -103,7 +103,7 @@ public void CreateSwapCore() {
var solrCoreAdmin = new SolrCoreAdmin( new SolrConnection( solrUrl ), GetHeaderParser(), GetStatusResponseParser() );

var createResponseHeader = solrCoreAdmin.Create(coreName, instanceDir);
Assert.Equal(createResponseHeader.Status, 0);
Assert.Equal(0, createResponseHeader.Status);
var result = solrCoreAdmin.Status(coreName);
Assert.NotNull(result);
Assert.NotEmpty(result.Name);
Expand All @@ -115,7 +115,7 @@ public void SwapCores() {
var solrCoreAdmin = new SolrCoreAdmin( new SolrConnection( solrUrl ), GetHeaderParser(), GetStatusResponseParser() );

var swapResponseHeader = solrCoreAdmin.Swap("core-new", "core-swap");
Assert.Equal(swapResponseHeader.Status, 0);
Assert.Equal(0, swapResponseHeader.Status);
}

[Fact]
Expand All @@ -126,7 +126,7 @@ public void Unload() {
//Assert.Equal(swapUnloadResponseHeader.Status, 0);

var newUnloadResponseHeader = solrCoreAdmin.Unload("core-new", UnloadCommand.Delete.Index);
Assert.Equal(newUnloadResponseHeader.Status, 0);
Assert.Equal(0, newUnloadResponseHeader.Status);
}
}
}
}
6 changes: 3 additions & 3 deletions SolrNet.Tests/CollapseExpandResponseParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public void Parse2()
Assert.Equal(4, results.CollapseExpand.Groups.Count);

var group = results.CollapseExpand.Groups.ElementAt(0);
Assert.Equal(group.Documents.Count, 2);
Assert.Equal(group.GroupValue, "First");
Assert.Equal(group.NumFound, 2);
Assert.Equal(2, group.Documents.Count);
Assert.Equal("First", group.GroupValue);
Assert.Equal(2, group.NumFound);
}

class Doc {}
Expand Down
2 changes: 1 addition & 1 deletion SolrNet.Tests/CollectionFieldSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CollectionFieldSerializerTests {
public void Serialize_null_returns_empty() {
var s = new CollectionFieldSerializer(new DefaultFieldSerializer());
var p = s.Serialize(null).ToList();
Assert.Equal(0, p.Count);
Assert.Empty(p);
}

[Fact]
Expand Down
6 changes: 3 additions & 3 deletions SolrNet.Tests/DebugResponseParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ParseDebugResponse()
var results = new SolrQueryResults<object>();
parser.Parse(xml, results);

Assert.Equal(0, results.Count);
Assert.Empty(results);
Assert.True(results.Debug is DebugResults.PlainDebugResults);
Assert.NotNull(results.Debug.Timing);
Assert.Equal(15, results.Debug.Timing.TotalTime);
Expand All @@ -32,7 +32,7 @@ public void ParseResponseWithSimpleDebugExplanation()
var results = new SolrQueryResults<object>();
parser.Parse(xml, results);

Assert.Equal(0, results.Count);
Assert.Empty(results);
Assert.True(results.Debug is DebugResults.PlainDebugResults);
Assert.NotNull(results.Debug.Explanation);
Assert.Equal(2, results.Debug.Explanation.Count);
Expand All @@ -47,7 +47,7 @@ public void ParseResponseWithStructuredDebugExplanation()
parser.Parse(xml, results);
var debugData = results.Debug;

Assert.Equal(0, results.Count);
Assert.Empty(results);
Assert.NotNull(results.Debug.Explanation);
Assert.True(results.Debug is DebugResults.StructuredDebugResults);

Expand Down
4 changes: 2 additions & 2 deletions SolrNet.Tests/DefaultFieldParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void ParseNullableInt() {
doc.Add(new XElement("int", "31"));
var p = new DefaultFieldParser();
var i = p.Parse(doc.Root, typeof (int?));
Assert.IsAssignableFrom(typeof(int?), i);
Assert.IsType(typeof(int), i);
Assert.IsAssignableFrom<int?>(i);
Assert.IsType<int>(i);
var ii = (int?) i;
Assert.True(ii.HasValue);
Assert.Equal(31, ii.Value);
Expand Down
4 changes: 2 additions & 2 deletions SolrNet.Tests/DefaultResponseParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ParseResponseWithLocation() {
var xml = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.response.xml");
var results = new SolrQueryResults<Doc>();
parser.Parse(xml, results);
Assert.Equal(1, results.Count);
Assert.Single(results);
Assert.Equal(new Location(51.5171, -0.1062), results[0].Loc);
}

Expand All @@ -31,7 +31,7 @@ public void Parse_If_Both_Result_And_Groups_Are_Present()
var xml = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.responseWithResultAndGroup.xml");
var results = new SolrQueryResults<TestDoc>();
parser.Parse(xml, results);
Assert.Equal(1, results.Count);
Assert.Single(results);
Assert.Equal(1, results.Grouping["titleId"].Ngroups);
}
}
Expand Down
2 changes: 1 addition & 1 deletion SolrNet.Tests/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ExceptionTests {
public void All_exceptions_are_serializable() {
var allExceptions = typeof (SolrNetException).Assembly.GetTypes().Where(t => typeof (SolrNetException).IsAssignableFrom(t));
foreach (var e in allExceptions) {
Assert.IsAssignableFrom(typeof(System.Runtime.Serialization.ISerializable), e);
Assert.IsAssignableFrom<System.Runtime.Serialization.ISerializable>(e);
}
}
}
Expand Down
Loading

0 comments on commit 32ae2ad

Please sign in to comment.