Skip to content

Commit

Permalink
Fix/initial commit (#1)
Browse files Browse the repository at this point in the history
* Initial commit of the fix for dependencies

* port from Easify and merge with EF core project

* Added icon for the packages
  • Loading branch information
moattarwork authored Jan 2, 2023
1 parent d55abe9 commit f85601a
Show file tree
Hide file tree
Showing 55 changed files with 2,567 additions and 29 deletions.
9 changes: 9 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
next-version: 1.0.0
mode: Mainline
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
no-bump-message: '\+semver:\s?(none|skip)'
ignore:
commits-before: 2023-01-01T00:00:00

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using LittleBlocks.Ef.UnitOfWork;

namespace LittleBlocks.Ef.Testing.UnitTests;

public class DbContextExtensionsTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

global using Microsoft.EntityFrameworkCore;
global using Microsoft.Extensions.DependencyInjection;

global using EfCore.UnitOfWork;
global using FluentAssertions;
global using Xunit;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using LittleBlocks.Ef.UnitOfWork;

namespace LittleBlocks.Ef.Testing;

public static class DbContextExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using LittleBlocks.Ef.UnitOfWork;

namespace LittleBlocks.Ef.Testing.Extensions;

public static class EntityListExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Mohammad Moattar</Authors>
<Company>ICG</Company>
<Company>LittleBlocks</Company>
<Description>LittleBlocks support for testing projects for UnitOfWork and Ef Core</Description>
<PackageProjectUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</RepositoryUrl>
<Version>1.0.0</Version>
<LangVersion>10</LangVersion>
<PackageIcon>Logo.png</PackageIcon>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="LittleBlocks" Version="5.0.1" />
<PackageReference Include="LittleBlocks" Version="1.0.1" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="FluentAssertions" Version="6.8.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.Ef\LittleBlocks.Ef.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Logo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>
Binary file added src/LittleBlocks.Ef.Testing/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@
global using Microsoft.EntityFrameworkCore.Diagnostics;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;

global using EfCore.UnitOfWork;
global using AutoMapper;
11 changes: 11 additions & 0 deletions src/LittleBlocks.Ef.UnitOfWork.UnitTests/Entities/City.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace LittleBlocks.Ef.UnitOfWork.UnitTests.Entities
{
public class City
{
public int Id { get; set; }
public string Name { get; set; }
public int CountryId { get; set; }
public Country Country { get; set; }
public List<Town> Towns { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/LittleBlocks.Ef.UnitOfWork.UnitTests/Entities/Country.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;

namespace LittleBlocks.Ef.UnitOfWork.UnitTests.Entities
{
public class Country
{
[Key]
public int Id { get; set; }
public string Name { get; set; }

public List<City> Cities { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/LittleBlocks.Ef.UnitOfWork.UnitTests/Entities/Customer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace LittleBlocks.Ef.UnitOfWork.UnitTests.Entities
{
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
}
10 changes: 10 additions & 0 deletions src/LittleBlocks.Ef.UnitOfWork.UnitTests/Entities/Town.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace LittleBlocks.Ef.UnitOfWork.UnitTests.Entities
{
public class Town
{
public int Id { get; set; }
public string Name { get; set; }
public int CityId { get; set; }
public City City { get; set; }
}
}
25 changes: 25 additions & 0 deletions src/LittleBlocks.Ef.UnitOfWork.UnitTests/InMemoryDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using LittleBlocks.Ef.UnitOfWork.UnitTests.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection;

namespace LittleBlocks.Ef.UnitOfWork.UnitTests
{
public class InMemoryDbContext : DbContext
{
public DbSet<Country> Countries { get; set; }
public DbSet<Customer> Customers { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var name = $"{typeof(InMemoryDbContext).Name}_{Guid.NewGuid()}";

var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
optionsBuilder.UseInMemoryDatabase(name)
.ConfigureWarnings(warnings => warnings.Ignore(InMemoryEventId.TransactionIgnoredWarning))
.UseInternalServiceProvider(serviceProvider);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Mohammad Moattar</Authors>
<Company>LittleBlocks</Company>
<Description>LittleBlocks support for entity framework core and UnitOfWork</Description>
<PackageProjectUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.Ef</RepositoryUrl>
<Version>1.0.0</Version>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LittleBlocks.Ef.UnitOfWork\LittleBlocks.Ef.UnitOfWork.csproj" />
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions src/LittleBlocks.Ef.UnitOfWork.UnitTests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using LittleBlocks.Ef.UnitOfWork.UnitTests.Entities;

namespace LittleBlocks.Ef.UnitOfWork.UnitTests
{
public class RepositoryFixture
{
private static IEnumerable<Country> TestCountries => new List<Country>
{
new Country {Id = 1, Name = "A"},
new Country {Id = 2, Name = "B"}
};

private static IEnumerable<City> TestCities => new List<City>
{
new City { Id = 1, Name = "A", CountryId = 1},
new City { Id = 2, Name = "B", CountryId = 2},
new City { Id = 3, Name = "C", CountryId = 1},
new City { Id = 4, Name = "D", CountryId = 2},
new City { Id = 5, Name = "E", CountryId = 1},
new City { Id = 6, Name = "F", CountryId = 2},
};

private static IEnumerable<Town> TestTowns => new List<Town>
{
new Town { Id = 1, Name="A", CityId = 1 },
new Town { Id = 2, Name="B", CityId = 2 },
new Town { Id = 3, Name="C", CityId = 3 },
new Town { Id = 4, Name="D", CityId = 4 },
new Town { Id = 5, Name="E", CityId = 5 },
new Town { Id = 6, Name="F", CityId = 6 },
};

public InMemoryDbContext DbContext()
{
var dbContext = new InMemoryDbContext();

dbContext.AddRange(TestCountries);
dbContext.AddRange(TestCities);
dbContext.AddRange(TestTowns);

dbContext.SaveChanges();

return dbContext;
}

public IUnitOfWork CreateUnitOfWork() => new UnitOfWork<InMemoryDbContext>(DbContext());

public IRepository<T> CreateRepository<T>() where T : class => new Repository<T>(DbContext());
}
}
Loading

0 comments on commit f85601a

Please sign in to comment.