Пример #1
0
        public async Task UpdateGroup_ShouldThrow_WhenCyclicDependencyDetected()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();
            var generator         = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);

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

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

                await generator.InsertGroups(root.Uid, 3, 3, null, null, cancellationToken);
                await AssertClosureEqual("../../../Content/closure.3x3.txt", generator.PrintClosure(root.Code), cancellationToken);

                // act & assert - cyclic dependency
                var result = await generator.UpdateGroup(root.Code, "1.1", "1.1.1", cancellationToken, false);

                Assert.IsNotNull(result);
                Assert.IsFalse(result.Success);
                Assert.IsNotNull(result.Errors);
                Assert.AreEqual("parentUid", result.Errors[0].Key);
                Assert.AreEqual("Cyclic dependency detected.", result.Errors[0].Messages[0]);
            }
        }
Пример #2
0
        public async Task Handle_NormalValues_RegisterExternalUser()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();

            var identityServiceFactory = new IdentityServiceFactory();

            var classifierRepositoryFactoryBuilder = new ClassifierRepositoryFactoryBuilder(dbContextFactory)
            {
                UserTypeCode = ClassifierTypeCode.User
            };
            var classifierRepositoryFactory = classifierRepositoryFactoryBuilder.Build();

            // todo: test EmailConfirmationService
            var emailConfirmationServiceMock = new Mock <IEmailConfirmationService>();

            var handler = new ExternalRegisterHandler(new NullLogger <ExternalRegisterHandler>(), classifierRepositoryFactory,
                                                      identityServiceFactory.UserManager, identityServiceFactory.SignInManager, emailConfirmationServiceMock.Object);

            using (var _ = unitOfWorkFactory.Create())
            {
                // act
                var command = new ExternalRegister
                {
                    Email = "*****@*****.**"
                };

                var result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsTrue(result.Success, string.Join(",", result.Message));
            }
        }
Пример #3
0
        public async Task UpdateGroup_Should_RebuildClosureTable()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();
            var generator         = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);

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

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

                await generator.InsertGroups(root.Uid, 3, 3, null, null, cancellationToken);
                await AssertClosureEqual("../../../Content/closure.3x3.txt", generator.PrintClosure(root.Code), cancellationToken);

                // act & assert - from null to not null parent
                await generator.UpdateGroup(root.Code, "1", "2.1", cancellationToken);
                await AssertClosureEqual("../../../Content/closure.3x3~1to2.1.txt", generator.PrintClosure(root.Code), cancellationToken);

                // act & assert - from not null to null parent
                await generator.UpdateGroup(root.Code, "2.2", null, cancellationToken);
                await AssertClosureEqual("../../../Content/closure.3x3~1to2.1~2.2toRoot.txt", generator.PrintClosure(root.Code), cancellationToken);

                // act & assert - from not null to not null parent
                await generator.UpdateGroup(root.Code, "3.3", "1.3", cancellationToken);
                await AssertClosureEqual("../../../Content/closure.3x3~1to2.1~2.2toRoot~3.3to1.3.txt", generator.PrintClosure(root.Code), cancellationToken);
            }
        }
        public async Task GetClassifierTreeList_ReturnList()
        {
            // arrange
            var cancellationToken        = new CancellationToken();
            var unitOfWorkFactory        = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory         = new DefaultDbContextFactory();
            var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory);
            var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new GetClassifierTreeListHandler(classifierTreeRepository);

            using (var _ = unitOfWorkFactory.Create())
            {
                // default tree will be insered for HierarchyType.Groups
                await generator.InsertType(HierarchyType.Groups, cancellationToken);

                // act
                var result = await handler.Handle(new GetClassifierTreeList
                {
                    TypeCode = generator.TypeCode
                }, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.TotalCount);
            }
        }
        public async Task <int?> AddUpdateDispositivoUsuario(Dispositivo dispositivo)
        {
            try
            {
                ICollection <Dispositivo> _dispositivos = null;
                Notificacao _notificacao = null;
                int?        _result      = 0;


                using (IUnitOfWork _unitOfWork = new TransactionScopeUnitOfWorkFactory(IsolationLevel.Serializable).Create())
                {
                    if (dispositivo.Notificacao != null)
                    {
                        var notificacaoId = dispositivo.Notificacao.Count > 0 ? dispositivo.Notificacao.FirstOrDefault().NotificacaoId : 0;

                        if (notificacaoId != 0)
                        {
                            _notificacao = await _notificacaoRepository.GetById(notificacaoId);
                        }
                    }

                    _dispositivos = await _dispositivoRepository.Search(p => p.Serial == dispositivo.Serial, x => x.Notificacao);


                    if (_dispositivos != null && _dispositivos.Count() > 0)
                    {
                        var dispositivoEncontrado = _dispositivos.FirstOrDefault();


                        if (dispositivoEncontrado != null && !dispositivoEncontrado.Notificacao.Contains(_notificacao))
                        {
                            dispositivoEncontrado.Notificacao.Add(_notificacao);
                        }
                        _dispositivoRepository.Update(dispositivoEncontrado);

                        _result = _dispositivoRepository.SaveChanges();
                    }
                    else
                    {
                        new List <Notificacao>().Add(_notificacao);

                        dispositivo.Notificacao.Add(_notificacao);
                        _dispositivoRepository.Add(dispositivo);

                        _result = _dispositivoRepository.SaveChanges();
                    }


                    _unitOfWork.Commit();
                }

                return(_result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #6
0
        public async Task Handle_NormalValues_RegisterUser()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();

            var appOptionsAccessorMock = new Mock <IOptionsMonitor <AppOptions> >();

            appOptionsAccessorMock.Setup(x => x.CurrentValue)
            .Returns(() => new AppOptions {
                AppUrl = "https://app.montr.net"
            });
            var appOptionsAccessor = appOptionsAccessorMock.Object;

            var identityServiceFactory = new IdentityServiceFactory();

            var classifierRepositoryFactoryBuilder = new ClassifierRepositoryFactoryBuilder(dbContextFactory)
            {
                UserTypeCode = ClassifierTypeCode.User
            };
            var classifierRepositoryFactory = classifierRepositoryFactoryBuilder.Build();

            // todo: test EmailConfirmationService

            /*
             * var dbMessageTemplateRepository = new DbMessageTemplateRepository(dbContextFactory);
             * var templateRenderer = new MustacheTemplateRenderer(dbMessageTemplateRepository);
             * var emailConfirmationService = new EmailConfirmationService(userManager, appUrlBuilder, new Mock<IEmailSender>().Object, templateRenderer);
             */

            var appUrlBuilder = new DefaultAppUrlBuilder(appOptionsAccessor);
            var emailConfirmationServiceMock = new Mock <IEmailConfirmationService>();

            var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);

            var handler = new RegisterHandler(new NullLogger <RegisterHandler>(), classifierRepositoryFactory,
                                              identityServiceFactory.UserManager, identityServiceFactory.SignInManager, appUrlBuilder, emailConfirmationServiceMock.Object);

            using (var _ = unitOfWorkFactory.Create())
            {
                await generator.EnsureClassifierTypeRegistered(Numerator.GetDefaultMetadata(), cancellationToken);

                await generator.EnsureClassifierTypeRegistered(User.GetDefaultMetadata(), cancellationToken);

                // act
                var command = new Register
                {
                    Email    = "*****@*****.**",
                    Password = Guid.NewGuid().ToString()
                };

                var result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsTrue(result.Success);
            }
        }
        public async Task Handle_WithoutExistingLink_ShouldInsertNewLink()
        {
            // 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 generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new InsertClassifierLinkHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

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

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

                var group1 = await generator.InsertGroup(root.Uid, "001", null, cancellationToken);

                var root2 = await generator.InsertTree("root2", cancellationToken);

                // ReSharper disable once PossibleInvalidOperationException
                var group2 = await generator.InsertGroup(root2.Uid.Value, "002", null, cancellationToken);

                var item1 = await generator.InsertItem("001", null, cancellationToken);

                await generator.InsertLink(group1.Uid, item1.Uid, cancellationToken);

                // assert - initially new items belongs to default group
                var links = await generator.GetLinks(null, item1.Uid, cancellationToken);

                Assert.AreEqual(1, links.TotalCount);
                Assert.AreEqual(group1.Uid, links.Rows[0].Group.Uid);
                Assert.AreEqual(item1.Uid, links.Rows[0].Item.Uid);

                // act - link with new group in same hierarchy
                var result = await handler.Handle(new InsertClassifierLink
                {
                    UserUid  = generator.UserUid,
                    TypeCode = generator.TypeCode,
                    // ReSharper disable once PossibleInvalidOperationException
                    GroupUid = group2.Uid.Value,
                    // ReSharper disable once PossibleInvalidOperationException
                    ItemUid = item1.Uid.Value
                }, cancellationToken);

                // assert - new link inserted
                Assert.IsTrue(result.Success);

                // assert - item linked to new group, link with default root still exists
                links = await generator.GetLinks(null, item1.Uid, cancellationToken);

                Assert.AreEqual(2, links.TotalCount);
                var groups = links.Rows.Select(x => x.Group.Uid).ToList();
                CollectionAssert.Contains(groups, group1.Uid);
                CollectionAssert.Contains(groups, group2.Uid);
            }
        }
Пример #8
0
        public async Task DeleteClassifier_NormalValues_DeleteItems()
        {
            // arrange
            var cancellationToken           = new CancellationToken();
            var unitOfWorkFactory           = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory            = new DefaultDbContextFactory();
            var generator                   = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var classifierRepositoryFactory = CreateClassifierRepositoryFactory(dbContextFactory);
            var handler = new DeleteClassifierHandler(unitOfWorkFactory, classifierRepositoryFactory);

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

                var insertedIds = new List <Guid>();
                for (var i = 0; i < 5; i++)
                {
                    var insertItem = await generator.InsertItem("00" + i, null, cancellationToken);

                    // ReSharper disable once PossibleInvalidOperationException
                    insertedIds.Add(insertItem.Uid.Value);
                }

                var searchResult = await classifierRepositoryFactory.GetNamedOrDefaultService(generator.TypeCode)
                                   .Search(new ClassifierSearchRequest {
                    TypeCode = generator.TypeCode
                }, cancellationToken);

                // assert
                Assert.IsNotNull(searchResult);
                Assert.AreEqual(insertedIds.Count, searchResult.Rows.Count);

                // act
                var command = new DeleteClassifier
                {
                    UserUid  = generator.UserUid,
                    TypeCode = generator.TypeCode,
                    Uids     = insertedIds.ToArray()
                };
                var result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsTrue(result.Success);
                Assert.AreEqual(insertedIds.Count, result.AffectedRows);

                searchResult = await classifierRepositoryFactory.GetNamedOrDefaultService(generator.TypeCode)
                               .Search(new ClassifierSearchRequest {
                    TypeCode = generator.TypeCode
                }, cancellationToken);

                // assert
                Assert.IsNotNull(searchResult);
                Assert.AreEqual(0, searchResult.Rows.Count);
            }
        }
Пример #9
0
        public async Task Handle_InSecondaryHierarchy_ShouldDeleteExistingLink()
        {
            // 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 dbHelper = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler  = new DeleteClassifierLinkHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

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

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

                var root2 = await dbHelper.InsertTree("root2", cancellationToken);

                // ReSharper disable once PossibleInvalidOperationException
                var group2 = await dbHelper.InsertGroup(root2.Uid.Value, "002", null, cancellationToken);

                var item1 = await dbHelper.InsertItem("001", null, cancellationToken);

                await dbHelper.InsertLink(group2.Uid, item1.Uid, cancellationToken);

                // assert - links to --default and-- secondary hierarchy exists
                var links = await dbHelper.GetLinks(null, item1.Uid, cancellationToken);

                Assert.AreEqual(1, links.TotalCount);
                var groups = links.Rows.Select(x => x.Group.Uid).ToList();
                // CollectionAssert.Contains(groups, root.Uid);
                CollectionAssert.Contains(groups, group2.Uid);

                // act
                var result = await handler.Handle(new DeleteClassifierLink
                {
                    UserUid  = dbHelper.UserUid,
                    TypeCode = dbHelper.TypeCode,
                    // ReSharper disable once PossibleInvalidOperationException
                    GroupUid = group2.Uid.Value,
                    // ReSharper disable once PossibleInvalidOperationException
                    ItemUid = item1.Uid.Value
                }, cancellationToken);

                // assert - link deleted
                Assert.IsTrue(result.Success);

                // assert - NO link to default hierarchy exists
                links = await dbHelper.GetLinks(null, item1.Uid, cancellationToken);

                Assert.AreEqual(0, links.TotalCount);
                // Assert.AreEqual(root.Uid, links.Rows[0].Group.Uid);
                // Assert.AreEqual(item1.Uid, links.Rows[0].Item.Uid);
            }
        }
Пример #10
0
        public async Task Execute_Should_UpdateEntityStatus()
        {
            // arrange
            var cancellationToken = CancellationToken.None;
            var dbContextFactory  = new DefaultDbContextFactory();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var generator         = new CoreDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler           = new UpdateEntityStatusHandler(unitOfWorkFactory, dbContextFactory);

            using (var _ = unitOfWorkFactory.Create())
            {
                // arrange
                var item1 = new EntityStatus {
                    Uid = Guid.NewGuid(), DisplayOrder = 1, Code = "drafted", Name = "Draft"
                };
                var item2 = new EntityStatus {
                    Uid = Guid.NewGuid(), DisplayOrder = 2, Code = "published", Name = "Published"
                };

                await generator.InsertEntityStatus(item1, cancellationToken);

                await generator.InsertEntityStatus(item2, cancellationToken);

                // act
                var request = new UpdateEntityStatus
                {
                    EntityTypeCode = generator.EntityTypeCode,
                    EntityUid      = generator.EntityUid,
                    Item           = new EntityStatus
                    {
                        Uid          = item1.Uid,
                        Code         = "draft",
                        Name         = "The Draft",
                        DisplayOrder = 10
                    }
                };

                var result = await handler.Handle(request, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.AreEqual(1, result.AffectedRows);

                var statuses = await generator.GetEntityStatuses(cancellationToken);

                Assert.AreEqual(2, statuses.Rows.Count);

                Assert.AreEqual(2, statuses.Rows[0].DisplayOrder);
                Assert.AreEqual("published", statuses.Rows[0].Code);
                Assert.AreEqual("Published", statuses.Rows[0].Name);

                Assert.AreEqual(10, statuses.Rows[1].DisplayOrder);
                Assert.AreEqual("draft", statuses.Rows[1].Code);
                Assert.AreEqual("The Draft", statuses.Rows[1].Name);
            }
        }
Пример #11
0
        public async Task ManageUserRoles_NormalValues_ReturnSuccess()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();

            var identityServiceFactory             = new IdentityServiceFactory();
            var classifierRepositoryFactoryBuilder = new ClassifierRepositoryFactoryBuilder(dbContextFactory);
            var classifierRepositoryFactory        = classifierRepositoryFactoryBuilder.Build();

            var roleRepository = classifierRepositoryFactory.GetNamedOrDefaultService(classifierRepositoryFactoryBuilder.RoleTypeCode);
            var userRepository = classifierRepositoryFactory.GetNamedOrDefaultService(classifierRepositoryFactoryBuilder.UserTypeCode);

            var generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);

            var addHandler    = new AddUserRolesHandler(new NullLogger <AddUserRolesHandler>(), unitOfWorkFactory, identityServiceFactory.UserManager);
            var removeHandler = new RemoveUserRolesHandler(new NullLogger <RemoveUserRolesHandler>(), unitOfWorkFactory, identityServiceFactory.UserManager);

            var roles = new[] { "test_role_1", "test_role_2", "test_role_3" };

            using (var _ = unitOfWorkFactory.Create())
            {
                await generator.EnsureClassifierTypeRegistered(Role.GetDefaultMetadata(), cancellationToken);

                await generator.EnsureClassifierTypeRegistered(User.GetDefaultMetadata(), cancellationToken);

                // arrange
                foreach (var name in roles)
                {
                    var role = await roleRepository.Insert(new Role { Uid = Guid.NewGuid(), Name = name }, cancellationToken);

                    Assert.IsTrue(role.Success, string.Join(",", role.Errors.SelectMany(x => x.Messages)));
                }

                // var dbRoles = identityServiceFactory.RoleManager.Roles.ToList();

                var user = await userRepository.Insert(new User { Uid = Guid.NewGuid(), UserName = "******" }, cancellationToken);

                Assert.IsTrue(user.Success, string.Join(",", user.Errors.SelectMany(x => x.Messages)));

                // ReSharper disable once PossibleInvalidOperationException
                var userUid = user.Uid.Value;

                // act - add roles
                var addResult = await addHandler.Handle(new AddUserRoles { UserUid = userUid, Roles = roles }, cancellationToken);

                Assert.IsTrue(addResult.Success, string.Join(",", user.Errors.SelectMany(x => x.Messages)));

                // act - remove roles
                var removeResult = await removeHandler.Handle(new RemoveUserRoles { UserUid = userUid, Roles = roles }, cancellationToken);

                Assert.IsTrue(removeResult.Success, string.Join(",", user.Errors.SelectMany(x => x.Messages)));
            }
        }
Пример #12
0
        public async Task Update_WithGetOptions_ShouldInsertAndUpdate()
        {
            // arrange
            var cancellationToken = new CancellationToken();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory  = new DefaultDbContextFactory();
            var dateTimeProvider  = new DefaultDateTimeProvider();
            var mediatorMock      = new Mock <IPublisher>();
            var repository        = new DbSettingsRepository(dbContextFactory, dateTimeProvider, mediatorMock.Object);

            using (var _ = unitOfWorkFactory.Create())
            {
                // act (insert)
                var options = repository.GetSettings <TestOptions>()
                              .Set(x => x.Number, 42)
                              .Set(x => x.Value, null)
                              .Set(x => x.State, AppState.Initialized);

                var affected = await options.Update(cancellationToken);

                // assert (insert)
                Assert.AreEqual(3, affected);

                var allSettings = await LoadSettings(dbContextFactory, cancellationToken);

                var s1 = allSettings.SingleOrDefault(x => x.Id == "Montr.Core.Tests.Services.TestOptions:Number");
                var s2 = allSettings.SingleOrDefault(x => x.Id == "Montr.Core.Tests.Services.TestOptions:Value");
                var s3 = allSettings.SingleOrDefault(x => x.Id == "Montr.Core.Tests.Services.TestOptions:State");

                Assert.IsNotNull(s1);
                Assert.AreEqual("42", s1.Value);

                Assert.IsNotNull(s2);
                Assert.AreEqual(null, s2.Value);

                Assert.IsNotNull(s3);
                Assert.AreEqual("Initialized", s3.Value);

                // act (update)
                options = repository.GetSettings <TestOptions>()
                          .Set(x => x.State, AppState.None);

                affected = await options.Update(cancellationToken);

                // assert (update)
                Assert.AreEqual(1, affected);

                allSettings = await LoadSettings(dbContextFactory, cancellationToken);

                s3 = allSettings.SingleOrDefault(x => x.Id == "Montr.Core.Tests.Services.TestOptions:State");

                Assert.IsNotNull(s3);
                Assert.AreEqual("None", s3.Value);
            }
        }
Пример #13
0
        public async Task Handle_LastLinkInDefaultHierarchy_ShouldThrow()
        {
            // 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 generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new DeleteClassifierLinkHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

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

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

                var group1 = await generator.InsertGroup(root.Uid, "001", null, cancellationToken);

                var item1 = await generator.InsertItem("001", null, cancellationToken);

                await generator.InsertLink(group1.Uid, item1.Uid, cancellationToken);

                // assert - links in default hierarchy exists
                var links = await generator.GetLinks(null, item1.Uid, cancellationToken);

                Assert.AreEqual(1, links.TotalCount);
                Assert.AreEqual(group1.Uid, links.Rows[0].Group.Uid);
                Assert.AreEqual(item1.Uid, links.Rows[0].Item.Uid);

                // act
                var result = await handler.Handle(new DeleteClassifierLink
                {
                    UserUid  = generator.UserUid,
                    TypeCode = generator.TypeCode,
                    // ReSharper disable once PossibleInvalidOperationException
                    GroupUid = group1.Uid.Value,
                    // ReSharper disable once PossibleInvalidOperationException
                    ItemUid = item1.Uid.Value
                }, cancellationToken);

                // assert - link not deleted
                Assert.IsTrue(result.Success);
                Assert.AreEqual(1, result.Errors.Count);

                // assert - link to default hierarchy root exists
                links = await generator.GetLinks(null, item1.Uid, cancellationToken);

                Assert.AreEqual(1, links.TotalCount);
                Assert.AreEqual(root.Uid, links.Rows[0].Group.Uid);
                Assert.AreEqual(item1.Uid, links.Rows[0].Item.Uid);
            }
        }
Пример #14
0
        public async Task InsertClassifier_DuplicateCode_ReturnError()
        {
            // arrange
            var cancellationToken           = new CancellationToken();
            var unitOfWorkFactory           = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory            = new DefaultDbContextFactory();
            var generator                   = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var classifierRepositoryFactory = CreateClassifierRepositoryFactory(dbContextFactory);
            var handler = new InsertClassifierHandler(unitOfWorkFactory, classifierRepositoryFactory);

            using (var _ = unitOfWorkFactory.Create())
            {
                // arrange - 1st item
                await generator.InsertType(HierarchyType.None, cancellationToken);

                var command = new InsertClassifier
                {
                    UserUid = generator.UserUid,
                    Item    = new Classifier
                    {
                        Type = generator.TypeCode,
                        Code = "001",
                        Name = "Test Classifier"
                    }
                };

                // act
                var result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsTrue(result.Success);
                Assert.IsNotNull(result.Uid);
                Assert.AreNotEqual(Guid.Empty, result.Uid);

                // arrange - 2nd item
                command.Item.Uid = Guid.NewGuid();

                // act
                result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsFalse(result.Success);
                Assert.IsNull(result.Uid);
                Assert.AreEqual(1, result.Errors.Count);
                Assert.AreEqual("code", result.Errors[0].Key);
                // todo: use error codes?
                Assert.AreEqual("Code «001» is already used in item \"Test Classifier\"", result.Errors[0].Messages[0]);
            }
        }
Пример #15
0
        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);
            }
        }
Пример #16
0
        public async Task Execute_Should_DeleteEntityStatus()
        {
            // arrange
            var cancellationToken = CancellationToken.None;
            var dbContextFactory  = new DefaultDbContextFactory();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var generator         = new CoreDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler           = new DeleteEntityStatusHandler(unitOfWorkFactory, dbContextFactory);

            using (var _ = unitOfWorkFactory.Create())
            {
                // arrange
                var uids = new List <Guid>();
                for (var i = 0; i < 42; i++)
                {
                    var insertResult = await generator.InsertEntityStatus(new EntityStatus
                    {
                        Uid  = Guid.NewGuid(),
                        Code = "status_code_" + i,
                        Name = "Status Name " + i
                    }, cancellationToken);

                    // ReSharper disable once PossibleInvalidOperationException
                    uids.Add(insertResult.Uid.Value);
                }

                // act
                var request = new DeleteEntityStatus
                {
                    EntityTypeCode = generator.EntityTypeCode,
                    EntityUid      = generator.EntityUid,
                    Uids           = uids.Take(3).ToList()
                };

                var result = await handler.Handle(request, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.AreEqual(3, result.AffectedRows);

                var statuses = await generator.GetEntityStatuses(cancellationToken);

                Assert.AreEqual(39, statuses.Rows.Count);

                foreach (var uid in request.Uids)
                {
                    Assert.IsNull(statuses.Rows.FirstOrDefault(x => x.Uid == uid));
                }
            }
        }
Пример #17
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);
            }
        }
        public async Task <int?> AddDispositivoUsuario(Dispositivo dispositivo)
        {
            int?_result = 0;

            using (IUnitOfWork _unitOfWork = new TransactionScopeUnitOfWorkFactory(IsolationLevel.Serializable).Create())
            {
                _dispositivoRepository.AddDispositivoUsuario(dispositivo);

                _result = _dispositivoRepository.SaveChanges();

                _unitOfWork.Commit();
            }

            return(await Task.FromResult <int>(_result.Value));
        }
Пример #19
0
        private static async Task DumpToDb(ParseResult result, string typeCode)
        {
            var unitOfWorkFactory        = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory         = new DefaultDbContextFactory();
            var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory);
            var classifierTypeService    = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository);

            var handler = new ImportClassifierListHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

            await handler.Handle(new ImportClassifierList
            {
                CompanyUid = Guid.Parse("6465dd4c-8664-4433-ba6a-14effd40ebed"),
                UserUid    = Guid.NewGuid(),
                TypeCode   = typeCode,
                Data       = result
            }, CancellationToken.None);
        }
        public async Task GetNumeratorEntityList_Should_ReturnList()
        {
            // arrange
            var cancellationToken = CancellationToken.None;
            var dbContextFactory  = new DefaultDbContextFactory();
            var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory();
            var generator         = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);

            var entityTypeResolverMock = new Mock <IEntityNameResolver>();

            entityTypeResolverMock.Setup(x => x.Resolve(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(() => "Numerator Entity Name");

            var entityTypeResolverFactory = new Mock <INamedServiceFactory <IEntityNameResolver> >();

            entityTypeResolverFactory.Setup(x => x.GetRequiredService(It.IsAny <string>()))
            .Returns(() => entityTypeResolverMock.Object);

            var repository = new DbNumeratorEntityRepository(dbContextFactory, entityTypeResolverFactory.Object);
            var handler    = new GetNumeratorEntityListHandler(repository);

            using (var _ = unitOfWorkFactory.Create())
            {
                // arrange
                var numerator = await generator.InsertNumerator(
                    new Numerator(),
                    new GenerateNumberRequest
                {
                    EntityTypeCode = "NumeratorTypeCode",
                    EntityTypeUid  = Guid.NewGuid()
                }, cancellationToken);

                // act
                // ReSharper disable once PossibleInvalidOperationException
                var command = new GetNumeratorEntityList {
                    NumeratorUid = numerator.Uid.Value
                };
                var result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsNull(result.TotalCount);
                Assert.IsTrue(result.Rows.Count > 0);
                Assert.IsTrue(result.Rows.Count(x => x.EntityTypeCode == "NumeratorTypeCode") == 1);
            }
        }
Пример #21
0
        public async Task UpdateClassifier_NormalValues_UpdateItems()
        {
            // arrange
            var cancellationToken           = new CancellationToken();
            var unitOfWorkFactory           = new TransactionScopeUnitOfWorkFactory();
            var dbContextFactory            = new DefaultDbContextFactory();
            var generator                   = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var classifierRepositoryFactory = CreateClassifierRepositoryFactory(dbContextFactory);
            var handler = new UpdateClassifierHandler(unitOfWorkFactory, classifierRepositoryFactory);

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

                var insertItem = await generator.InsertItem("001", null, cancellationToken);

                // act
                var command = new UpdateClassifier
                {
                    UserUid = generator.UserUid,
                    Item    = new Classifier
                    {
                        // ReSharper disable once PossibleInvalidOperationException
                        Uid    = insertItem.Uid.Value,
                        Type   = generator.TypeCode,
                        Code   = "001",
                        Name   = "Test Classifier",
                        Fields = new FieldData
                        {
                            { "test1", "value1" },
                            { "test2", "value2" },
                            { "test3", "value3" }
                        }
                    }
                };

                var result = await handler.Handle(command, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsTrue(result.Success);
                Assert.AreEqual(1, result.AffectedRows);
            }
        }
Пример #22
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);
            }
        }
        public async Task Handle_NormalValues_ShouldDeleteTree()
        {
            // 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 generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new DeleteClassifierTreeHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

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

                var tree2 = await generator.InsertTree("tree2", cancellationToken);

                // assert - default and second trees exists
                var trees = await generator.GetTrees(cancellationToken);

                Assert.AreEqual(2, trees.TotalCount);

                // act
                var result = await handler.Handle(new DeleteClassifierTree
                {
                    UserUid  = generator.UserUid,
                    TypeCode = generator.TypeCode,
                    // ReSharper disable once PossibleInvalidOperationException
                    Uids = new [] { tree2.Uid.Value }
                }, cancellationToken);

                // assert - link deleted
                Assert.IsTrue(result.Success);
                Assert.AreEqual(1, result.AffectedRows);

                // assert - default hierarchy exists
                trees = await generator.GetTrees(cancellationToken);

                Assert.AreEqual(1, trees.TotalCount);
                Assert.AreEqual(ClassifierTree.DefaultCode, trees.Rows[0].Code);
            }
        }
        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);
            }
        }
Пример #25
0
        public async Task Handle_ByUid_UpdateClassifierTree()
        {
            // 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 generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new UpdateClassifierTreeHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

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

                var trees = await generator.GetTrees(cancellationToken);

                // act
                var result = await handler.Handle(new UpdateClassifierTree
                {
                    UserUid  = generator.UserUid,
                    TypeCode = generator.TypeCode,
                    Item     = new ClassifierTree
                    {
                        Uid  = trees.Rows[0].Uid,
                        Code = ClassifierTree.DefaultCode,
                        Name = "Test Classifier Tree"
                    }
                }, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsTrue(result.Success);
                Assert.AreEqual(1, result.AffectedRows);

                trees = await generator.GetTrees(cancellationToken);

                Assert.AreEqual(1, trees.TotalCount);
                Assert.AreEqual("Test Classifier Tree", trees.Rows[0].Name);
            }
        }
Пример #26
0
        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);
            }
        }
Пример #27
0
        public async Task Handle_NormalValues_InsertClassifierTree()
        {
            // 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 generator = new MasterDataDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new InsertClassifierTreeHandler(unitOfWorkFactory, dbContextFactory, classifierTypeService);

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

                // act
                var result = await handler.Handle(new InsertClassifierTree
                {
                    UserUid  = generator.UserUid,
                    TypeCode = generator.TypeCode,
                    Item     = new ClassifierTree
                    {
                        Code = "001",
                        Name = "Test Classifier Tree"
                    }
                }, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.IsTrue(result.Success);
                Assert.IsNotNull(result.Uid);
                Assert.AreNotEqual(Guid.Empty, result.Uid);

                var trees = await generator.GetTrees(cancellationToken);

                Assert.AreEqual(2, trees.TotalCount);                 // one for default tree and second for inserted in test
            }
        }
Пример #28
0
        public async Task GetEntityStatusList_Should_ReturnList()
        {
            // arrange
            var cancellationToken      = CancellationToken.None;
            var dbContextFactory       = new DefaultDbContextFactory();
            var unitOfWorkFactory      = new TransactionScopeUnitOfWorkFactory();
            var entityStatusRepository = new DbEntityStatusRepository(dbContextFactory);
            var generator = new CoreDbGenerator(unitOfWorkFactory, dbContextFactory);
            var handler   = new GetEntityStatusListHandler(entityStatusRepository);

            using (var _ = unitOfWorkFactory.Create())
            {
                // arrange
                for (var i = 0; i < 42; i++)
                {
                    await generator.InsertEntityStatus(new EntityStatus
                    {
                        Code = "status_code_" + i,
                        Name = "Status Name " + i
                    }, cancellationToken);
                }

                // act
                var request = new GetEntityStatusList
                {
                    EntityTypeCode = generator.EntityTypeCode,
                    EntityUid      = generator.EntityUid
                };
                var result = await handler.Handle(request, cancellationToken);

                // assert
                Assert.IsNotNull(result);
                Assert.AreEqual(10, result.Rows.Count);
                Assert.AreEqual(42, result.TotalCount);
            }
        }
Пример #29
0
        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);
            }
        }
Пример #30
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);
            }
        }