Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
scottbommarito committed Apr 28, 2017
2 parents ca3627d + 02ca2e4 commit f337fac
Show file tree
Hide file tree
Showing 10 changed files with 373 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
<Compile Include="Models\PackageVersion.cs" />
<Compile Include="Models\SearchDiagResult.cs" />
<Compile Include="Models\RegistrationCursor.cs" />
<Compile Include="Models\SearchResultEntry.cs" />
<Compile Include="Models\V2PackageRegistration.cs" />
<Compile Include="Models\V2SearchResultEntry.cs" />
<Compile Include="Models\V3SearchResultEntry.cs" />
<Compile Include="Models\ServiceEndpoint.cs" />
<Compile Include="Models\ServiceEndpointsList.cs" />
<Compile Include="TestSupport\RetryHandler.cs" />
Expand Down
7 changes: 7 additions & 0 deletions tests/BasicSearchTests.FunctionalTests.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ namespace BasicSearchTests.FunctionalTests.Core
public static class Constants
{
// Predefined Texts
public const string TestPackageId = "BaseTestPackage";
public const string TestPackageVersion = "1.0.0";
public const string TestPackageTitle = "BaseTestPackage";
public const string TestPackageDescription = "Package description";
public const string TestPackageSummary = "";
public const string TestPackageAuthor = "clayco";
public const string TestPackageCopyright = "Copyright 2013";
public const string NonExistentSearchString = "RandomCharacters234asdfa433";
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace BasicSearchTests.FunctionalTests.Core.Models
{
public class V2PackageRegistration
{
public string Id { get; set; }

public long DownloadCount { get; set; }

public IList<string> Owners { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Newtonsoft.Json;
using System;
using System.Collections.Generic;

Expand All @@ -14,6 +15,6 @@ public class V2SearchResult

public string Index { get; set; }

public IList<object> Data { get; set; }
public IList<V2SearchResultEntry> Data { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Newtonsoft.Json;
using System;

namespace BasicSearchTests.FunctionalTests.Core.Models
{
public class V2SearchResultEntry
{
public V2PackageRegistration PackageRegistration { get; set; }

[JsonProperty(Required = Required.Always)]
public string Version { get; set; }

[JsonProperty(Required = Required.Always)]
public string NormalizedVersion { get; set; }

public string Title { get; set; }

public string Description { get; set; }

public string Summary { get; set; }

public string Authors { get; set; }

public string Copyright { get; set; }

public string Language { get; set; }

public string Tags { get; set; }

public string ReleaseNotes { get; set; }

public string ProjectUrl { get; set; }

public string IconUrl { get; set; }

public bool IsLatestStable { get; set; }

public bool IsLatest { get; set; }

public bool Listed { get; set; }

public DateTime Created { get; set; }

public DateTime Published { get; set; }

public DateTime LastUpdated { get; set; }

public DateTime? LastEdited { get; set; }

public long DownloadCount { get; set; }

public string FlattenedDependencies { get; set; }

public object[] Dependencies { get; set; }

public string[] SupportedFrameworks { get; set; }

public string Hash { get; set; }

public string HashAlgorithm { get; set; }

public long PackageFileSize { get; set; }

public string LicenseUrl { get; set; }

public bool RequireslicenseAcceptance { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class V3SearchResult

public string Index { get; set; }

public IList<SearchResultEntry> Data { get; set; }
public IList<V3SearchResultEntry> Data { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Newtonsoft.Json;

namespace BasicSearchTests.FunctionalTests.Core.Models
{
public class V3SearchResultEntry
{
[JsonProperty("@id")]
public string AtId { get; set; }

[JsonProperty("@type")]
public string AtType { get; set; }

public string Registration { get; set; }

[JsonProperty(Required = Required.Always)]
public string Id { get; set; }

[JsonProperty(Required = Required.Always)]
public string Version { get; set; }

public string Description { get; set; }

public string Summary { get; set; }

public string Title { get; set; }

public string IconUrl { get; set; }

public string LicenseUrl { get; set; }

public string ProjectUrl { get; set; }

public string[] Tags { get; set; }

public string[] Authors { get; set; }

public long TotalDownloads { get; set; }

public PackageVersion[] Versions { get; set; }

}
}
111 changes: 111 additions & 0 deletions tests/BasicSearchTests.FunctionalTests.Core/V2SearchFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using BasicSearchTests.FunctionalTests.Core.TestSupport;
using Xunit;
using System.Net;
using Newtonsoft.Json;
using System.Linq;
using System;

namespace BasicSearchTests.FunctionalTests.Core
{
Expand Down Expand Up @@ -37,5 +40,113 @@ public async Task ShouldGetResultsForEmptyString()
Assert.True(result.TotalHits.HasValue && result.TotalHits.Value > 0, "No results found, should find atleast some results for empty string query.");
Assert.NotNull(result.Data);
}

[Fact]
public void ShouldThrowExceptionForInvalidSearchResults()
{
var content = @"{
'totalHits': 1,
'index': 'C:\\NuGetSearchData\\Lucene-v2v3',
'indexTimestamp': '1/23/2000 1:23:45 AM',
'data': [
{
}
]
}";

// Assert that a JsonSerializationException is thrown if the search results
// are missing required fields.
Assert.Throws<JsonSerializationException>(() =>
{
JsonConvert.DeserializeObject<V2SearchResult>(content);
});
}

[Fact]
public async Task EmptyQueryResultHaveRequiredProperties()
{
// Act
var response = await Client.GetAsync(new V2SearchBuilder().RequestUri);
var content = await response.Content.ReadAsStringAsync();

// Assert that all required properties are present in the search result by
// deserializing the response. An exception will be thrown if required fields
// are missing.
Assert.Null(Record.Exception(() =>
{
JsonConvert.DeserializeObject<V2SearchResult>(content);
}));
}

[Fact]
public async Task EnsureTestPackageIsValid()
{
// Act
var response = await Client.GetAsync(new V2SearchBuilder() { Query = Constants.TestPackageId }.RequestUri);
var result = await response.Content.ReadAsAsync<V2SearchResult>();

// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);

Assert.True(result.TotalHits.HasValue);
Assert.True(result.TotalHits.Value > 0, $"Could not find test package {Constants.TestPackageId}");
Assert.True(result.Data.Count > 0, $"Could not find test package {Constants.TestPackageId}");

Assert.False(string.IsNullOrEmpty(result.Index));
Assert.True(result.IndexTimestamp.HasValue);
Assert.True(result.IndexTimestamp.Value != default(DateTime));

// Assert that the package result whose Id is "BaseTestPackage" with Version "1.0.0"
// matches exactly what is expected.
var package = result.Data
.Where(p => p.PackageRegistration.Id == Constants.TestPackageId)
.Where(p => p.Version == Constants.TestPackageVersion)
.FirstOrDefault();

Assert.NotNull(package);
Assert.True(package.PackageRegistration.DownloadCount != default(long));
Assert.True(package.PackageRegistration.Owners.Count == 1);
Assert.False(string.IsNullOrEmpty(package.PackageRegistration.Owners[0]));
Assert.True(package.NormalizedVersion == "1.0.0");
Assert.True(package.Title == Constants.TestPackageTitle);
Assert.True(package.Description == Constants.TestPackageDescription);
Assert.True(package.Summary == Constants.TestPackageSummary);
Assert.True(package.Authors == Constants.TestPackageAuthor);
Assert.True(package.Copyright == Constants.TestPackageCopyright);
Assert.True(package.Tags == "Tag1 Tag2");
Assert.True(package.ReleaseNotes == "Summary of changes made in this release of the package.");
Assert.True(package.IsLatestStable);
Assert.True(package.IsLatest);
Assert.True(package.Listed);
Assert.True(package.Created != default(DateTime));
Assert.True(package.Published != default(DateTime));
Assert.True(package.LastUpdated != default(DateTime));
Assert.True(package.DownloadCount != default(long));
Assert.True(package.FlattenedDependencies == "");
Assert.True(package.Dependencies.Count() == 0);
Assert.True(package.SupportedFrameworks.Count() == 0);
Assert.True(package.Hash == "5KJqge5+IYZkmba5C/pRVwjqwwaF1YM28xs6AiWMoxfxE/dzFVXJ5QGR7Rx2JmKWPLwz0R3eO+jWjd4lRX1WxA==");
Assert.True(package.HashAlgorithm == "SHA512");
Assert.True(package.PackageFileSize == 3943);
Assert.True(package.RequireslicenseAcceptance == false);
}

[Fact]
public async Task TestPackageResultsHaveRequiredProperties()
{
// Act.
var response = await Client.GetAsync(new V2SearchBuilder { Query = Constants.TestPackageId }.RequestUri);
var content = await response.Content.ReadAsStringAsync();

// Assert that all required properties are present in the search result by
// deserializing the response. An exception will be thrown if required fields
// are missing.
Assert.Null(Record.Exception(() =>
{
var result = JsonConvert.DeserializeObject<V2SearchResult>(content);

Assert.True(result.Data.Count > 0, $"No hits for query '{Constants.TestPackageId}'");
}));
}
}
}
Loading

0 comments on commit f337fac

Please sign in to comment.