public void GivenSourceFormatDimensionStructureNodeIsModified(Table table)
        {
            SourceFormatDimensionStructureNodeIsModifiedEntity instance = table
                                                                          .CreateInstance <SourceFormatDimensionStructureNodeIsModifiedEntity>();

            SourceFormatDimensionStructureNode node = _scenarioContext[instance.Key] as
                                                      SourceFormatDimensionStructureNode;

            Check.IsNotNull(node);

            if (instance.SourceFormatKey != null)
            {
                SourceFormat sourceFormat = _scenarioContext[instance.SourceFormatKey] as SourceFormat;
                Check.IsNotNull(sourceFormat);
                node.SourceFormatId = sourceFormat.Id;
            }

            if (instance.DimensionStructureNodeKey != null)
            {
                DimensionStructureNode dimensionStructureNode = _scenarioContext[instance.DimensionStructureNodeKey]
                                                                as DimensionStructureNode;
                Check.IsNotNull(dimensionStructureNode);
                node.DimensionStructureNodeId = dimensionStructureNode.Id;
            }

            _scenarioContext.Remove(instance.ResultKey);
            _scenarioContext.Add(instance.ResultKey, node);
        }
Esempio n. 2
0
        public void GivenAlreadySavedSourceFormatDimensionStructureNodeIsUpdated(Table table)
        {
            AlreadySavedSourceFormatDimensionStructureNodeIsUpdatedEntity instance = table
                                                                                     .CreateInstance <AlreadySavedSourceFormatDimensionStructureNodeIsUpdatedEntity>();

            SourceFormatDimensionStructureNode sourceFormatDimensionStructureNode =
                _scenarioContext[instance.Key] as SourceFormatDimensionStructureNode;

            Check.IsNotNull(sourceFormatDimensionStructureNode);

            if (instance.Id != "none")
            {
                sourceFormatDimensionStructureNode.Id = Convert.ToInt32(instance.Id);
            }

            if (instance.SourceFormatId != "none")
            {
                sourceFormatDimensionStructureNode.SourceFormatId = Convert.ToInt32(instance.SourceFormatId);
            }

            if (instance.DimensionStructureNodeId != "none")
            {
                sourceFormatDimensionStructureNode.DimensionStructureNodeId = Convert
                                                                              .ToInt32(instance.DimensionStructureNodeId);
            }

            _scenarioContext.Remove(instance.ResultKey);
            _scenarioContext.Add(instance.ResultKey, sourceFormatDimensionStructureNode);
        }
        public void GivenThereIsASourceFormatDimensionStructureNodeDomainObject(Table table)
        {
            ThereIsASourceFormatDimensionStructureNodeDomainObjectEntity instance = table
               .CreateInstance<ThereIsASourceFormatDimensionStructureNodeDomainObjectEntity>();

            SourceFormatDimensionStructureNode result = new SourceFormatDimensionStructureNode();

            if (instance.SourceFormatKey != null)
            {
                SourceFormat sourceFormat = _scenarioContext[instance.SourceFormatKey]
                    as SourceFormat;
                Check.IsNotNull(sourceFormat);
                result.SourceFormatId = sourceFormat.Id;
                result.SourceFormat = sourceFormat;
            }

            if (instance.DimensionStructureNodeKey != null)
            {
                DimensionStructureNode dimensionStructureNode = _scenarioContext[instance.DimensionStructureNodeKey]
                    as DimensionStructureNode;
                Check.IsNotNull(dimensionStructureNode);
                result.DimensionStructureNodeId = dimensionStructureNode.Id;
                result.DimensionStructureNode = dimensionStructureNode;
            }

            _scenarioContext.Add(instance.ResultKey, result);
        }
Esempio n. 4
0
        public void Have_Null_AsDefaultValue_For_SourceFormatId()
        {
            // Arrange
            SourceFormatDimensionStructureNode sut = new SourceFormatDimensionStructureNode();

            // Assert
            sut.SourceFormatId.Should().BeNull();
        }
Esempio n. 5
0
        public void Have_Zero_AsDefaultValueFor_Id()
        {
            // Arrange
            SourceFormatDimensionStructureNode sut = new SourceFormatDimensionStructureNode();

            // Assert
            sut.Id.Should().Be(0);
        }
        public void ThenSourceFormatDimensionStructureNodeIdNotEqualsTo(Table table)
        {
            KeyNotEqualsToEntityLong instance = table.CreateInstance <KeyNotEqualsToEntityLong>();

            SourceFormatDimensionStructureNode result = _scenarioContext[instance.Key]
                                                        as SourceFormatDimensionStructureNode;

            Check.IsNotNull(result);

            result.Id.Should().NotBe(instance.NotEqualsToLong);
        }
Esempio n. 7
0
        public void ThenSourceFormatDimensionStructureNodeDimensionStructureNodeIdNullableEqualsTo(Table table)
        {
            KeyResultKeyEntity instance = table.CreateInstance <KeyResultKeyEntity>();

            SourceFormatDimensionStructureNode node = _scenarioContext[instance.Key]
                                                      as SourceFormatDimensionStructureNode;

            Check.IsNotNull(node);

            node.DimensionStructureNodeId.Should().BeNull();
        }
Esempio n. 8
0
        public async Task Id_NotChange_DuringSetGet()
        {
            // Arrange
            long Id = 100;

            // Act
            SourceFormatDimensionStructureNode sut = new SourceFormatDimensionStructureNode
            {
                Id = Id,
            };

            // Assert
            sut.Id.Should().Be(Id);
        }
        public void ThenSourceFormatDimensionStructureNodeSourceFormatIdIs(Table table)
        {
            KeySourceFormatKeyEntity instance = table.CreateInstance <KeySourceFormatKeyEntity>();

            SourceFormatDimensionStructureNode sourceFormatDimensionStructureNode =
                _scenarioContext[instance.Key] as SourceFormatDimensionStructureNode;

            Check.IsNotNull(sourceFormatDimensionStructureNode);

            SourceFormat sourceFormat = _scenarioContext[instance.SourceFormatKey]
                                        as SourceFormat;

            Check.IsNotNull(sourceFormat);

            sourceFormatDimensionStructureNode.SourceFormatId.Should()
            .Be(sourceFormat.Id);
        }
        public void GivenThereIsASourceFormatDimensionStructureNodeDomainObjectForValidation(Table table)
        {
            ThereIsASourceFormatDimensionStructureNodeDomainObjectForValidationEntity instance = table
                                                                                                 .CreateInstance <ThereIsASourceFormatDimensionStructureNodeDomainObjectForValidationEntity>();

            SourceFormatDimensionStructureNode node = new SourceFormatDimensionStructureNode();

            if (instance.Id != "none")
            {
                node.Id = Convert.ToInt32(instance.Id);
            }

            if (instance.SourceFormatId != "none")
            {
                node.SourceFormatId = Convert.ToInt32(instance.SourceFormatId);
            }

            if (instance.DimensionStructureNodeId != "none")
            {
                node.DimensionStructureNodeId = Convert.ToInt32(instance.DimensionStructureNodeId);
            }

            _scenarioContext.Add(instance.ResultKey, node);
        }
        /// <inheritdoc/>
        public async Task DeleteRootDimensionStructureNodeAsync(
            long dimensionStructureNodeId,
            long sourceFormatId,
            CancellationToken cancellationToken = default)
        {
            using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions))
                using (IDbContextTransaction transaction = await ctx.Database
                                                           .BeginTransactionAsync(cancellationToken)
                                                           .ConfigureAwait(false))
                {
                    try
                    {
                        Check.AreNotEqual(dimensionStructureNodeId, 0);
                        Check.AreNotEqual(sourceFormatId, 0);

                        DimensionStructureNode rootNode = await ctx.DimensionStructureNodes
                                                          .AsNoTracking()
                                                          .Include(i => i.SourceFormatDimensionStructureNode)
                                                          .ThenInclude(ii => ii.SourceFormat)
                                                          .Include(iii => iii.ChildNodes)
                                                          .FirstOrDefaultAsync(
                            w => w.Id == dimensionStructureNodeId &&
                            w.SourceFormatDimensionStructureNode.SourceFormatId == sourceFormatId,
                            cancellationToken)
                                                          .ConfigureAwait(false);

                        if (rootNode == null)
                        {
                            string msg = $"There is no {nameof(DimensionStructureNode)} with Id: " +
                                         $"{dimensionStructureNodeId}.";
                            throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg);
                        }

                        SourceFormatDimensionStructureNode sourceFormatDimensionStructureNode = await ctx
                                                                                                .SourceFormatDimensionStructureNodes
                                                                                                .FirstOrDefaultAsync(
                            w => w.Id == rootNode.Id,
                            cancellationToken)
                                                                                                .ConfigureAwait(false);

                        ctx.Entry(sourceFormatDimensionStructureNode).State = EntityState.Deleted;
                        await ctx.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                        if (rootNode.ChildNodes.Any())
                        {
                            DimensionStructureNode rootNodeWithoutChildren = new DimensionStructureNode
                            {
                                Id = rootNode.Id,
                            };

                            DimensionStructureNode tree = await GetDimensionStructureNodeTreeAsync(
                                rootNodeWithoutChildren, ctx)
                                                          .ConfigureAwait(false);
                            await DeleteChildNodesOfDimensionStructureNodeAsync(
                                tree,
                                ctx,
                                cancellationToken)
                            .ConfigureAwait(false);
                        }

                        DimensionStructureNode refresh = await ctx.DimensionStructureNodes
                                                         .FirstOrDefaultAsync(
                            w => w.Id == dimensionStructureNodeId,
                            cancellationToken)
                                                         .ConfigureAwait(false);

                        if (refresh != null)
                        {
                            ctx.Entry(refresh).State = EntityState.Deleted;
                            await ctx.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
                        }

                        await transaction.CommitAsync(cancellationToken).ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        await transaction.RollbackAsync(cancellationToken).ConfigureAwait(false);

                        string msg = $"{nameof(MasterDataSourceFormatBusinessLogic)}." +
                                     $"{nameof(DeleteRootDimensionStructureNodeAsync)} operation has failed. " +
                                     "For further information see inner exception.";
                        throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg, e);
                    }
                }
        }
        /// <inheritdoc/>
        public async Task AddRootDimensionStructureNodeAsync(
            long sourceFormatId,
            long dimensionStructureNodeId,
            CancellationToken cancellationToken = default)
        {
            using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions))
                using (IDbContextTransaction transaction = await ctx.Database
                                                           .BeginTransactionAsync(cancellationToken)
                                                           .ConfigureAwait(false))
                {
                    try
                    {
                        Check.AreNotEqual(sourceFormatId, 0);
                        Check.AreNotEqual(dimensionStructureNodeId, 0);

                        SourceFormat sourceFormat = await ctx.SourceFormats
                                                    .Include(root => root.SourceFormatDimensionStructureNode)
                                                    .FirstOrDefaultAsync(k => k.Id == sourceFormatId, cancellationToken)
                                                    .ConfigureAwait(false);

                        DimensionStructureNode dimensionStructureNode = await ctx.DimensionStructureNodes
                                                                        .FirstOrDefaultAsync(k => k.Id == dimensionStructureNodeId, cancellationToken)
                                                                        .ConfigureAwait(false);

                        if (sourceFormat is null)
                        {
                            string msg = $"No {nameof(SourceFormat)} with id: {sourceFormatId}.";
                            throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg);
                        }

                        if (dimensionStructureNode is null)
                        {
                            string msg = $"No {nameof(DimensionStructureNode)} with id: {dimensionStructureNodeId}.";
                            throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg);
                        }

                        if (sourceFormat.SourceFormatDimensionStructureNode is not null)
                        {
                            string msg = $"{nameof(SourceFormat)}(${sourceFormat.Id}) already has " +
                                         $"root ${nameof(DimensionStructureNode)}.";
                            throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg);
                        }

                        dimensionStructureNode.SourceFormat     = sourceFormat;
                        ctx.Entry(dimensionStructureNode).State = EntityState.Modified;

                        SourceFormatDimensionStructureNode sourceFormatDimensionStructureNode =
                            new SourceFormatDimensionStructureNode
                        {
                            DimensionStructureNode = dimensionStructureNode,
                            SourceFormat           = sourceFormat,
                        };

                        await ctx.AddAsync(sourceFormatDimensionStructureNode, cancellationToken)
                        .ConfigureAwait(false);

                        await ctx.SaveChangesAsync(cancellationToken)
                        .ConfigureAwait(false);

                        await transaction.CommitAsync(cancellationToken)
                        .ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        await transaction.RollbackAsync(cancellationToken)
                        .ConfigureAwait(false);

                        string msg = $"{nameof(AddRootDimensionStructureNodeAsync)} operation failed!" +
                                     $" For further information see inner exception.";
                        throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg, e);
                    }
                }
        }
Esempio n. 13
0
        /// <inheritdoc/>
        public async Task <DimensionStructureNode> CreateRootNodeAsync(
            SourceFormat sourceFormat,
            CancellationToken cancellationToken = default)
        {
            using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions))
                using (IDbContextTransaction transaction = await ctx.Database
                                                           .BeginTransactionAsync(cancellationToken)
                                                           .ConfigureAwait(false))
                {
                    try
                    {
                        await _masterDataValidators.SourceFormatValidator.ValidateAsync(sourceFormat, o =>
                        {
                            o.IncludeRuleSets(SourceFormatValidatorRulesets.AddRootNode);
                            o.ThrowOnFailures();
                        }, cancellationToken).ConfigureAwait(false);

                        DimensionStructureNode newNode = new DimensionStructureNode();
                        await ctx.DimensionStructureNodes.AddAsync(newNode, cancellationToken).ConfigureAwait(false);

                        await ctx.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                        SourceFormat sourceFormatResult = await ctx.SourceFormats
                                                          .FirstOrDefaultAsync(p => p.Id == sourceFormat.Id, cancellationToken)
                                                          .ConfigureAwait(false);

                        if (sourceFormatResult == null)
                        {
                            string msg = $"There is no {nameof(SourceFormat)} entity " +
                                         $"with id: {sourceFormat.Id}";
                            throw new MasterDataDimensionStructureNodeBusinessLogicException(msg);
                        }

                        SourceFormatDimensionStructureNode sourceFormatDimensionStructureNode =
                            new SourceFormatDimensionStructureNode
                        {
                            DimensionStructureNode = newNode,
                            SourceFormat           = sourceFormatResult,
                        };
                        await ctx.SourceFormatDimensionStructureNodes.AddAsync(
                            sourceFormatDimensionStructureNode,
                            cancellationToken)
                        .ConfigureAwait(false);

                        await ctx.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

                        await transaction.CommitAsync(cancellationToken).ConfigureAwait(false);

                        return(newNode);
                    }
                    catch (Exception e)
                    {
                        await transaction.RollbackAsync(cancellationToken).ConfigureAwait(false);

                        string msg = $"{nameof(MasterDataDimensionStructureNodeBusinessLogic)}." +
                                     $"{nameof(CreateRootNodeAsync)} operation failed. " +
                                     $"For further information see inner exception!";
                        throw new MasterDataDimensionStructureNodeBusinessLogicException(msg, e);
                    }
                }
        }