Skip to content

Commit

Permalink
Merge 2f0bad7 into ac48c18
Browse files Browse the repository at this point in the history
  • Loading branch information
dlidstrom authored Nov 27, 2021
2 parents ac48c18 + 2f0bad7 commit 2898496
Show file tree
Hide file tree
Showing 96 changed files with 1,161 additions and 241 deletions.
25 changes: 21 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions/cache@v2
id: cache
with:
path: ~/.nuget/packages
path: packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
Expand All @@ -43,10 +43,15 @@ jobs:
#if: steps.cache.outputs.cache-hit != 'true'
run: |
nuget restore Snittlistan.sln
Get-ChildItem -Recurse C:\Users\runneradmin\.nuget
- name: Build
run: msbuild build.build -t:All -p:Version=$env:BUILD_VERSION -p:WIX_PATH=$env:wix -p:NUnitConsoleRunnerPath=C:\Users\runneradmin\.nuget\packages\nunit.consolerunner\3.12.0\
run: msbuild build.build -t:All -p:Version=$env:BUILD_VERSION -p:WIX_PATH=$env:wix -p:NUnitConsoleRunnerPath=packages\nunit.consolerunner\3.12.0\

- name: Upload a Build Artifact
uses: actions/upload-artifact@v2
with:
name: 'Test Result'
path: Build\_build\TestResult.html

- name: Push tag
id: tag
Expand All @@ -55,6 +60,18 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.BUILD_VERSION }}

- name: Comment pull request
uses: actions/[email protected]
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const filename = "Build/_build/TestResult.html";
const contents = fs.readFileSync(filename, "utf8");
const { issue: { number: issue_number }, repo: { owner, repo } } = context;
github.issues.createComment({ issue_number, owner, repo, body: contents });
- name: Create release
id: create_release
uses: actions/create-release@v1
Expand All @@ -64,7 +81,7 @@ jobs:
tag_name: ${{ steps.tag.outputs.new_tag }}
release_name: Release v${{ steps.tag.outputs.new_tag }}
draft: false
prerelease: false
prerelease: github.event_name == 'pull_request'

- name: Upload artifact
id: upload-artifact
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ obj/
_ReSharper*/
[Tt]est[Rr]esult*
packages
Snittlistan.Web/Web.Release.config
Snittlistan.Web/Snittlistan.Publish.xml
Snittlistan.Web/App_Data/Database
Tools/
Expand Down
10 changes: 10 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="./packages" />
<add key="globalPackagesFolder" value="./packages" />
</config>
<settings>
<repositoryPath>./packages</repositoryPath>
</settings>
</configuration>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable


namespace Snittlistan.Queue.Infrastructure
{
// TODO remove
public class Tenant
{
public int TenantId { get; set; }
Expand Down
26 changes: 23 additions & 3 deletions Snittlistan.Queue/Messages/MessageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,50 @@
namespace Snittlistan.Queue.Messages
{
using System;
using System.Threading.Tasks;

public delegate Task PublishMessageDelegate(
ITask task,
int tenantId,
Guid causationId,
IMsmqTransaction msmqTransaction);

public interface IMessageContext
{
Action<ITask> PublishMessage { get; set; }
PublishMessageDelegate PublishMessageDelegate { get; set; }
}

public class MessageContext<TTask> : IMessageContext where TTask : ITask
{
public MessageContext(
TTask task,
int tenantId,
Guid correlationId,
Guid causationId)
Guid causationId,
IMsmqTransaction msmqTransaction)
{
Task = task;
TenantId = tenantId;
CorrelationId = correlationId;
CausationId = causationId;
MsmqTransaction = msmqTransaction;
}

public TTask Task { get; }

public int TenantId { get; }

public Guid CorrelationId { get; }

public Guid CausationId { get; }

public Action<ITask> PublishMessage { get; set; } = null!;
public IMsmqTransaction MsmqTransaction { get; }

public async Task PublishMessage(ITask task)
{
await PublishMessageDelegate(task, TenantId, CausationId, MsmqTransaction);
}

public PublishMessageDelegate PublishMessageDelegate { get; set; } = null!;
}
}
2 changes: 1 addition & 1 deletion Snittlistan.Queue/Snittlistan.Queue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<Compile Include="Infrastructure\DatabaseContext.cs" />
<Compile Include="IMsmqTransaction.cs" />
<Compile Include="Infrastructure\NLogLoggingProvider.cs" />
<Compile Include="Infrastructure\TenantConfiguration.cs" />
<Compile Include="Infrastructure\Tenant.cs" />
<Compile Include="JsonMessageFormatter.cs" />
<Compile Include="LoggingHandler.cs" />
<Compile Include="Messages\BusinessKey.cs" />
Expand Down
14 changes: 14 additions & 0 deletions Snittlistan.Test/ApiControllers/Infrastructure/IdGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#nullable enable

namespace Snittlistan.Test.ApiControllers.Infrastructure
{
public class IdGenerator
{
private int _currentId;

public int GetNext()
{
return ++_currentId;
}
}
}
141 changes: 141 additions & 0 deletions Snittlistan.Test/ApiControllers/Infrastructure/InMemoryContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#nullable enable

namespace Snittlistan.Test.ApiControllers.Infrastructure
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Snittlistan.Web.Infrastructure.Database;

public sealed class InMemoryDbSet<T> : IDbSet<T>, IDbAsyncEnumerable<T> where T : class
{
private readonly IdGenerator _generator;
private readonly HashSet<T> _data;
private readonly IQueryable<T> _query;

public InMemoryDbSet(IdGenerator generator)
{
_generator = generator;
_data = new HashSet<T>();
_query = _data.AsQueryable();
}

public ObservableCollection<T> Local => new(_data);

public Type ElementType => _query.ElementType;

public Expression Expression => _query.Expression;

public IQueryProvider Provider => new InMemoryDbAsyncQueryProvider<T>(_query.Provider);

public IQueryable<T> AsQueryable()
{
return _query;
}

public T Add(T entity)
{
_ = _data.Add(entity);
Type type = typeof(T);
string idPropertyName = $"{type.Name}Id";
PropertyInfo propertyInfo = type.GetProperty(idPropertyName);
if (propertyInfo == null)
{
throw new Exception($"No {idPropertyName} property found on {type.Name} class");
}

propertyInfo.SetValue(entity, _generator.GetNext());

return entity;
}

public T Attach(T entity)
{
_ = _data.Add(entity);
return entity;
}

public TDerivedEntity Create<TDerivedEntity>() where TDerivedEntity : class, T
{
throw new NotImplementedException();
}

public T Create()
{
return Activator.CreateInstance<T>();
}

public T Find(params object[] keyValues)
{
throw new NotImplementedException("Derive from FakeDbSet and override Find");
}

public T Remove(T entity)
{
_ = _data.Remove(entity);
return entity;
}

public IEnumerator<T> GetEnumerator()
{
return _data.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return _data.GetEnumerator();
}

public IDbAsyncEnumerator<T> GetAsyncEnumerator()
{
return new InMemoryDbAsyncEnumerator<T>(GetEnumerator());
}

IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator()
{
return GetAsyncEnumerator();
}
}

public class InMemoryContext : ISnittlistanContext, IBitsContext
{
public InMemoryContext()
{
IdGenerator generator = new();
DelayedTasks = new InMemoryDbSet<DelayedTask>(generator);
PublishedTasks = new InMemoryDbSet<PublishedTask>(generator);
Tenants = new InMemoryDbSet<Tenant>(generator);
Teams = new InMemoryDbSet<Bits_Team>(generator);
Hallar = new InMemoryDbSet<Bits_Hall>(generator);
}

public IDbSet<DelayedTask> DelayedTasks { get; }

public IDbSet<PublishedTask> PublishedTasks { get; }

public IDbSet<Bits_Team> Teams { get; }

public IDbSet<Bits_Hall> Hallar { get; }

public IDbSet<Tenant> Tenants { get; }

public DbChangeTracker ChangeTracker => throw new NotImplementedException();

public int SaveChanges()
{
return 0;
}

public Task<int> SaveChangesAsync()
{
return Task.FromResult(0);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#nullable enable

namespace Snittlistan.Test.ApiControllers.Infrastructure
{
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Linq.Expressions;

public class InMemoryDbAsyncEnumerable<T> : EnumerableQuery<T>, IDbAsyncEnumerable<T>, IQueryable<T>
{
public InMemoryDbAsyncEnumerable(IEnumerable<T> enumerable)
: base(enumerable)
{ }

public InMemoryDbAsyncEnumerable(Expression expression)
: base(expression)
{ }

public IQueryProvider Provider => new InMemoryDbAsyncQueryProvider<T>(this);

public IDbAsyncEnumerator<T> GetAsyncEnumerator()
{
return new InMemoryDbAsyncEnumerator<T>(this.AsEnumerable().GetEnumerator());
}

IDbAsyncEnumerator IDbAsyncEnumerable.GetAsyncEnumerator()
{
return GetAsyncEnumerator();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#nullable enable

namespace Snittlistan.Test.ApiControllers.Infrastructure
{
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Threading;
using System.Threading.Tasks;

public class InMemoryDbAsyncEnumerator<T> : IDbAsyncEnumerator<T>
{
private readonly IEnumerator<T> _inner;

public InMemoryDbAsyncEnumerator(IEnumerator<T> inner)
{
_inner = inner;
}

public T Current => _inner.Current;

object? IDbAsyncEnumerator.Current => Current;

public void Dispose()
{
_inner.Dispose();
}

public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
return Task.FromResult(_inner.MoveNext());
}
}
}
Loading

0 comments on commit 2898496

Please sign in to comment.