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_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_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 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 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()); }