コード例 #1
0
        public async Task Register_NormalValues_RegisterClassifierType()
        {
            // arrange
            var cancellationToken        = new CancellationToken();
            var unitOfWorkFactory        = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory         = new DefaultDbContextFactory();
            var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory);
            var classifierTypeService    = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository);
            var dbFieldMetadataService   = new DbFieldMetadataService(dbContextFactory, new DefaultDateTimeProvider(), new NewtonsoftJsonSerializer());

            var handler = new DefaultClassifierTypeRegistrator(
                new NullLogger <DefaultClassifierTypeRegistrator>(),
                unitOfWorkFactory, classifierTypeService, dbFieldMetadataService);

            using (var _ = unitOfWorkFactory.Create())
            {
                // act
                var command = new RegisterClassifierType
                {
                    Item = new ClassifierType
                    {
                        Code     = "new_classifier_registration",
                        Name     = "New Classifier Registration",
                        IsSystem = true
                    },
                    Fields = new List <FieldMetadata>
                    {
                        new TextField {
                            Key = "code", Name = "Code", Active = true, System = true
                        },
                        new TextField {
                            Key = "name", Name = "Name", Active = true, System = true
                        },
                    }
                };

                var result = await handler.Register(command.Item, command.Fields, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.AreNotEqual(Guid.Empty, result.Uid);
            }
        }
コード例 #2
0
        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);
        }