Skip to content

Instantly share code, notes, and snippets.

View Alexei000's full-sized avatar

Alex Dragan Alexei000

View GitHub Profile
@Alexei000
Alexei000 / Startup_hangfire.cs
Created August 29, 2019 09:37
Startup configuration for Hangfire
using Hangfire;
using Hangfire.SqlServer;
/// <summary>
/// specifies if hangfire job run or not
/// </summary>
protected bool HangFireEnabled => Configuration.GetSection("GeneralApplicationSettings").GetValue<bool>("HangFireEnabled");
/// <summary>
/// configures Hangfire functionality (async jobs)
@Alexei000
Alexei000 / Startup_recurring.cs
Last active August 29, 2019 09:32
Recurring job with Hangfire
RecurringJob.AddOrUpdate<UserGroupRolesSyncService>(nameof(UserGroupRolesSyncService),
x => x.SyncUserGroupRolesData(),
"0 10 17 * * *");
using Hangfire;
using Hangfire.SqlServer;
/// <summary>
/// specifies if hangfire job run or not
/// </summary>
protected bool HangFireEnabled => Configuration.GetSection("GeneralApplicationSettings").GetValue<bool>("HangFireEnabled");
/// <summary>
/// configures Hangfire functionality (async jobs)
using Hangfire;
using Hangfire.SqlServer;
/// <summary>
/// specifies if hangfire job run or not
/// </summary>
protected bool HangFireEnabled => Configuration.GetSection("GeneralApplicationSettings").GetValue<bool>("HangFireEnabled");
/// <summary>
/// configures Hangfire functionality (async jobs)
@Alexei000
Alexei000 / gist:ec864b1ef6e8473fb24cb21dfa95b998
Created April 3, 2018 13:13
EnvironmentProxyService rebind
Kernel.Rebind<IEnvironmentProxyService>().To<EnvironmentProxyServiceMock>();
@Alexei000
Alexei000 / EnvironmentProxyServiceMock.cs
Created April 3, 2018 13:11
Environment proxy service mock class
public class EnvironmentProxyServiceMock : IEnvironmentProxyService
{
public List<EnvironmentServiceModel> Environments => EnvironmentInitialData.EnvironmentServiceModels;
public Dictionary<int, EnvironmentServiceModel> EnvironmentsMap => Environments.ToDictionary(item => item.EnvironmentId, item => item);
public EnvironmentServiceModel Get(int environmentId) => EnvironmentsMap.ContainsKey(environmentId) ? EnvironmentsMap[environmentId] : null;
public List<EnvironmentTypeApiModel> EnvironmentTypes => EnvironmentInitialData.EnvironmentTypeModels;
@Alexei000
Alexei000 / EnvironmentService.cs
Created March 28, 2018 15:35
Get all environments
/// <summary>
/// gets a list of environment service models
/// </summary>
/// <param name="applySecurity">specifies if current user security rules should be applied</param>
/// <param name="enabledOnly">specifies if only enabled environments will be returned</param>
/// <returns>a list of environment service models</returns>
public List<EnvironmentServiceModel> GetAllEnvironments(bool applySecurity, bool enabledOnly)
{
var serviceModels = EnvironmentProxyService.Environments.Where(env => !enabledOnly || env.IsEnabled);
if (!applySecurity)
@Alexei000
Alexei000 / EnvironmentServiceTest.cs
Created March 28, 2018 15:33
get all environments test
[Test]
public void GetAllEnvironmentsTest()
{
//DEV USER -> Only Enabled
ResetData(currentUserId: 1000);
var envDataDev1 = EnvironmentService.GetAllEnvironments(applySecurity: true, enabledOnly: true);
Assert.IsTrue(envDataDev1.Count == 2, "GetAllEnvironments count failed for enabled only");
//DEV USER -> Enabled and Disabled
ResetData(currentUserId: 1000);
@Alexei000
Alexei000 / BaseTest3.cs
Created March 28, 2018 15:24
Fake current user
public void FakeCurrentUser(int userId)
{
var userRef = DataAccess.AppUserRepository.AllNoTracking.FirstOrDefault(u => u.AppUserId == userId);
var securitySubstitude = Substitute.ForPartsOf<SecurityService>(
Kernel.Get<IScopedDataAccess>(),
Kernel.Get<IMappingService>(),
Kernel.Get<ILoggingService>(),
Kernel.Get<IEnvironmentProxyService>());
@Alexei000
Alexei000 / BaseTest2.cs
Created March 28, 2018 15:19
Register custom services
protected void RegisterCustomServicesForServiceTesting()
{
// IRepository<T> should be solved using InMemoryRepository<T>, by default
Kernel.Rebind(typeof(IRepository<>)).To(typeof(InMemoryRepository<>));
// IRepository<T> must be solved to Repository<T>, if used in CachedRepository<T>
Kernel.Rebind(typeof(IRepository<>)).To(typeof(InMemoryRepository<>)).WhenInjectedInto(typeof(CachedRepository<>));
var nonCachedTypes = NinjectCommon.GetNonCachedTypes();
nonCachedTypes.ForEach(type =>