Skip to content

Commit

Permalink
clean up and get mediar tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hathcock committed Apr 11, 2024
1 parent d6d0899 commit f661855
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 437 deletions.
1 change: 0 additions & 1 deletion src/Conduit/Domain/Person.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

Expand Down
6 changes: 3 additions & 3 deletions src/Conduit/Features/Articles/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ CancellationToken cancellationToken
var t = await context.Tags.FindAsync(tag);
if (t == null)
{
t = new Tag() { TagId = tag };
t = new Tag { TagId = tag };
await context.Tags.AddAsync(t, cancellationToken);
//save immediately for reuse
await context.SaveChangesAsync(cancellationToken);
}
tags.Add(t);
}

var article = new Article()
var article = new Article
{
Author = author,
Body = message.Article.Body,
Expand All @@ -81,7 +81,7 @@ CancellationToken cancellationToken
await context.Articles.AddAsync(article, cancellationToken);

await context.ArticleTags.AddRangeAsync(
tags.Select(x => new ArticleTag() { Article = article, Tag = x }),
tags.Select(x => new ArticleTag { Article = article, Tag = x }),
cancellationToken
);

Expand Down
4 changes: 2 additions & 2 deletions src/Conduit/Features/Articles/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ IEnumerable<string> articleTagList
var at = article.ArticleTags?.FirstOrDefault(t => t.TagId == tag);
if (at == null)
{
at = new ArticleTag()
at = new ArticleTag
{
Article = article,
ArticleId = article.ArticleId,
Tag = new Tag() { TagId = tag },
Tag = new Tag { TagId = tag },
TagId = tag
};
articleTagsToCreate.Add(at);
Expand Down
3 changes: 1 addition & 2 deletions src/Conduit/Features/Articles/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Conduit.Domain;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using MediatR;
Expand Down Expand Up @@ -111,7 +110,7 @@ CancellationToken cancellationToken
.AsNoTracking()
.ToListAsync(cancellationToken);

return new ArticlesEnvelope()
return new ArticlesEnvelope
{
Articles = articles,
ArticlesCount = queryable.Count()
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Comments/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CancellationToken cancellationToken
cancellationToken
);

var comment = new Comment()
var comment = new Comment
{
Author = author,
Body = message.Model.Comment.Body ?? string.Empty,
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Favorites/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CancellationToken cancellationToken

if (favorite == null)
{
favorite = new ArticleFavorite()
favorite = new ArticleFavorite
{
Article = article,
ArticleId = article.ArticleId,
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Followers/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CancellationToken cancellationToken

if (followedPeople == null)
{
followedPeople = new FollowedPeople()
followedPeople = new FollowedPeople
{
Observer = observer,
ObserverId = observer.PersonId,
Expand Down
2 changes: 1 addition & 1 deletion src/Conduit/Features/Tags/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<TagsEnvelope> Handle(Query message, CancellationToken cancella
.Tags.OrderBy(x => x.TagId)
.AsNoTracking()
.ToListAsync(cancellationToken);
return new TagsEnvelope()
return new TagsEnvelope
{
Tags = tags?.Select(x => x.TagId ?? string.Empty).ToList() ?? new List<string>()
};
Expand Down
1 change: 0 additions & 1 deletion src/Conduit/Infrastructure/Security/JwtIssuerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;

namespace Conduit.Infrastructure.Security;
Expand Down
37 changes: 5 additions & 32 deletions src/Conduit/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Conduit;
using Conduit.Features.Profiles;
using Conduit.Infrastructure;
using Conduit.Infrastructure.Errors;
using Conduit.Infrastructure.Security;
using FluentValidation;
using FluentValidation.AspNetCore;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
Expand All @@ -25,15 +17,6 @@

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())
);
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationPipelineBehavior<,>));
builder.Services.AddScoped(
typeof(IPipelineBehavior<,>),
typeof(DBContextTransactionPipelineBehavior<,>)
);

// take the connection string from the environment variable or use hard-coded database name
var connectionString = defaultDatabaseConnectionSrting;

Expand Down Expand Up @@ -81,7 +64,7 @@
x.SupportNonNullableReferenceTypes();
x.AddSecurityRequirement(
new OpenApiSecurityRequirement()
new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
Expand All @@ -98,8 +81,8 @@
);
x.SwaggerDoc("v1", new OpenApiInfo { Title = "RealWorld API", Version = "v1" });
x.CustomSchemaIds(y => y.FullName);
x.DocInclusionPredicate((version, apiDescription) => true);
x.TagActionsBy(y => new List<string>()
x.DocInclusionPredicate((_, _) => true);
x.TagActionsBy(y => new List<string>
{
y.GroupName ?? throw new InvalidOperationException()
});
Expand All @@ -123,17 +106,7 @@
.WhenWritingNull
);

builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddFluentValidationClientsideAdapters();
builder.Services.AddValidatorsFromAssemblyContaining<Startup>();

builder.Services.AddAutoMapper(typeof(Program));

builder.Services.AddScoped<IPasswordHasher, PasswordHasher>();
builder.Services.AddScoped<IJwtTokenGenerator, JwtTokenGenerator>();
builder.Services.AddScoped<ICurrentUserAccessor, CurrentUserAccessor>();
builder.Services.AddScoped<IProfileReader, ProfileReader>();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
builder.Services.AddConduit();

builder.Services.AddJwt();

Expand All @@ -143,7 +116,7 @@

app.UseMiddleware<ErrorHandlingMiddleware>();

app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());

app.UseAuthentication();
app.UseMvc();
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit f661855

Please sign in to comment.