public async Task GetGroups_ForNotNullParent_ReturnItems() { // arrange var cancellationToken = CancellationToken.None; var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var dbContextFactory = new DefaultDbContextFactory(); var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory); var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory); var classifierTypeService = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository); var classifierTreeService = new DefaultClassifierTreeService(classifierTreeRepository); var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new GetClassifierGroupListHandler(dbContextFactory, classifierTypeService, classifierTreeService); using (var _ = unitOfWorkFactory.Create()) { // arrange await generator.InsertType(HierarchyType.Groups, cancellationToken); var tree = await generator.FindTree(ClassifierTree.DefaultCode, cancellationToken); var parentGroup = await generator.InsertGroup(tree.Uid, "001", null, cancellationToken); await generator.InsertGroup(tree.Uid, "001.001", parentGroup.Uid, cancellationToken); await generator.InsertGroup(tree.Uid, "001.002", parentGroup.Uid, cancellationToken); await generator.InsertGroup(tree.Uid, "001.003", parentGroup.Uid, cancellationToken); await generator.InsertGroup(tree.Uid, "001.004", parentGroup.Uid, cancellationToken); await generator.InsertGroup(tree.Uid, "001.005", parentGroup.Uid, cancellationToken); await generator.InsertGroup(tree.Uid, "001.006", parentGroup.Uid, cancellationToken); await generator.InsertGroup(tree.Uid, "001.007", parentGroup.Uid, cancellationToken); // act var command = new GetClassifierGroupList { TypeCode = generator.TypeCode, TreeUid = tree.Uid, ParentUid = parentGroup.Uid, }; var result = await handler.Handle(command, cancellationToken); // assert Assert.IsNotNull(result); Assert.AreEqual(7, result.Rows.Count); } }
public MasterDataDbGenerator(IUnitOfWorkFactory unitOfWorkFactory, IDbContextFactory dbContextFactory) { _dbContextFactory = dbContextFactory; var dateTimeProvider = new DefaultDateTimeProvider(); var jsonSerializer = new NewtonsoftJsonSerializer(); var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory); var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory); var fieldProviderRegistry = new DefaultFieldProviderRegistry(); fieldProviderRegistry.AddFieldType(typeof(TextField)); fieldProviderRegistry.AddFieldType(typeof(TextAreaField)); var dbFieldMetadataRepository = new DbFieldMetadataRepository(dbContextFactory, fieldProviderRegistry, jsonSerializer); var dbFieldDataRepository = new DbFieldDataRepository(dbContextFactory, fieldProviderRegistry); var dbFieldMetadataService = new DbFieldMetadataService(dbContextFactory, dateTimeProvider, jsonSerializer); _classifierTypeService = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository); _getClassifierTreeListHandler = new GetClassifierTreeListHandler(classifierTreeRepository); _insertClassifierTreeTypeHandler = new InsertClassifierTreeHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService); _insertClassifierTypeHandler = new InsertClassifierTypeHandler(unitOfWorkFactory, _classifierTypeService, dbFieldMetadataService); _insertClassifierGroupHandler = new InsertClassifierGroupHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService); _classifierTypeRegistrator = new DefaultClassifierTypeRegistrator(new NullLogger <DefaultClassifierTypeRegistrator>(), unitOfWorkFactory, _classifierTypeService, dbFieldMetadataService); var classifierTypeMetadataService = new ClassifierTypeMetadataService(dbFieldMetadataRepository); var classifierTreeService = new DefaultClassifierTreeService(classifierTreeRepository); var dbNumberGenerator = new DbNumberGenerator(dbContextFactory, null, dateTimeProvider, null); var classifierRepositoryFactory = new ClassifierRepositoryFactory(new DbClassifierRepository <Classifier>( dbContextFactory, _classifierTypeService, classifierTreeService, classifierTypeMetadataService, dbFieldDataRepository, dbNumberGenerator)); _insertClassifierHandler = new InsertClassifierHandler(unitOfWorkFactory, classifierRepositoryFactory); _updateClassifierGroupHandler = new UpdateClassifierGroupHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService); _deleteClassifierGroupHandler = new DeleteClassifierGroupHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService); _insertClassifierLinkHandler = new InsertClassifierLinkHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService); _getClassifierLinkListHandler = new GetClassifierLinkListHandler(dbContextFactory, _classifierTypeService); }
public async Task GetItems_ForNotNullParent_ReturnItems() { // arrange var cancellationToken = CancellationToken.None; var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var dbContextFactory = new DefaultDbContextFactory(); var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory); var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory); var classifierTypeService = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository); var classifierTreeService = new DefaultClassifierTreeService(classifierTreeRepository); var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new GetClassifierGroupListHandler(dbContextFactory, classifierTypeService, classifierTreeService); using (var _ = unitOfWorkFactory.Create()) { // arrange await generator.InsertType(HierarchyType.Items, cancellationToken); var parentItem = await generator.InsertItem("001", null, cancellationToken); for (var i = 0; i < 3; i++) { await generator.InsertItem($"{i:D4}", parentItem.Uid, cancellationToken); } // act var command = new GetClassifierGroupList { TypeCode = generator.TypeCode, ParentUid = parentItem.Uid }; var result = await handler.Handle(command, cancellationToken); // assert Assert.IsNotNull(result); Assert.AreEqual(3, result.Rows.Count); } }
public async Task GetItems_ForBigGroups_ReturnNoMoreThan1000Items() { // arrange var cancellationToken = CancellationToken.None; var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var dbContextFactory = new DefaultDbContextFactory(); var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory); var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory); var classifierTypeService = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository); var classifierTreeService = new DefaultClassifierTreeService(classifierTreeRepository); var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new GetClassifierGroupListHandler(dbContextFactory, classifierTypeService, classifierTreeService); using (var _ = unitOfWorkFactory.Create()) { // arrange await generator.InsertType(HierarchyType.Groups, cancellationToken); var tree = await generator.FindTree(ClassifierTree.DefaultCode, cancellationToken); // todo: generate a lot of groups // act var command = new GetClassifierGroupList { TypeCode = generator.TypeCode, TreeUid = tree.Uid }; var result = await handler.Handle(command, cancellationToken); // assert Assert.IsNotNull(result); Assert.IsTrue(result.Rows.Count <= 1000); } }
public async Task GetGroups_WithFocusUid_ReturnChildrenOfEachParentGroups() { // arrange var cancellationToken = CancellationToken.None; var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var dbContextFactory = new DefaultDbContextFactory(); var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory); var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory); var classifierTypeService = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository); var classifierTreeService = new DefaultClassifierTreeService(classifierTreeRepository); var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new GetClassifierGroupListHandler(dbContextFactory, classifierTypeService, classifierTreeService); using (var _ = unitOfWorkFactory.Create()) { // arrange await generator.InsertType(HierarchyType.Groups, cancellationToken); var tree = await generator.FindTree(ClassifierTree.DefaultCode, cancellationToken); // 2 roots without parent for (var i = 0; i < 2; i++) { await generator.InsertGroup(tree.Uid, $"1-{i:D4}", null, cancellationToken); } // 1 root with 4 deep children Guid?parentUid = null; for (var i = 0; i <= 5; i++) { var childGroup = await generator.InsertGroup(tree.Uid, $"2-{i:D4}", parentUid, cancellationToken); parentUid = childGroup.Uid; } // 3 roots without parent for (var i = 0; i < 3; i++) { await generator.InsertGroup(tree.Uid, $"3-{i:D4}", null, cancellationToken); } var focusUid = parentUid; // act & assert - focus in root scope var command = new GetClassifierGroupList { TypeCode = generator.TypeCode, TreeUid = tree.Uid, ParentUid = null, FocusUid = focusUid // PageSize = 100 // todo: common limit for all levels is not ok }; var result = await handler.Handle(command, cancellationToken); // todo: pretty print and compare by focus.txt Assert.IsNotNull(result); Assert.AreEqual(6, result.Rows.Count); Assert.IsNull(result.Rows[0].Children); Assert.IsNull(result.Rows[1].Children); Assert.IsNull(result.Rows[3].Children); Assert.IsNull(result.Rows[4].Children); Assert.IsNull(result.Rows[5].Children); Assert.IsNotNull(result.Rows[2].Children); Assert.AreEqual(result.Rows[2].Children.Count, 1); // 0 lvl Assert.AreEqual(result.Rows[2].Children[0].Children.Count, 1); // 1 lvl Assert.AreEqual(result.Rows[2].Children[0].Children[0].Children.Count, 1); // 2 lvl Assert.AreEqual(result.Rows[2].Children[0].Children[0].Children[0].Children.Count, 1); // 3 lvl Assert.AreEqual(result.Rows[2].Children[0].Children[0].Children[0].Children[0].Children.Count, 1); // 4 lvl Assert.IsNull(result.Rows[2].Children[0].Children[0].Children[0].Children[0].Children[0].Children); // act & assert - focus in scope of selected parent // todo: what is the difference with previous asserts - ParentUid should be set? command = new GetClassifierGroupList { TypeCode = generator.TypeCode, TreeUid = tree.Uid, FocusUid = focusUid }; result = await handler.Handle(command, cancellationToken); // todo: pretty print and compare by focus.txt Assert.IsNotNull(result); Assert.AreEqual(6, result.Rows.Count); Assert.IsNull(result.Rows[0].Children); Assert.IsNull(result.Rows[1].Children); Assert.IsNull(result.Rows[3].Children); Assert.IsNull(result.Rows[4].Children); Assert.IsNull(result.Rows[5].Children); Assert.IsNotNull(result.Rows[2].Children); Assert.AreEqual(result.Rows[2].Children.Count, 1); // 0 lvl Assert.AreEqual(result.Rows[2].Children[0].Children.Count, 1); // 1 lvl Assert.AreEqual(result.Rows[2].Children[0].Children[0].Children.Count, 1); // 2 lvl Assert.AreEqual(result.Rows[2].Children[0].Children[0].Children[0].Children.Count, 1); // 3 lvl Assert.AreEqual(result.Rows[2].Children[0].Children[0].Children[0].Children[0].Children.Count, 1); // 4 lvl Assert.IsNull(result.Rows[2].Children[0].Children[0].Children[0].Children[0].Children[0].Children); } }