Skip to content

Commit

Permalink
#16 create article endpoint and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgroves committed Aug 18, 2023
1 parent cc3ab2d commit 3ea9605
Show file tree
Hide file tree
Showing 61 changed files with 679 additions and 66 deletions.
28 changes: 28 additions & 0 deletions Conduit/Conduit.Migrations/005_CreateArticlesCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NoSqlMigrator.Infrastructure;

namespace Conduit.Migrations;

[Migration(5)]
public class CreateArticlesCollection : MigrateBase
{
private readonly string? _collectionName;
private readonly string? _scopeName;

public CreateArticlesCollection()
{
_collectionName = _config["Couchbase:ArticlesCollectionName"];
_scopeName = _config["Couchbase:ScopeName"];
}

public override void Up()
{
Create.Collection(_collectionName)
.InScope(_scopeName);
}

public override void Down()
{
Delete.Collection(_collectionName)
.FromScope(_scopeName);
}
}
1 change: 1 addition & 0 deletions Conduit/Conduit.Tests/Conduit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<Folder Include="Integration\Users\Controllers\UserController\" />
<Folder Include="Integration\Users\Services\UserDataServiceTests\" />
<Folder Include="TestHelpers\Dto\" />
<Folder Include="Unit\Articles\Handlers\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Conduit.Web.Articles.Handlers;
using Conduit.Web.Articles.Services;
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Providers;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Follows.Handlers;
using Conduit.Web.Follows.Services;
using Conduit.Web.Models;
using Conduit.Web.Users.Services;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Follows.Handlers;
using Conduit.Web.Follows.Services;
using Conduit.Web.Models;
using Conduit.Web.Users.Services;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
using Conduit.Web;
using System.Net;
using Conduit.Tests.TestHelpers;
using Conduit.Web.Models;
using Conduit.Web.Users.ViewModels;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using Conduit.Web.DataAccess.Providers;

namespace Conduit.Tests.Integration.Users.Controllers.UserController;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Users.Handlers;
using Conduit.Web.Users.Services;
using Couchbase.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Follows.Services;
using Conduit.Web.Models;
using Conduit.Web.Users.Handlers;
using Conduit.Web.Users.Services;
using Couchbase.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Tests.TestHelpers.Dto;
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Users.Handlers;
using Conduit.Web.Users.Services;
using Couchbase.Extensions.DependencyInjection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Conduit.Tests.TestHelpers.Dto;
using Conduit.Web.Models;
using Conduit.Web.Users.Handlers;
using Conduit.Web.Users.Services;
using Conduit.Web.Users.ViewModels;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Tests.TestHelpers;
using Conduit.Web.DataAccess.Providers;

namespace Conduit.Tests.Integration.Users.Handlers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Tests.TestHelpers.Dto;
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Users.Handlers;
using Conduit.Web.Users.Services;
using Conduit.Web.Users.ViewModels;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Conduit.Tests.TestHelpers;
using Conduit.Tests.TestHelpers.Data;
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Users.Services;
using Couchbase.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
Expand Down
2 changes: 1 addition & 1 deletion Conduit/Conduit.Tests/TestHelpers/Data/FollowHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Providers;
using Couchbase.KeyValue;

namespace Conduit.Tests.TestHelpers.Data;
Expand Down
3 changes: 2 additions & 1 deletion Conduit/Conduit.Tests/TestHelpers/Data/UserHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Conduit.Web.Models;
using Conduit.Web.DataAccess.Models;
using Conduit.Web.DataAccess.Providers;
using Conduit.Web.Users.Services;

namespace Conduit.Tests.TestHelpers.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Conduit.Web.Articles.Handlers;
using Conduit.Web.Articles.ViewModels;

namespace Conduit.Tests.TestHelpers.Dto;

public static class CreateArticleRequestHelper
{
public static CreateArticleRequest Create(
string? body = null,
string? description = null,
string? title = null,
List<string>? tags = null,
string? username = null,
bool makeTagsNull = false)
{
var random = new Random();

body ??= random.String(1000);
description ??= random.String(100);
title ??= random.String(60);
tags ??= new List<string> { "Couchbase", "cruising" };
username ??= Path.GetRandomFileName();
if (makeTagsNull) tags = null;

var article = new CreateArticleSubmitModel
{
Body = body,
Description = description,
Title = title,
Tags = tags
};

return new CreateArticleRequest(article, username);
}
}
13 changes: 13 additions & 0 deletions Conduit/Conduit.Tests/TestHelpers/RandomHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Conduit.Tests.TestHelpers;

public static class RandomHelpers
{
const string _defaultCharacterSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

public static string String(this Random @this, int length, string? characterPool = null)
{
var chars = characterPool ?? _defaultCharacterSet;
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[@this.Next(s.Length)]).ToArray());
}
}
Loading

0 comments on commit 3ea9605

Please sign in to comment.