public async Task WorkItemService_Reschedule_WorkItemRescheduled() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); var repository = serviceProvider.GetRequiredService <IWorkItemRepository>(); var workItems = this.GetWorkItems(); await context.WorkItems.AddRangeAsync(workItems); await context.SaveChangesAsync(); var dueDate = SystemTime.Now().AddMinutes(1); var model = new tomware.Microwf.Infrastructure.WorkItemDto { Id = 1, DueDate = dueDate }; // Act await service.Reschedule(model); // Assert var rescheduledItem = await repository.GetByIdAsync(1); Assert.NotNull(rescheduledItem); Assert.Equal(rescheduledItem.DueDate, dueDate); }
public void WorkflowService_GetWorkflowDefinitions_ReturnsOneDefiniton() { // Arrange var diHelper = new DITestHelper(); diHelper.AddTestDbContext(); diHelper.Services.AddScoped <IWorkflowDefinitionProvider, SimpleWorkflowDefinitionProvider>(); diHelper.Services.AddTransient <IUserWorkflowMappingService, TestUserWorkflowMappingService>(fact => { return(new TestUserWorkflowMappingService(new List <IWorkflowDefinition> { new HolidayApprovalWorkflow() })); }); diHelper.Services.AddTransient <IWorkflowDefinitionDtoCreator, TestWorkflowDefinitionViewModelCreator>(); diHelper.Services.AddTransient <IUserContextService, TestUserContextService>(); diHelper.Services.AddTransient <IWorkflowRepository, WorkflowRepository <TestDbContext> >(); diHelper.Services.AddTransient <IWorkflowService, WorkflowService>(); var serviceProvider = diHelper.Build(); var workflowDefinitionProvider = serviceProvider.GetRequiredService <IWorkflowDefinitionProvider>(); workflowDefinitionProvider.RegisterWorkflowDefinition(new HolidayApprovalWorkflow()); workflowDefinitionProvider.RegisterWorkflowDefinition(new OnOffWorkflow()); var workflowService = serviceProvider.GetRequiredService <IWorkflowService>(); // Act var result = workflowService.GetWorkflowDefinitions(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); Assert.AreEqual(HolidayApprovalWorkflow.TYPE, result.First().Type); }
public async Task WorkItemService_PersistWorkItemsAsync_OneItemPersistedOneItemUpdated() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); var workItems = this.GetWorkItems(); var firstWorkItem = workItems.First(); firstWorkItem.WorkflowType = "firstCopy"; await context.WorkItems.AddAsync(firstWorkItem); await context.SaveChangesAsync(); firstWorkItem.WorkflowType = "first"; // Act await service.PersistWorkItemsAsync(workItems); // Assert Assert.Equal(2, context.WorkItems.Count()); Assert.Equal("first", context.WorkItems.First().WorkflowType); }
public IActionResult TestDIScope() { DITestHelper dihelper = new DITestHelper(); dihelper.DifScope(); return(Ok("Seccuss")); }
public void Initialize() { var options = TestDbContext.CreateDbContextOptions(); Context = new TestDbContext(options); var diHelper = new DITestHelper(); var loggerFactory = diHelper.GetLoggerFactory(); ILogger <WorkflowService <TestDbContext> > logger = loggerFactory .CreateLogger <WorkflowService <TestDbContext> >(); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new HolidayApprovalWorkflow()); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new OnOffWorkflow()); IUserWorkflowMappingService userWorkflowMappingService = new TestUserWorkflowMappingService(); IWorkflowDefinitionViewModelCreator workflowDefinitionViewModelCreator = new TestWorkflowDefinitionViewModelCreator(); IUserContextService userContextService = new TestUserContextService(); this.WorkflowService = new WorkflowService <TestDbContext>( Context, logger, SimpleWorkflowDefinitionProvider.Instance, userWorkflowMappingService, workflowDefinitionViewModelCreator, userContextService ); }
public async Task WorkItemService_PersistWorkItemsAsync_OneItemPersistedOneItemUpdated() { // Arrange var options = TestDbContext.CreateDbContextOptions(); var context = new TestDbContext(options); var workItems = GetWorkItems(); var firstWorkItem = workItems.First(); firstWorkItem.WorkflowType = "firstCopy"; await context.WorkItems.AddAsync(firstWorkItem); await context.SaveChangesAsync(); firstWorkItem.WorkflowType = "first"; var diHelper = new DITestHelper(); var loggerFactory = diHelper.GetLoggerFactory(); ILogger <WorkItemService <TestDbContext> > logger = loggerFactory .CreateLogger <WorkItemService <TestDbContext> >(); var service = new WorkItemService <TestDbContext>(context, logger); // Act await service.PersistWorkItemsAsync(workItems); // Assert Assert.AreEqual(2, context.WorkItems.Count()); Assert.AreEqual("first", context.WorkItems.First().WorkflowType); }
public async Task WorkItemService_DeleteAsync_OneItemDeleted() { // Arrange var options = TestDbContext.CreateDbContextOptions(); var context = new TestDbContext(options); var workItems = GetWorkItems(); await context.WorkItems.AddRangeAsync(workItems); await context.SaveChangesAsync(); var diHelper = new DITestHelper(); var loggerFactory = diHelper.GetLoggerFactory(); ILogger <WorkItemService <TestDbContext> > logger = loggerFactory .CreateLogger <WorkItemService <TestDbContext> >(); var service = new WorkItemService <TestDbContext>(context, logger); // Act var result = await service.DeleteAsync(1); // Assert Assert.AreEqual(1, result); Assert.AreEqual(1, context.WorkItems.Count()); Assert.AreEqual(2, context.WorkItems.First().Id); }
public async Task WorkItemService_GetFailedAsync_FailedReturned() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); var workItems = this.GetWorkItems(); workItems.First().Retries = 4; await context.WorkItems.AddRangeAsync(workItems); await context.SaveChangesAsync(); var parameters = new PagingParameters(); // Act var failed = await service.GetFailedAsync(parameters); // Assert Assert.NotNull(failed); Assert.Single(failed); Assert.Equal(1, failed.First().Id); Assert.Equal(4, failed.First().Retries); }
public void Initialize() { var diHelper = new DITestHelper(); diHelper.AddTestDbContext(); diHelper.Services.Configure <WorkflowConfiguration>(config => { config.Types = new List <WorkflowType> { new WorkflowType { Type = EntityOnOffWorkflow.TYPE } }; }); diHelper.Services.AddScoped <IWorkflowDefinitionProvider, SimpleWorkflowDefinitionProvider>(); diHelper.Services.AddTransient <IUserWorkflowMappingService, TestUserWorkflowMappingService>(fact => { return(new TestUserWorkflowMappingService()); }); diHelper.Services.AddTransient <IWorkflowDefinitionDtoCreator, TestWorkflowDefinitionViewModelCreator>(); diHelper.Services.AddTransient <IUserContextService, TestUserContextService>(); diHelper.Services.AddTransient <IWorkflowRepository, WorkflowRepository <TestDbContext> >(); diHelper.Services.AddTransient <IWorkflowService, WorkflowService>(); var serviceProvider = diHelper.Build(); this.Context = serviceProvider.GetRequiredService <TestDbContext>(); this.WorkflowDefinitionProvider = serviceProvider.GetRequiredService <IWorkflowDefinitionProvider>(); this.WorkflowDefinitionProvider.RegisterWorkflowDefinition(new EntityOnOffWorkflow()); this.WorkflowDefinitionProvider.RegisterWorkflowDefinition(new HolidayApprovalWorkflow()); this.WorkflowDefinitionProvider.RegisterWorkflowDefinition(new OnOffWorkflow()); this.WorkflowService = serviceProvider.GetRequiredService <IWorkflowService>(); }
public async Task WorkItemService_GetUpCommingsAsync_UpCommingsReturned() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); var dueDate = SystemTime.Now().AddMinutes(2); var workItems = this.GetWorkItems(dueDate); await context.WorkItems.AddRangeAsync(workItems); await context.SaveChangesAsync(); var parameters = new PagingParameters(); // Act var upcommings = await service.GetUpCommingsAsync(parameters); // Assert Assert.NotNull(upcommings); Assert.Equal(2, upcommings.Count); }
private void Initialize() { var diHelper = new DITestHelper(); diHelper.AddTestDbContext(); diHelper.Services.AddScoped <IWorkflowDefinitionProvider, SimpleWorkflowDefinitionProvider>(); diHelper.Services.AddTransient <IUserWorkflowMappingService, TestUserWorkflowMappingService>(fact => { return(new TestUserWorkflowMappingService()); }); diHelper.Services.AddTransient <IWorkflowDefinitionDtoCreator, TestWorkflowDefinitionViewModelCreator>(); diHelper.Services.AddTransient <IUserContextService, TestUserContextService>(); diHelper.Services.AddTransient <IWorkflowService, WorkflowService>(); diHelper.Services.AddTransient <IWorkflowRepository, WorkflowRepository <TestDbContext> >(); diHelper.Services.AddTransient <IWorkflowEngineService, WorkflowEngineService>(); var serviceProvider = diHelper.Build(); this.Context = serviceProvider.GetRequiredService <TestDbContext>(); this.WorkflowDefinitionProvider = serviceProvider.GetRequiredService <IWorkflowDefinitionProvider>(); this.WorkflowDefinitionProvider.RegisterWorkflowDefinition(new HolidayApprovalWorkflow()); this.WorkflowDefinitionProvider.RegisterWorkflowDefinition(new OnOffWorkflow()); this.WorkflowDefinitionProvider.RegisterWorkflowDefinition(new EntityOnOffWorkflow()); this.WorkflowEngineService = serviceProvider.GetRequiredService <IWorkflowEngineService>(); }
public async Task WorkItemService_PersistWorkItemsAsync_TwoItemsPersisted() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); var workItems = this.GetWorkItems(); // Act await service.PersistWorkItemsAsync(workItems); // Assert Assert.Equal(2, context.WorkItems.Count()); }
public void WorkflowService_GetWorkflowDefinitions_ReturnsOneDefiniton() { // Arrange SimpleWorkflowDefinitionProvider.Instance.Invalidate(); var options = TestDbContext.CreateDbContextOptions(); Context = new TestDbContext(options); var diHelper = new DITestHelper(); var loggerFactory = diHelper.GetLoggerFactory(); ILogger <WorkflowService <TestDbContext> > logger = loggerFactory .CreateLogger <WorkflowService <TestDbContext> >(); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new HolidayApprovalWorkflow()); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new OnOffWorkflow()); var filters = SimpleWorkflowDefinitionProvider.Instance .GetWorkflowDefinitions().Where(_ => _.Type == HolidayApprovalWorkflow.TYPE); IUserWorkflowMappingService userWorkflowMappingService = new TestUserWorkflowMappingService(filters); IWorkflowDefinitionViewModelCreator workflowDefinitionViewModelCreator = new TestWorkflowDefinitionViewModelCreator(); IUserContextService userContextService = new TestUserContextService(); var service = new WorkflowService <TestDbContext>( Context, logger, SimpleWorkflowDefinitionProvider.Instance, userWorkflowMappingService, workflowDefinitionViewModelCreator, userContextService ); // Act var result = service.GetWorkflowDefinitions(); // Assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); Assert.AreEqual(HolidayApprovalWorkflow.TYPE, result.First().Type); }
public async Task WorkItemService_PersistWorkItemsAsync_TwoItemsPersisted() { // Arrange var options = TestDbContext.CreateDbContextOptions(); var context = new TestDbContext(options); var diHelper = new DITestHelper(); var logger = diHelper.GetLoggerFactory() .CreateLogger <WorkItemService <TestDbContext> >(); var workItems = GetWorkItems(); var service = new WorkItemService <TestDbContext>(context, logger); // Act await service.PersistWorkItemsAsync(workItems); // Assert Assert.AreEqual(2, context.WorkItems.Count()); }
public async Task WorkItemService_ResumeWorkItemsAsync_TwoItemsResumed() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); await context.WorkItems.AddRangeAsync(this.GetWorkItems()); await context.SaveChangesAsync(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); // Act IEnumerable <WorkItem> resumedItems = await service.ResumeWorkItemsAsync(); // Assert Assert.Equal(2, resumedItems.Count()); }
public async Task WorkItemService_DeleteAsync_OneItemDeleted() { // Arrange var diHelper = new DITestHelper(); var serviceProvider = diHelper.BuildDefault(); var context = serviceProvider.GetRequiredService <TestDbContext>(); var service = serviceProvider.GetRequiredService <IWorkItemService>(); var workItems = this.GetWorkItems(); await context.WorkItems.AddRangeAsync(workItems); await context.SaveChangesAsync(); // Act await service.DeleteAsync(1); // Assert Assert.Equal(1, context.WorkItems.Count()); Assert.Equal(2, context.WorkItems.First().Id); }
public void Initialize() { var options = TestDbContext.CreateDbContextOptions(); Context = new TestDbContext(options); var diHelper = new DITestHelper(); var loggerFactory = diHelper.GetLoggerFactory(); ILogger <WorkflowEngine <TestDbContext> > logger = loggerFactory .CreateLogger <WorkflowEngine <TestDbContext> >(); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new HolidayApprovalWorkflow()); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new OnOffWorkflow()); SimpleWorkflowDefinitionProvider.Instance .RegisterWorkflowDefinition(new EntityOnOffWorkflow()); this.WorkflowEngine = new WorkflowEngine <TestDbContext>( Context, logger, SimpleWorkflowDefinitionProvider.Instance ); }
public async Task WorkItemService_ResumeWorkItemsAsync_TwoItemsResumed() { // Arrange var options = TestDbContext.CreateDbContextOptions(); var context = new TestDbContext(options); var workItems = GetWorkItems(); await context.WorkItems.AddRangeAsync(workItems); await context.SaveChangesAsync(); var diHelper = new DITestHelper(); var loggerFactory = diHelper.GetLoggerFactory(); ILogger <WorkItemService <TestDbContext> > logger = loggerFactory .CreateLogger <WorkItemService <TestDbContext> >(); var service = new WorkItemService <TestDbContext>(context, logger); // Act IEnumerable <WorkItem> resumedItems = await service.ResumeWorkItemsAsync(); // Assert Assert.AreEqual(2, resumedItems.Count()); }