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

Json Support #59

Merged
merged 22 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Flickr.Net.Core.Test/bin/Debug/net7.0/Flickr.Net.Core.Test.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Flickr.Net.Core.Test",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "file:///g%3A/GIT/Flickr.Net/.git/workflows/docfx-build-publish.yml"
}
},
"dotnet.defaultSolution": "src/Flickr.Net.sln"
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/Flickr.Net.Core.Test/Flickr.Net.Core.Test.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/Flickr.Net.Core.Test/Flickr.Net.Core.Test.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/src/Flickr.Net.Core.Test/Flickr.Net.Core.Test.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
107 changes: 107 additions & 0 deletions src/Flickr.Net.Core.Test/Entities/BlogTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Flickr.Net.Core.Flickrs.Results;
using Flickr.Net.Core.Internals;

namespace Flickr.Net.Core.Test.Entities;

public class BlogTests
{
[Fact]
public void JsonStringToBlogs()
{
var json = /*lang=json*/ """
{
"stat": "ok",
"blogs":{
"blog": [
{
"id" : "73",
"name" : "Bloxus test",
"needspassword" : "0",
"url" : "http://remote.bloxus.com/"
},
{
"id" : "74",
"name" : "Manila Test",
"needspassword" : "1",
"url" : "http://flickrtest1.userland.com/"
}
]
}
}
""";

var result = FlickrConvert.DeserializeObject<FlickrResult<Blogs>>(json);

Assert.NotNull(result);
Assert.False(result.HasError);
var items = result.Content;
Assert.IsType<Blogs>(items);
Assert.Equal(2, result.Content.Values.Count);
}

[Fact]
public void JsonStringToServices()
{
var json = /*lang=json,strict*/ """
{
"stat": "ok",
"services": {
"service": [
{
"id": "beta.blogger.com",
"_content": "Blogger"
},
{
"id": "Typepad",
"_content": "Typepad"
},
{
"id": "MovableType",
"_content": "Movable Type"
},
{
"id": "LiveJournal",
"_content": "LiveJournal"
},
{
"id": "MetaWeblogAPI",
"_content": "Wordpress"
},
{
"id": "MetaWeblogAPI",
"_content": "MetaWeblogAPI"
},
{
"id": "Manila",
"_content": "Manila"
},
{
"id": "AtomAPI",
"_content": "AtomAPI"
},
{
"id": "BloggerAPI",
"_content": "BloggerAPI"
},
{
"id": "Vox",
"_content": "Vox"
},
{
"id": "Twitter",
"_content": "Twitter"
}
]
}
}
""";

var result = FlickrConvert.DeserializeObject<FlickrResult<Services>>(json);

Assert.NotNull(result);
Assert.False(result.HasError);
var items = result.Content;
Assert.IsType<Services>(items);
Assert.Equal(11, result.Content.Values.Count);
}
}
47 changes: 47 additions & 0 deletions src/Flickr.Net.Core.Test/Entities/CSVFileTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Flickr.Net.Core.Flickrs.Results;
using Flickr.Net.Core.Internals;

namespace Flickr.Net.Core.Test.Entities;

public class CSVFileTests
{
[Fact]
public void JsonStringToCSVFiles()
{
var json = /*lang=json,strict*/ """
{
"stat": "ok",
"stats": {
"csvfiles": [
{
"href": "http://farm4.static.flickr.com/3496/stats/72157623902771865_faaa.csv",
"type": "daily",
"date": "2010-04-01"
},
{
"href": "http://farm4.static.flickr.com/3376/stats/72157624027152370_fbbb.csv",
"type": "monthly",
"date": "2010-04-01"
},
{
"href": "http://farm5.static.flickr.com/4006/stats/72157623627769689_fccc.csv",
"type": "daily",
"date": "2010-03-01"
}
]
}
}
""";

var result = FlickrConvert.DeserializeObject<FlickrResult<CSVFiles>>(json);

Assert.NotNull(result);
Assert.False(result.HasError);
var items = result.Content;
Assert.IsType<CSVFiles>(items);
Assert.NotEmpty(items.Values);
Assert.Equal(new DateOnly(2010, 04, 01), items.Values[0].Date);
Assert.Equal(new DateOnly(2010, 04, 01), items.Values[1].Date);
Assert.Equal(new DateOnly(2010, 03, 01), items.Values[2].Date);
}
}
100 changes: 100 additions & 0 deletions src/Flickr.Net.Core.Test/Entities/CameraTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Flickr.Net.Core.Flickrs.Results;
using Flickr.Net.Core.Internals;

namespace Flickr.Net.Core.Test.Entities;

public class CameraTests
{
[Fact]
public void JsonStringToCameras()
{
var json = /*lang=json,strict*/ """
{
"stat": "ok",
"cameras": {
"brand": "apple",
"camera": [
{
"id": "iphone_9000",
"name": "iPhone 9000",
"details": {
"megapixels": "22.0",
"zoom": "3.0",
"lcd_size": "40.5",
"storage_type": "Flash"
},
"images": {
"small": "http://farm3.staticflickr.com/1234/cameras/123456_model_small_123456.jpg",
"large": "http://farm3.staticflickr.com/1234/cameras/123456_model_large_123456.jpg"
}
},
{
"id": "iphone_9000",
"name": "iPhone 9000",
"details": {
"megapixels": "22.0",
"zoom": "3.0",
"lcd_size": "40.5",
"storage_type": "Flash"
},
"images": {
"small": "http://farm3.staticflickr.com/1234/cameras/123456_model_small_123456.jpg",
"large": "http://farm3.staticflickr.com/1234/cameras/123456_model_large_123456.jpg"
}
}
]
}
}
""";

var result = FlickrConvert.DeserializeObject<FlickrResult<Cameras>>(json);

Assert.NotNull(result);
Assert.False(result.HasError);
var items = result.Content;
Assert.IsType<Cameras>(items);
Assert.IsType<Camera>(items.Values[0]);
Assert.NotEmpty(items.Values[0].Name);
Assert.IsType<Details>(items.Values[0].Details);
Assert.NotEmpty(items.Values[0].Details.Zoom);
Assert.IsType<Image>(items.Values[0].Image);
Assert.NotEmpty(items.Values[0].Image.Large);
}

[Fact]
public void JsonStringToBrands()
{
var json = /*lang=json,strict*/ """
{
"stat": "ok",
"brands": {
"brand": [
{
"id": "canon",
"_content": "Canon"
},
{
"id": "nikon",
"_content": "Nikon"
},
{
"id": "apple",
"_content": "Apple"
}
]
}
}
""";

var result = FlickrConvert.DeserializeObject<FlickrResult<Brands>>(json);

Assert.NotNull(result);
Assert.False(result.HasError);
var items = result.Content;
Assert.IsType<Brands>(items);
Assert.IsType<Brand>(items.Values[0]);
Assert.Equal("canon", items.Values[0].Id);
Assert.Equal("nikon", items.Values[1].Id);
Assert.Equal("apple", items.Values[2].Id);
}
}
Loading