Skip to content

Commit

Permalink
Blogifier.Core added to the main project
Browse files Browse the repository at this point in the history
  • Loading branch information
rxtur committed May 10, 2020
1 parent b9a3c9c commit c804c98
Show file tree
Hide file tree
Showing 87 changed files with 8,472 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Blogifier.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blogifier", "src\Blogifier\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blogifier.Widgets", "src\Blogifier.Widgets\Blogifier.Widgets.csproj", "{19384C5F-D421-4A41-AD66-8812B48F48AC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blogifier.Core", "src\Blogifier.Core\Blogifier.Core.csproj", "{B5E6D870-731D-4E48-B772-3751EAEBA77E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blogifier.Core.Tests", "src\Blogifier.Core.Tests\Blogifier.Core.Tests.csproj", "{F16D9352-B301-4643-B1AE-E16AC82ADA10}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -56,13 +60,23 @@ Global
{19384C5F-D421-4A41-AD66-8812B48F48AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19384C5F-D421-4A41-AD66-8812B48F48AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19384C5F-D421-4A41-AD66-8812B48F48AC}.Release|Any CPU.Build.0 = Release|Any CPU
{B5E6D870-731D-4E48-B772-3751EAEBA77E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B5E6D870-731D-4E48-B772-3751EAEBA77E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B5E6D870-731D-4E48-B772-3751EAEBA77E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B5E6D870-731D-4E48-B772-3751EAEBA77E}.Release|Any CPU.Build.0 = Release|Any CPU
{F16D9352-B301-4643-B1AE-E16AC82ADA10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F16D9352-B301-4643-B1AE-E16AC82ADA10}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F16D9352-B301-4643-B1AE-E16AC82ADA10}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F16D9352-B301-4643-B1AE-E16AC82ADA10}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{0DC52C2B-3803-4BB3-A5A2-6371E94700D7} = {39614650-0D6E-4502-B87D-184366060F59}
{19384C5F-D421-4A41-AD66-8812B48F48AC} = {39614650-0D6E-4502-B87D-184366060F59}
{B5E6D870-731D-4E48-B772-3751EAEBA77E} = {39614650-0D6E-4502-B87D-184366060F59}
{F16D9352-B301-4643-B1AE-E16AC82ADA10} = {39614650-0D6E-4502-B87D-184366060F59}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D601BCCC-A1D9-415B-94B5-B3C0EF4AAF0B}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ via theming engine and Blazor components.

## Other Projects

Blogifier uses `Blogifier.Core` library hosted in this same
repository and published to `Nuget.org` package gallery.
Blogifier publishes `Blogifier.Core` library to the Nuget gallery.
This package used by Blogifier.SPA and can be used by other applications.

![blogifier-diagram](https://user-images.githubusercontent.com/1932785/78852494-1465b100-79e2-11ea-81f4-2d7c51f89702.png)
![blogifier-dgm](https://user-images.githubusercontent.com/1932785/81506457-1611e580-92bc-11ea-927e-b826c56ba21b.png)
## Demo site

The [demo site](http://blogifier.net) is a playground to check out Blogifier features. You can write and publish posts, upload files and test application before install.

![dashboard-3](https://user-images.githubusercontent.com/1932785/77836549-1481c900-7125-11ea-812f-9bd5343274f9.png)
![screenshot](https://user-images.githubusercontent.com/1932785/81506584-faf3a580-92bc-11ea-92c9-fd0802d9e977.png)

The [developer's blog](http://rtur.net/blog).
Binary file added src/Blogifier.Core.Tests/Blog.db
Binary file not shown.
35 changes: 35 additions & 0 deletions src/Blogifier.Core.Tests/Blogifier.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Blogifier.Core\Blogifier.Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Blog.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions src/Blogifier.Core.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Xunit;

namespace Blogifier.Core.Tests.Extensions
{
public class StringExtensionsTests
{
[Theory]
[InlineData("tes't, #one", "test-one")]
[InlineData("{test [two?", "test-two")]
[InlineData("test$ ~three!", "test-three")]
[InlineData("Тест* для& --Кирил/лицы", "тест-для-кириллицы")]
public void ShouldRemoveIlligalChars(string title, string slug)
{
Assert.Equal(title.ToSlug(), slug);
}

[Theory]
[InlineData("http://foo/bar/img.jpg", "http://foo/bar/thumbs/img.jpg")]
[InlineData("foo/bar//img-foo.jpg", "foo/bar//thumbs/img-foo.jpg")]
[InlineData("foo/bar/img.one.png", "foo/bar/thumbs/img.one.png")]
public void ShouldConvertImgPathToTumbPath(string img, string thumb)
{
Assert.Equal(img.ToThumb(), thumb);
}
}
}
159 changes: 159 additions & 0 deletions src/Blogifier.Core.Tests/Repositories/AuthorRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
using Blogifier.Core.Data;
using Blogifier.Core.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Blogifier.Core.Tests.Repositories
{
public class AuthorRepositoryTests
{
private readonly IEnumerable<Author> _authors = Enumerable.Range(1, 12)
.Select(i => new Author
{
Id = i,
AppUserName = $"test{i}"
});

[Fact]
public async Task Can_Save_New_Author()
{
// arrange
var dbName = Guid.NewGuid().ToString();
var db = GetMemoryDb(dbName);
var sut = new AuthorRepository(db);

var author = new Author
{
Id = 25,
AppUserName = "Test25"
};

// act
await sut.Save(author);
var result = await sut.GetItem(a => a.AppUserName == "Test25");
ClearMemoryDb(dbName);

// assert
Assert.NotNull(result);
Assert.True(result.Id == 25);
}

[Fact]
public async Task Can_Remove_Author()
{
// arrange
var dbName = Guid.NewGuid().ToString();
var db = GetMemoryDb(dbName);
var sut = new AuthorRepository(db);
var author = new Author { Id = 25, AppUserName = "Test25" };

// act
await sut.Save(author);
var result1 = await sut.GetItem(a => a.Id == 25);
await sut.Remove(25);
var result2 = await sut.GetItem(a => a.Id == 25);
ClearMemoryDb(dbName);

// assert
Assert.NotNull(result1);
Assert.Null(result2);
}

[Fact]
public async Task GetItem_By_Matching_Id_Returns_1_Result()
{
// arrange
var dbName = Guid.NewGuid().ToString();
var db = GetMemoryDb(dbName);
var sut = new AuthorRepository(db);

// act
var result = await sut.GetItem(x => x.AppUserName == "test1");
ClearMemoryDb(dbName);

// assert
Assert.NotNull(result);
Assert.True(result.Id == 1);
}

[Fact]
public async Task GetItems_By_NotMatching_Id_Returns_0_Results()
{
// arrange
var dbName = Guid.NewGuid().ToString();
var db = GetMemoryDb(dbName);
var sut = new AuthorRepository(db);
var pager = new Pager(1);

// act
var result = await sut.GetList(x => x.Id == 123, pager);
ClearMemoryDb(dbName);

// assert
Assert.Empty(result);
}

[Fact]
public async Task GetItems_By_Matching_Id_Returns_1_Result()
{
// arrange
var dbName = Guid.NewGuid().ToString();
var db = GetMemoryDb(dbName);
var sut = new AuthorRepository(db);
var pager = new Pager(1);

// act
var result = await sut.GetList(x => x.Id == 1, pager);
ClearMemoryDb(dbName);

// assert
Assert.True(result.Count() == 1);
}

[Fact]
public async Task Get_First_Page_Returns_10_Results()
{
// arrange
var dbName = Guid.NewGuid().ToString();
var db = GetMemoryDb(dbName);
var sut = new AuthorRepository(db);
var pager = new Pager(1);

// act
var result = await sut.GetList(x => x.Id > 0, pager);
ClearMemoryDb(dbName);

// assert
Assert.True(result.Count() == 10);
}

private AppDbContext GetMemoryDb(string dbName)
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase(dbName).Options;

var context = new AppDbContext(options);

context.Authors.AddRange(_authors);
context.SaveChanges();

return context;
}

private void ClearMemoryDb(string dbName)
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseInMemoryDatabase(dbName).Options;

using (var context = new AppDbContext(options))
{
context.RemoveRange(_authors);
context.SaveChanges();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Blogifier.Core.Data;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
using Xunit;

namespace Blogifier.Core.Tests.Repositories
{
public class CustomFieldsRepositoryTests
{
[Fact]
public async Task CanSaveAndGetCustomField()
{
var db = GetSut();
var sut = new CustomFieldRepository(db);

sut.Add(new CustomField { AuthorId = 1, Name = "social|facebook|1", Content = "http://your.facebook.page.com" });
await db.SaveChangesAsync();

var result = sut.Single(f => f.Name.Contains("social|facebook"));
Assert.NotNull(result);

sut.Remove(result);
await db.SaveChangesAsync();

result = sut.Single(f => f.Name.Contains("social|facebook"));
Assert.Null(result);
}

[Fact]
public async Task CanSaveAndGetSocialField()
{
var db = GetSut();
var sut = new CustomFieldRepository(db);

await sut.SaveSocial(new SocialField {
AuthorId = 0,
Title = "Facebook",
Icon = "fa-facebook",
Name = "social|facebook|1",
Rank = 1,
Content = "http://your.facebook.page.com"
});

var socials = await sut.GetSocial();
Assert.NotNull(socials);

var result = sut.Single(f => f.Name.Contains("social|facebook"));
Assert.NotNull(result);

sut.Remove(result);
await db.SaveChangesAsync();

result = sut.Single(f => f.Name.Contains("social|facebook"));
Assert.Null(result);
}

private AppDbContext GetSut()
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlite("DataSource=Blog.db").Options;

var context = new AppDbContext(options);

return context;
}
}
}
44 changes: 44 additions & 0 deletions src/Blogifier.Core.Tests/Repositories/NewsletterRepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Blogifier.Core.Data;
using Blogifier.Core.Helpers;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Threading.Tasks;
using Xunit;

namespace Blogifier.Core.Tests.Repositories
{
public class NewsletterRepositoryTests
{
[Fact]
public async Task CanGetAndRemoveNewsletterFromDb()
{
var email = "test@test.com";
var db = GetSut();
var sut = new NewsletterRepository(db);

sut.Add(new Newsletter { Email = email, Ip = "1.2.3", Created = SystemClock.Now() });
db.SaveChanges();

var result = await sut.GetList(x => x.Id > 0, new Pager(1));
Assert.NotNull(result);
int count = result.Count();

var existing = sut.Single(x => x.Email == email);
db.Newsletters.Remove(existing);
db.SaveChanges();

result = await sut.GetList(x => x.Id > 0, new Pager(1));
Assert.True(result.Count() == count - 1);
}

private AppDbContext GetSut()
{
var options = new DbContextOptionsBuilder<AppDbContext>()
.UseSqlite("DataSource=Blog.db").Options;

var context = new AppDbContext(options);

return context;
}
}
}
Loading

0 comments on commit c804c98

Please sign in to comment.