Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
[Catalog SDK] Fix serialization issue (#671)
Browse files Browse the repository at this point in the history
Mirrors NuGet/Samples#34, discovered by @jstoker
  • Loading branch information
loic-sharma authored Oct 8, 2019
1 parent b327a58 commit 3f8258d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
if (_fromType.TryGetValue((CatalogLeafType)value, out output))
{
writer.WriteValue(output);
return;
}

throw new NotSupportedException($"The catalog leaf type '{value}' is not supported.");
Expand Down
29 changes: 29 additions & 0 deletions tests/NuGet.Protocol.Catalog.Tests/Models/CatalogLeafItemFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 System;
using Newtonsoft.Json;
using Xunit;

namespace NuGet.Protocol.Catalog
{
public class CatalogLeafItemFacts
{
[Fact]
public void JsonSerializationException()
{
var leafItem = new CatalogLeafItem
{
Url = "https://api.nuget.org/v3/registration3-gz-semver2/newtonsoft.json/12.0.1.json",
Type = CatalogLeafType.PackageDetails,
CommitTimestamp = DateTimeOffset.Parse("2019-10-10T00:00:00.00+00:00"),
PackageId = "Newtonsoft.Json",
PackageVersion = "12.0.1"
};

var result = JsonConvert.SerializeObject(leafItem);

Assert.Equal(TestData.CatalogLeafItem, result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="CatalogClientFacts.cs" />
<Compile Include="CatalogProcessorSettingsFacts.cs" />
<Compile Include="Models\CatalogLeafItemFacts.cs" />
<Compile Include="Models\ModelExtensionsFacts.cs" />
<Compile Include="NullLogger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
11 changes: 10 additions & 1 deletion tests/NuGet.Protocol.Catalog.Tests/TestData.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/NuGet.Protocol.Catalog.Tests/TestData.resx

Large diffs are not rendered by default.

0 comments on commit 3f8258d

Please sign in to comment.