Skip to content

Commit 0caa72f

Browse files
lonesomegeekdugept
andauthored
Version/4.1.0 (#102)
* Work/12 (#86) * some steps done * adjust repository layer * before forking crudservice to new definition * all layers adjusted * adding T1, T2 to historical crud * some switching in dto services * unit tests adjusted * minor corrections * head verb working (#87) * Work/11 (#88) * adjusting all structure of historical to include events and changesets * adjust unit tests for new historical event and changeset structure * Work/2 3 (#89) * everythings working, not uni tested * everythings working, not uni tested * Work/8 9 (#90) * part of minimal structure done * adding mark as read, unread, adding readstatus by id * add read status for all entities * implement delta snapshot * done with changeset diff, begins restore with changeset * fix build issues * working version, with bugs * bug resolved (#91) * bug seems to be resolved, more bugs should come in integration testing (#92) * little cleanup * put code in dto layers, not tested (#93) * refactoring done (#94) * Work/23 (#95) * code base ready, only need to convert tentity to tdto * fix for dto historical crud service layer * everything seems to work now * Work/23 (#97) * code base ready, only need to convert tentity to tdto * fix for dto historical crud service layer * everything seems to work now * ready for final tests * working with a little refactorign * adjusting version numbers * adding service helpers and controller attributes. * adding unit tests * adding more unit tests on historical service layer * adding two more unit tests * more unit tests * more unit tests * delta history * remove comment * Work/13 (#98) * new doc * adding new doc * upgrade samples to 4.0.0-alpha1 and correct projets * adding new doc * adding more documentation * finalizing tests on samples, missing code on custom repository on GlobalFilters * all samples are working * prepare v 4.0.0-alpha2 to complete docs * fix temp tests * change version numbers * adjust sample doc * ready for beta * change IEnumerable for IQueryable * change ienumerable to iqueryable, fix some errors in samples * adding db scripts and db projects * adding scripts * working migration scripts * ready for beta build of 4.1 * remove junk projects * cleanup in projects within the solution * adding readme documentation * changing version numbers * Minor adjustments Co-authored-by: Emmanuel Dugas-Gallant <[email protected]>
1 parent fa58b03 commit 0caa72f

35 files changed

+533
-69
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<IncludeCompositeObjects>True</IncludeCompositeObjects>
5+
<TargetDatabaseName>MySampleDb</TargetDatabaseName>
6+
<DeployScriptFileName>LSG.GenericCrud.Database.sql</DeployScriptFileName>
7+
<TargetConnectionString>Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False</TargetConnectionString>
8+
<ProfileVersionNumber>1</ProfileVersionNumber>
9+
</PropertyGroup>
10+
</Project>

LSG.GenericCrud.Database/LSG.GenericCrud.Database.sqlproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -62,6 +62,7 @@
6262
<ItemGroup>
6363
<Build Include="Tables\HistoricalEvents.sql" />
6464
<Build Include="Tables\HistoricalChangesets.sql" />
65+
<None Include="Scripts\Migration-v2.2-to-v4.0.sql" />
6566
</ItemGroup>
6667
<ItemGroup>
6768
<None Include="LSG.GenericCrud.Database.publish.xml" />
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
print N'Creating tables'
2+
GO
3+
4+
CREATE TABLE [dbo].[HistoricalChangesets]
5+
(
6+
[Id] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
7+
[EventId] [uniqueidentifier] NOT NULL,
8+
[ObjectData] [nvarchar](max) NULL,
9+
[ObjectDelta] [nvarchar](max) NULL,
10+
[CreatedDate] [datetime] NULL,
11+
[CreatedBy] [nvarchar](255) NULL,
12+
13+
-- constraints
14+
CONSTRAINT PK_HistoricalChangesets PRIMARY KEY (Id)
15+
)
16+
GO
17+
CREATE TABLE [dbo].[HistoricalEvents_v4]
18+
(
19+
[Id] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
20+
[EntityId] [nvarchar](255) NOT NULL,
21+
[EntityName] [nvarchar](255) NOT NULL,
22+
[Action] [nvarchar](50) NOT NULL,
23+
[CreatedDate] [datetime] NULL,
24+
[CreatedBy] [nvarchar](255) NULL
25+
26+
-- constraints
27+
CONSTRAINT PK_HistoricalEvents_v4 PRIMARY KEY (Id)
28+
)
29+
GO
30+
31+
print N'Copying existing data into new table structure'
32+
GO
33+
INSERT
34+
INTO dbo.HistoricalEvents_v4
35+
SELECT
36+
Id,
37+
EntityId,
38+
EntityName,
39+
Action,
40+
ActionDate CreatedDate,
41+
TriggeredBy CreatedBy
42+
FROM dbo.HistoricalEvents
43+
44+
INSERT
45+
INTO dbo.HistoricalChangesets
46+
SELECT
47+
NEWID() Id,
48+
Id EventId,
49+
Changeset ObjectData,
50+
NULL ObjectDelta,
51+
ActionDate CreatedDate,
52+
TriggeredBy CreatedBy
53+
FROM dbo.HistoricalEvents
54+
55+
print N'Renaming tables'
56+
exec sp_rename 'dbo.HistoricalEvents', 'HistoricalEvents_old'
57+
exec sp_rename 'dbo.HistoricalEvents_v4', 'HistoricalEvents'
58+
59+
print N'Renaming indices'
60+
exec sp_rename 'dbo.HistoricalEvents_old.PK_HistoricalEvents', 'PK_HistoricalEvents_old', 'INDEX'
61+
exec sp_rename 'dbo.HistoricalEvents.PK_HistoricalEvents_v4', 'PK_HistoricalEvents', 'INDEX'
62+
63+
print N'Done.'

LSG.GenericCrud.Database/Tables/HistoricalChangesets.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[ObjectData] [nvarchar](max) NULL,
66
[ObjectDelta] [nvarchar](max) NULL,
77
[CreatedDate] [datetime] NULL,
8-
[CreatedBy] [nvarchar](50) NULL,
8+
[CreatedBy] [nvarchar](255) NULL,
99

1010
-- constraints
1111
CONSTRAINT PK_HistoricalChangesets PRIMARY KEY (Id)

LSG.GenericCrud.Database/Tables/HistoricalEvents.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
CREATE TABLE [dbo].[HistoricalEvents]
22
(
33
[Id] [uniqueidentifier] NOT NULL DEFAULT NEWID(),
4-
[EntityId] [nvarchar](50) NOT NULL,
5-
[EntityName] [nvarchar](50) NOT NULL,
4+
[EntityId] [nvarchar](255) NOT NULL,
5+
[EntityName] [nvarchar](255) NOT NULL,
66
[Action] [nvarchar](50) NOT NULL,
77
[CreatedDate] [datetime] NULL,
8-
[CreatedBy] [nvarchar](50) NULL
8+
[CreatedBy] [nvarchar](255) NULL
99

1010
-- constraints
1111
CONSTRAINT PK_HistoricalEvents PRIMARY KEY (Id)

LSG.GenericCrud.Dto/LSG.GenericCrud.Dto.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Version>4.0.0</Version>
5+
<Version>4.1.0</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<PackageId>LSG.GenericCrud.Dto</PackageId>
88
<Authors>lonesomegeek</Authors>

LSG.GenericCrud.Dto/Services/HistoricalCrudService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public async Task<DifferentialChangeset> GetDeltaDifferential(TId id, DateTime f
283283
var events = _repository
284284
.GetAll<HistoricalEvent>()
285285
.Where(_ => _.EntityId == id.ToString() && _.CreatedDate >= fromTimestamp && _.CreatedDate <= toTimestamp && _.Action != HistoricalActions.Read.ToString())
286+
.ToList()
286287
.OrderBy(_ => _.CreatedDate);
287288

288289
if (events.Count() == 0) throw new NoHistoryException();

LSG.GenericCrud.Extensions/LSG.GenericCrud.Extensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Version>4.0.0</Version>
5+
<Version>4.1.0</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Authors>lonesomegeek</Authors>
88
<Company>lonesomegeek</Company>

LSG.GenericCrud.Samples/Sample.CrudOptions/Sample.CrudOptions.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
12+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.2.0" />
15+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.1" />
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1" />
1318
<PackageReference Include="RestSharp" Version="106.2.1" />
1419
</ItemGroup>
1520

LSG.GenericCrud.Samples/Sample.DataFiller/Sample.DataFiller/Sample.DataFiller.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
12+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.1" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1" />
1316
</ItemGroup>
1417

1518
<ItemGroup>

LSG.GenericCrud.Samples/Sample.GenericCrud.VS/Sample.GenericCrud/Sample.GenericCrud.VS.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
12+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.1" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1" />
1316
</ItemGroup>
1417

1518
<ItemGroup>

LSG.GenericCrud.Samples/Sample.GenericCrud.VSCode/Controllers/AccountsController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
using LSG.GenericCrud.Services;
44
using Microsoft.AspNetCore.Mvc;
55
using Sample.Models;
6+
using System;
67

78
namespace Sample.Controllers
89
{
910
[Route("api/[controller]")]
11+
[ApiController]
1012
public class AccountsController : CrudController<Account>
1113
{
12-
public AccountsController(ICrudService<Account> service) : base(service) { }
14+
public AccountsController(ICrudController<Guid, Account> controller) : base(controller)
15+
{
16+
}
1317
}
1418
}

LSG.GenericCrud.Samples/Sample.GenericCrud.VSCode/Models/SampleContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Sample.Models
66
{
77
public class SampleContext : BaseDbContext, IDbContext
88
{
9-
public SampleContext(DbContextOptions options, IServiceProvider serviceProvider) : base(options, serviceProvider) {}
9+
public SampleContext(DbContextOptions options, IServiceProvider serviceProvider) : base(options, serviceProvider) { }
1010

1111
public DbSet<Account> Accounts { get; set; }
1212
}

LSG.GenericCrud.Samples/Sample.GenericCrud.VSCode/Sample.GenericCrud.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<Folder Include="wwwroot\" />
77
</ItemGroup>
88
<ItemGroup>
9-
<PackageReference Include="LSG.GenericCrud" Version="2.1.1" />
10-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
9+
<ProjectReference Include="..\..\LSG.GenericCrud\LSG.GenericCrud.csproj" />
10+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
12+
<PackageReference Include="microsoft.entityframeworkcore.inmemory" Version="2.2.4" />
1113
</ItemGroup>
1214
</Project>

LSG.GenericCrud.Samples/Sample.GenericCrud.VSCode/Startup.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LSG.GenericCrud.Helpers;
1+
using LSG.GenericCrud.Controllers;
2+
using LSG.GenericCrud.Helpers;
23
using LSG.GenericCrud.Repositories;
34
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Hosting;
@@ -12,10 +13,12 @@ public class Startup
1213
{
1314
public void ConfigureServices(IServiceCollection services)
1415
{
16+
// to activate mvc service
1517
services.AddMvc();
18+
// to load an InMemory EntityFramework context
1619
services.AddDbContext<SampleContext>(opt => opt.UseInMemoryDatabase());
1720
services.AddTransient<IDbContext, SampleContext>();
18-
21+
// to dynamically inject any type of Crud repository of type T in any controllers
1922
services.AddCrud();
2023
}
2124

LSG.GenericCrud.Samples/Sample.GlobalFilters/Sample.GlobalFilters/Repositories/CrudRepositoryIgnoreFilter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,22 @@ Task<T2> ICrudRepository.DeleteAsync<T1, T2>(T1 id)
6969
throw new NotImplementedException();
7070
}
7171

72-
IEnumerable<T> ICrudRepository.GetAll<T>()
72+
IQueryable<T> ICrudRepository.GetAll<T>()
7373
{
7474
throw new NotImplementedException();
7575
}
7676

77-
Task<IEnumerable<T>> ICrudRepository.GetAllAsync<T>()
77+
IQueryable<T2> ICrudRepository.GetAll<T1, T2>()
7878
{
7979
throw new NotImplementedException();
8080
}
8181

82-
Task<IEnumerable<T2>> ICrudRepository.GetAllAsync<T1, T2>()
82+
Task<IQueryable<T>> ICrudRepository.GetAllAsync<T>()
83+
{
84+
throw new NotImplementedException();
85+
}
86+
87+
Task<IQueryable<T2>> ICrudRepository.GetAllAsync<T1, T2>()
8388
{
8489
throw new NotImplementedException();
8590
}

LSG.GenericCrud.Samples/Sample.GlobalFilters/Sample.GlobalFilters/Sample.GlobalFilters.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
13+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
14+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
15+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.2.0" />
16+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
17+
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.1" />
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1" />
1420
</ItemGroup>
1521

1622
<ItemGroup>

LSG.GenericCrud.Samples/Sample.GlobalFilters/Sample.GlobalFilters/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
using Sample.GlobalFilters.DataFillers;
1212
using Sample.GlobalFilters.Models;
1313
using Sample.GlobalFilters.Repositories;
14+
using Microsoft.AspNetCore.Http;
15+
using Microsoft.AspNetCore.Mvc;
1416

1517
namespace Sample.GlobalFilters
1618
{

LSG.GenericCrud.Samples/Sample.HistoricalCrud/Sample.HistoricalCrud/Sample.HistoricalCrud.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
13-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.1" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1" />
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
1613
</ItemGroup>
1714

1815
<ItemGroup>

LSG.GenericCrud.Tests/LSG.GenericCrud.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.0</TargetFramework>

LSG.GenericCrud.Tests/Services/CrudServiceTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace LSG.GenericCrud.Tests.Services
1414
{
1515
public class CrudServiceTests
1616
{
17-
private readonly IList<TestEntity> _entities;
17+
private readonly IQueryable<TestEntity> _entities;
1818
private readonly TestEntity _entity;
1919

2020
public CrudServiceTests()
@@ -23,7 +23,7 @@ public CrudServiceTests()
2323
var entityFaker = new Faker<TestEntity>().
2424
RuleFor(_ => _.Id, Guid.NewGuid()).
2525
RuleFor(_ => _.Value, _ => _.Lorem.Word());
26-
_entities = entityFaker.Generate(5);
26+
_entities = entityFaker.Generate(5).AsQueryable();
2727
_entity = entityFaker.Generate();
2828
}
2929

@@ -44,7 +44,7 @@ public void GetAll_ReturnElements()
4444

4545
var result = service.GetAll();
4646

47-
Assert.Equal(result.Count(), _entities.Count);
47+
Assert.Equal(result.Count(), _entities.Count());
4848
repositoryMock.Verify(_ => _.GetAllAsync<Guid, TestEntity>(), Times.Once);
4949
}
5050

@@ -57,7 +57,7 @@ public async void GetAllAsync_ReturnElements()
5757

5858
var result = await service.GetAllAsync();
5959

60-
Assert.Equal(result.Count(), _entities.Count);
60+
Assert.Equal(result.Count(), _entities.Count());
6161
repositoryMock.Verify(_ => _.GetAllAsync<Guid, TestEntity>(), Times.Once);
6262
}
6363

0 commit comments

Comments
 (0)