コード例 #1
0
        public async Task GenerateNumber_IndependentNumerator_ShouldGenerate()
        {
            // arrange
            var cancellationToken    = new CancellationToken();
            var unitOfWorkFactory    = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory     = new DefaultDbContextFactory();
            var dateTimeProvider     = new DefaultDateTimeProvider();
            var generator            = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var numeratorTagProvider = new TestNumberTagResolver {
                EntityTypeCode = NumerableEntityTypeCode
            };
            var classifierRepositoryFactory = CreateClassifierRepositoryFactory(dbContextFactory);
            var service = new DbNumberGenerator(dbContextFactory, classifierRepositoryFactory, dateTimeProvider, new INumberTagResolver[] { numeratorTagProvider });

            using (var _ = unitOfWorkFactory.Create())
            {
                var request = new GenerateNumberRequest
                {
                    EntityTypeCode = NumerableEntityTypeCode,
                    EntityTypeUid  = Guid.NewGuid()
                };

                await generator.InsertNumerator(new Numerator
                {
                    Pattern = "{Company}-{Number}",
                    KeyTags = new[] { "Company" }
                }, request, cancellationToken);

                // act
                numeratorTagProvider.Values = new Dictionary <string, string> {
                    { "Company", "MT" }
                };
                var number1 = await service.GenerateNumber(request, cancellationToken);

                var number2 = await service.GenerateNumber(request, cancellationToken);

                numeratorTagProvider.Values = new Dictionary <string, string> {
                    { "Company", "GT" }
                };
                var number3 = await service.GenerateNumber(request, cancellationToken);

                var number4 = await service.GenerateNumber(request, cancellationToken);

                // assert
                Assert.AreEqual("MT-00001", number1);
                Assert.AreEqual("MT-00002", number2);
                Assert.AreEqual("GT-00001", number3);
                Assert.AreEqual("GT-00002", number4);
            }
        }
コード例 #2
0
        public async Task GenerateNumber_WithPeriodTags_ShouldGenerate()
        {
            // arrange
            var cancellationToken    = new CancellationToken();
            var unitOfWorkFactory    = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory     = new DefaultDbContextFactory();
            var dateTimeProvider     = new DefaultDateTimeProvider();
            var generator            = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var numeratorTagProvider = new TestNumberTagResolver {
                EntityTypeCode = NumerableEntityTypeCode
            };
            var classifierRepositoryFactory = CreateClassifierRepositoryFactory(dbContextFactory);
            var service = new DbNumberGenerator(dbContextFactory, classifierRepositoryFactory, dateTimeProvider, new INumberTagResolver[] { numeratorTagProvider });

            using (var _ = unitOfWorkFactory.Create())
            {
                var request = new GenerateNumberRequest
                {
                    EntityTypeCode = NumerableEntityTypeCode,
                    EntityTypeUid  = Guid.NewGuid()
                };

                await generator.InsertNumerator(new Numerator
                {
                    Periodicity = NumeratorPeriodicity.Year,
                    Pattern     = "{Company}-{Number}-{Day}-{Month}-{Quarter}-{Year2}-{Year4}"
                }, request, cancellationToken);

                // act
                numeratorTagProvider.Values = new Dictionary <string, string> {
                    { "Company", "MT" }
                };
                numeratorTagProvider.Date = new DateTime(2003, 2, 5);
                var number1 = await service.GenerateNumber(request, cancellationToken);

                numeratorTagProvider.Date = new DateTime(1999, 10, 30);
                var number2 = await service.GenerateNumber(request, cancellationToken);

                // assert
                Assert.AreEqual("MT-00001-05-02-1-03-2003", number1);
                Assert.AreEqual("MT-00001-30-10-4-99-1999", number2);
            }
        }
コード例 #3
0
        public async Task InsertGroup_Should_BuildClosureTable()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();

            var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);

            using (var _ = unitOfWorkFactory.Create())
            {
                // arrange
                await generator.InsertType(HierarchyType.Groups, cancellationToken);

                var root = await generator.FindTree(ClassifierTree.DefaultCode, cancellationToken);

                // act
                await generator.InsertGroups(root.Uid, 2, 3, null, null, cancellationToken);

                // assert
                var closure = generator.PrintClosure(root.Code);
                await AssertClosureEqual("../../../Content/closure.2x3.txt", closure, cancellationToken);
            }
        }
コード例 #4
0
        public async Task GenerateNumber_QuarterPeriodicity_ShouldGenerate()
        {
            // arrange
            var cancellationToken    = new CancellationToken();
            var unitOfWorkFactory    = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory     = new DefaultDbContextFactory();
            var dateTimeProvider     = new DefaultDateTimeProvider();
            var generator            = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var numeratorTagProvider = new TestNumberTagResolver
            {
                EntityTypeCode = NumerableEntityTypeCode,
                Values         = new Dictionary <string, string>()
            };
            var classifierRepositoryFactory = CreateClassifierRepositoryFactory(dbContextFactory);
            var service = new DbNumberGenerator(dbContextFactory, classifierRepositoryFactory, dateTimeProvider, new INumberTagResolver[] { numeratorTagProvider });

            using (var _ = unitOfWorkFactory.Create())
            {
                var request = new GenerateNumberRequest
                {
                    EntityTypeCode = NumerableEntityTypeCode,
                    EntityTypeUid  = Guid.NewGuid()
                };

                await generator.InsertNumerator(new Numerator
                {
                    Periodicity = NumeratorPeriodicity.Quarter,
                    Pattern     = "{Company}-{Number}/{Year4}"
                }, request, cancellationToken);

                numeratorTagProvider.Values = new Dictionary <string, string> {
                    { "Company", "MT" }
                };

                // act - Q1.2020 - first time
                numeratorTagProvider.Date = new DateTime(2020, 01, 31);
                var number1OfQ1 = await service.GenerateNumber(request, cancellationToken);

                var number2OfQ1 = await service.GenerateNumber(request, cancellationToken);

                // assert - Q1.2020 - first time
                Assert.AreEqual("MT-00001/2020", number1OfQ1);
                Assert.AreEqual("MT-00002/2020", number2OfQ1);

                // act - Q3.2020
                numeratorTagProvider.Date = new DateTime(2020, 07, 30);
                var number1OfQ3 = await service.GenerateNumber(request, cancellationToken);

                var number2OfQ3 = await service.GenerateNumber(request, cancellationToken);

                // assert - Q3.2020
                Assert.AreEqual("MT-00001/2020", number1OfQ3);
                Assert.AreEqual("MT-00002/2020", number2OfQ3);

                // act - Q1.2020 - second time
                numeratorTagProvider.Date = new DateTime(2020, 02, 29);
                var number3OfQ1 = await service.GenerateNumber(request, cancellationToken);

                var number4OfQ1 = await service.GenerateNumber(request, cancellationToken);

                // assert - Q1.2020 - second time
                Assert.AreEqual("MT-00003/2020", number3OfQ1);
                Assert.AreEqual("MT-00004/2020", number4OfQ1);
            }
        }