public async Task Return_Two_WhenSfHasTwoChildren() { // Arrange SourceFormat sf = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode rootDsn = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sf.Id, rootDsn.Id) .ConfigureAwait(false); DimensionStructureNode child = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AppendDimensionStructureNodeToTreeAsync(child.Id, rootDsn.Id, sf.Id) .ConfigureAwait(false); // Act long amount = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetAmountOfDimensionStructureNodeOfSourceFormatAsync(sf) .ConfigureAwait(false); // Assert amount.Should().Be(2); }
/// <inheritdoc/> public async Task <DimensionStructureNode> GetNodeAsync( long sourceFormatId, long dimensionStructureId, CancellationToken cancellationToken = default) { using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions)) { try { Check.AreNotEqual(sourceFormatId, 0); Check.AreNotEqual(dimensionStructureId, 0); DimensionStructureNode node = await ctx.DimensionStructureNodes .AsNoTracking() .Where(w => w.SourceFormatId == sourceFormatId) .FirstOrDefaultAsync( ww => ww.DimensionStructureId == dimensionStructureId, cancellationToken) .ConfigureAwait(false); return(node); } catch (Exception e) { string msg = $"{nameof(MasterDataSourceFormatBusinessLogic)}." + $"{nameof(GetNodeAsync)} operation failed. " + $"For further info see inner exception."; throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg, e); } } }
public async Task DeleteRootDsn_WhenItDoesNotHaveChildren() { // Arrange SourceFormat sourceFormat = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode rootDsn = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sourceFormat.Id, rootDsn.Id) .ConfigureAwait(false); // Action await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .DeleteRootDimensionStructureNodeAsync(rootDsn.Id, sourceFormat.Id) .ConfigureAwait(false); // Assert SourceFormat result = await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .GetSourceFormatByIdWithRootDimensionStructureNodeAsync(sourceFormat) .ConfigureAwait(false); result.SourceFormatDimensionStructureNode.Should().BeNull(); int dsnAmount = await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .GetAmountOfDimensionStructureNodeOfSourceFormatAsync(sourceFormat) .ConfigureAwait(false); dsnAmount.Should().Be(0); }
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); }
public async Task Throw_WhenBothDsnAndSfHaveConnection_ButToSomewhereElse() { // Arrange SourceFormat sf1 = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode dsn1 = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sf1.Id, dsn1.Id) .ConfigureAwait(false); SourceFormat sf2 = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode dsn2 = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sf2.Id, dsn2.Id) .ConfigureAwait(false); // Action Func <Task> task = async() => { await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .DeleteRootDimensionStructureNodeAsync(dsn1.Id, sf2.Id) .ConfigureAwait(false); }; // Assert task.Should().ThrowExactly <MasterDataBusinessLogicSourceFormatDatabaseOperationException>(); }
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); }
public async Task Deletes_RootDimensionStructureNodeToo() { // Arrange SourceFormat sourceFormatOrig = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode dimensionStructureNode = await CreateSavedDimensionStructureNodeEntity() .ConfigureAwait(false); await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sourceFormatOrig.Id, dimensionStructureNode.Id) .ConfigureAwait(false); // Action await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .DeleteAsync(sourceFormatOrig) .ConfigureAwait(false); // Assert List <SourceFormat> sourceFormats = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetAllAsync() .ConfigureAwait(false); sourceFormats.Count.Should().Be(0); List <DimensionStructureNode> dimensionStructureNodes = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetAllDimensionStructureNodesAsync() .ConfigureAwait(false); dimensionStructureNodes.Count.Should().Be(0); }
/// <inheritdoc/> public async Task <SourceFormat> GetSourceFormatByIdWithActiveOnlyDimensionStructuresInTheTreeAsync( SourceFormat querySourceFormat) { try { Check.IsNotNull(querySourceFormat); SourceFormat result = await GetSourceFormatByIdWithRootDimensionStructureNodeAsync(querySourceFormat) .ConfigureAwait(false); if (result == null) { return(null); } using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions)) { DimensionStructureNode tree = await GetActiveDimensionStructureNodeTreeAsync( result.SourceFormatDimensionStructureNode.DimensionStructureNode, ctx) .ConfigureAwait(false); result.SourceFormatDimensionStructureNode.DimensionStructureNode = tree; } return(result); } catch (Exception e) { string msg = $"{nameof(MasterDataSourceFormatBusinessLogic)}." + $"{nameof(GetSourceFormatByIdWithActiveOnlyDimensionStructuresInTheTreeAsync)} " + $"operation failed. For further info see inner exception."; throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg, e); } }
private async Task <DimensionStructureNode> GetActiveDimensionStructureNodeTreeAsync( DimensionStructureNode dimensionStructureNode, MasterDataContext ctx) { Check.IsNotNull(dimensionStructureNode); Check.IsNotNull(ctx); DimensionStructureNode node = await ctx.DimensionStructureNodes .AsNoTracking() .Include(i => i.ChildNodes) .Include(ii => ii.DimensionStructure) .Where(p => p.DimensionStructure.IsActive == 1) .FirstAsync(w => w.Id == dimensionStructureNode.Id) .ConfigureAwait(false); if (node.ChildNodes.Any()) { foreach (DimensionStructureNode childNode in node.ChildNodes) { DimensionStructureNode n = await GetDimensionStructureNodeTreeAsync( childNode, ctx) .ConfigureAwait(false); dimensionStructureNode.ChildNodes.Add(n); } } return(dimensionStructureNode); }
/// <inheritdoc/> public async Task <DimensionStructureNode> CreateDimensionStructureNodeAsync( DimensionStructureNode node, CancellationToken cancellationToken = default) { using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions)) { try { Check.IsNotNull(node); await _masterDataValidators.DimensionStructureNodeValidator.ValidateAsync(node, o => { o.IncludeRuleSets(SourceFormatValidatorRulesets.CreateDimensionStructureNode); o.ThrowOnFailures(); }, cancellationToken) .ConfigureAwait(false); await ctx.DimensionStructureNodes.AddAsync(node, cancellationToken).ConfigureAwait(false); await ctx.SaveChangesAsync(cancellationToken).ConfigureAwait(false); return(node); } catch (Exception e) { string msg = $"{nameof(MasterDataSourceFormatBusinessLogic)}." + $"${nameof(CreateDimensionStructureNodeAsync)} failed. " + $"For further info see inner exception."; throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg); } } }
public async Task Delete_Dsn_FromLevel1() { // Arrange Dictionary <string, long> tree = await CreateThreeLevelDeepAndWideDsnTreeAsync().ConfigureAwait(false); long toBeDeleted = tree["dsn-2"]; DimensionStructureNode parent = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetDimensionStructureNodeByIdWithParentAsync(toBeDeleted) .ConfigureAwait(false); long sfId = tree["sf"]; // Act await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .DeleteDimensionStructureNodeFromTreeAsync(toBeDeleted, parent.Id, sfId) .ConfigureAwait(false); // Assert DimensionStructureNode result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetDimensionStructureNodeByIdAsync(toBeDeleted) .ConfigureAwait(false); result.Should().BeNull(); long dsn_2_1_id = tree["dsn-2-1"]; DimensionStructureNode dsn_2_1_result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetDimensionStructureNodeByIdAsync(dsn_2_1_id) .ConfigureAwait(false); dsn_2_1_result.Should().BeNull(); long dsn_2_2_id = tree["dsn-2-2"]; DimensionStructureNode dsn_2_2_result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetDimensionStructureNodeByIdAsync(dsn_2_2_id) .ConfigureAwait(false); dsn_2_2_result.Should().BeNull(); long dsn_2_3_id = tree["dsn-2-3"]; DimensionStructureNode dsn_2_3_result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetDimensionStructureNodeByIdAsync(dsn_2_3_id) .ConfigureAwait(false); dsn_2_3_result.Should().BeNull(); long dsn_2_1_1_id = tree["dsn-2-1-1"]; DimensionStructureNode dsn_2_1_1_result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .GetDimensionStructureNodeByIdAsync(dsn_2_1_1_id) .ConfigureAwait(false); dsn_2_1_1_result.Should().BeNull(); }
public async Task RootDimensionStructureNodeIsAddedToSourceFormat(Table table) { RootDimensionStructureNodeIsAddedToSourceFormatEntity instance = table .CreateInstance <RootDimensionStructureNodeIsAddedToSourceFormatEntity>(); SourceFormat sf = _scenarioContext.Get <SourceFormat>(instance.SourceFormatResultKey); Check.IsNotNull(sf); DimensionStructureNode dsn = _scenarioContext.Get <DimensionStructureNode>( instance.DimensionStructureNodeResultKey); Check.IsNotNull(dsn); AddRootDimensionStructureNodeViewModel vm = new AddRootDimensionStructureNodeViewModel() { DimensionStructureNodeId = dsn.Id, SourceFormatId = sf.Id, }; DilibHttpClientResponse <SourceFormat> result = await _masterDataHttpClient.SourceFormatHttpClient .AddRootDimensionStructureNodeAsync(vm) .ConfigureAwait(false); _scenarioContext.Add(instance.ResultKey, result); }
protected async Task AddChildToDsnAsync( DimensionStructureNode child, DimensionStructureNode parent, DomainModel.SourceFormat sf) { await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .AppendDimensionStructureNodeToTreeAsync(child.Id, parent.Id, sf.Id) .ConfigureAwait(false); }
protected async Task <DimensionStructureNode> CreateSavedDimensionStructureNodeEntity() { DimensionStructureNode node = _dimensionStructureNodeFaker.Generate(); DimensionStructureNode result = await _masterDataBusinessLogic .MasterDataDimensionStructureNodeBusinessLogic .AddAsync(node) .ConfigureAwait(false); return(result); }
/// <inheritdoc/> public async Task <DilibHttpClientResponse <DimensionStructureNode> > CreateDimensionStructureNodeAsync( DimensionStructureNode dimensionStructureNode, CancellationToken cancellationToken = default) { Check.IsNotNull(dimensionStructureNode); string url = $"{SourceFormatBase}/{MasterDataApi.SourceFormat.V1.CreateDimensionStructureNode}"; DilibHttpClientResponse <DimensionStructureNode> result = await _diLibHttpClient .PostAsync(url, dimensionStructureNode, cancellationToken) .ConfigureAwait(false); return(result); }
public async Task DimensionStructureNodeIsAddedToSourceFormatAsRootDimensionStructureNode(Table table) { DimensionStructureNodeIsAddedToSourceFormatAsRootDimensionStructureNodeEntity instance = table .CreateInstance <DimensionStructureNodeIsAddedToSourceFormatAsRootDimensionStructureNodeEntity>(); bool doesSourceFormatExist = GetKeyValueFromScenarioContext <bool>(ScenarioContextKeys.SourceFormatExist); bool doesDimensionStructureNodeExist = GetKeyValueFromScenarioContext <bool>(ScenarioContextKeys.DimensionStructureNodeIdExist); long sourceFormatIdFromContext = GetKeyValueFromScenarioContext <long>(ScenarioContextKeys.SourceFormatId); long dimensionStructureNodeIdFromContext = GetKeyValueFromScenarioContext <long>(ScenarioContextKeys.DimensionStructureNodeId); long dimensionStructureNodeId = 0; long sourceFormatId = 0; if (doesSourceFormatExist) { SourceFormat sourceFormat = await CreateSourceFormatEntity().ConfigureAwait(false); sourceFormatId = sourceFormat.Id; } else { sourceFormatId = sourceFormatIdFromContext; } if (doesDimensionStructureNodeExist) { DimensionStructureNode node = await CreateDimensionStructureNodeEntity().ConfigureAwait(false); dimensionStructureNodeId = node.Id; } else { dimensionStructureNodeId = dimensionStructureNodeIdFromContext; } AddRootDimensionStructureNodeViewModel addRootDimensionStructureNodeViewModel = new AddRootDimensionStructureNodeViewModel { SourceFormatId = sourceFormatId, DimensionStructureNodeId = dimensionStructureNodeId, }; DilibHttpClientResponse <SourceFormat> result = await _masterDataHttpClient .SourceFormatHttpClient .AddRootDimensionStructureNodeAsync(addRootDimensionStructureNodeViewModel) .ConfigureAwait(false); _scenarioContext.Add(instance.ResultKey, result); }
private async Task <DimensionStructureNode> CreateDimensionStructureNodeEntity() { DimensionStructureNode entity = _dimensionStructureNodeFaker.Generate(); DilibHttpClientResponse <DimensionStructureNode> result = await _masterDataHttpClient .SourceFormatHttpClient .CreateDimensionStructureNodeAsync(entity) .ConfigureAwait(false); if (!result.IsSuccess) { throw new Exception(); } return(result.Result); }
public async Task <ActionResult <DimensionStructureNode> > CreateDimensionStructureNodeAsync( DimensionStructureNode dimensionStructureNode) { try { DimensionStructureNode result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .CreateDimensionStructureNodeAsync(dimensionStructureNode) .ConfigureAwait(false); return(Ok(result)); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <ActionResult <DimensionStructureNode> > AddAsync( DimensionStructureNode dimensionStructureNode, CancellationToken cancellationToken = default) { try { DimensionStructureNode result = await _masterDataBusinessLogic .MasterDataDimensionStructureNodeBusinessLogic .AddAsync(dimensionStructureNode, cancellationToken) .ConfigureAwait(false); return(Ok(result)); } catch (Exception e) { return(BadRequest(e)); } }
public void ThenSourceFormatDimensionStructureNodeDimensionStructureNodeIdIs(Table table) { KeyDimensionStructureNodeKeyEntity instance = table .CreateInstance <KeyDimensionStructureNodeKeyEntity>(); SourceFormatDimensionStructureNode sourceFormatDimensionStructureNode = _scenarioContext[instance.Key] as SourceFormatDimensionStructureNode; Check.IsNotNull(sourceFormatDimensionStructureNode); DimensionStructureNode dimensionStructureNode = _scenarioContext[instance.DimensionStructureNodeKey] as DimensionStructureNode; Check.IsNotNull(dimensionStructureNode); sourceFormatDimensionStructureNode.DimensionStructureNodeId .Should().Be(dimensionStructureNode.Id); }
public async Task GivenThereIsASavedDimensionStructureNodeDomainObject(Table table) { KeyResultKeyEntity instance = table.CreateInstance <KeyResultKeyEntity>(); DimensionStructureNode node = _dimensionStructureNodeFaker.Generate(); DilibHttpClientResponse <DimensionStructureNode> result = await _masterDataHttpClient .SourceFormatHttpClient .CreateDimensionStructureNodeAsync(node) .ConfigureAwait(false); if (!result.IsSuccess) { throw new Exception(result.ExceptionMessage); } _scenarioContext.Add(instance.ResultKey, result.Result); }
public async Task Throw_WhenInputIsInvalid( long sourceFormatId, long dimensionStructureNodeId, bool doesSourceFormatExists, bool doesDimensionStructureNodeExist) { // Arrange long sourceFormatIdInTest = 0; long dimensionStructureNodeIdInTest = 0; if (doesSourceFormatExists is false) { sourceFormatIdInTest = sourceFormatId; } else { SourceFormat sourceFormat = await CreateSavedSourceFormatEntity().ConfigureAwait(false); sourceFormatIdInTest = sourceFormat.Id; } if (doesDimensionStructureNodeExist is false) { dimensionStructureNodeIdInTest = dimensionStructureNodeId; } else { DimensionStructureNode dimensionStructureNode = await CreateSavedDimensionStructureNodeEntity() .ConfigureAwait(false); dimensionStructureNodeIdInTest = dimensionStructureNode.Id; } // Action Func <Task> task = async() => { await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sourceFormatIdInTest, dimensionStructureNodeIdInTest) .ConfigureAwait(false); }; // Assert task.Should().ThrowExactly <MasterDataBusinessLogicSourceFormatDatabaseOperationException>(); }
public async Task Throw_WhenNoSuchDimensionStructureNode_Or_SourceFormat( long dimensionStructureNodeId, bool isDimensionStructureNodeExist, long sourceFormatId, bool isSourceFormatExist) { // Arrange long dimensionStructureNodeIdUsed; long sourceFormatIdUsed; if (isDimensionStructureNodeExist) { DimensionStructureNode dsn = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); dimensionStructureNodeIdUsed = dsn.Id; } else { dimensionStructureNodeIdUsed = dimensionStructureNodeId; } if (isSourceFormatExist) { SourceFormat sf = await CreateSavedSourceFormatEntity().ConfigureAwait(false); sourceFormatIdUsed = sf.Id; } else { sourceFormatIdUsed = sourceFormatId; } // Action Func <Task> task = async() => { await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .DeleteRootDimensionStructureNodeAsync(dimensionStructureNodeIdUsed, sourceFormatIdUsed) .ConfigureAwait(false); }; // Assert task.Should().ThrowExactly <MasterDataBusinessLogicSourceFormatDatabaseOperationException>(); }
public async Task CreateEntity(long Id, int IsActive) { // Arrange DimensionStructureNode node = new DimensionStructureNode { Id = Id, IsActive = IsActive, }; // Action DimensionStructureNode result = await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .CreateDimensionStructureNodeAsync(node) .ConfigureAwait(false); // Assert result.Id.Should().BeGreaterThan(0); result.IsActive.Should().Be(IsActive); }
public async Task Add_DSNToSourceFormatAsRoot() { // Arrange SourceFormat sourceFormat = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode dimensionStructureNode = await CreateSavedDimensionStructureNodeEntity() .ConfigureAwait(false); // Action await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sourceFormat.Id, dimensionStructureNode.Id) .ConfigureAwait(false); // Assert SourceFormat result = await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .GetSourceFormatByIdWithRootDimensionStructureNodeAsync(sourceFormat) .ConfigureAwait(false); result.SourceFormatDimensionStructureNode.Id.Should().Be(dimensionStructureNode.Id); }
public async Task Throw_WhenInputValue_IsInvalid(long Id, int IsActive) { // Arrange DimensionStructureNode node = new DimensionStructureNode { Id = Id, IsActive = IsActive, }; // Action Func <Task> action = async() => { await _masterDataBusinessLogic .MasterDataSourceFormatBusinessLogic .CreateDimensionStructureNodeAsync(node) .ConfigureAwait(false); }; // Assert action.Should().ThrowExactly <MasterDataBusinessLogicSourceFormatDatabaseOperationException>(); }
/// <inheritdoc/> public async Task <DimensionStructureNode> AddAsync( DimensionStructureNode dimensionStructureNode, CancellationToken cancellationToken = default) { using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions)) { try { Check.IsNotNull(dimensionStructureNode); await _masterDataValidators .DimensionStructureNodeValidator.ValidateAsync(dimensionStructureNode, o => { o.IncludeRuleSets(DimensionStructureNodeValidatorRulesets.Add); o.ThrowOnFailures(); }, cancellationToken).ConfigureAwait(false); DimensionStructureNode newNode = new DimensionStructureNode { IsActive = dimensionStructureNode.IsActive, }; await ctx.DimensionStructureNodes.AddAsync( newNode, cancellationToken) .ConfigureAwait(false); await ctx.SaveChangesAsync(cancellationToken).ConfigureAwait(false); return(newNode); } catch (Exception e) { string msg = $"{nameof(MasterDataDimensionStructureNodeBusinessLogic)}." + $"{nameof(AddAsync)} operation has failed. " + $"For further info see inner exception."; throw new MasterDataDimensionStructureNodeBusinessLogicException(msg, e); } } }
/// <inheritdoc/> public async Task <SourceFormat> GetSourceFormatByIdWithActiveDimensionStructureTreeAsync( long sourceFormatId, CancellationToken cancellationToken) { using (MasterDataContext ctx = new MasterDataContext(_dbContextOptions)) { Check.AreNotEqual(sourceFormatId, 0); try { SourceFormat result = await ctx.SourceFormats.AsNoTracking() .FirstOrDefaultAsync(w => w.Id == sourceFormatId, cancellationToken) .ConfigureAwait(false); if (result == null) { return(null); } DimensionStructureNode tree = await GetActiveDimensionStructureNodeTreeAsync( result.SourceFormatDimensionStructureNode.DimensionStructureNode, ctx) .ConfigureAwait(false); result.SourceFormatDimensionStructureNode.DimensionStructureNode = tree; return(result); } catch (Exception e) { string msg = $"{nameof(MasterDataSourceFormatBusinessLogic)}." + $"{nameof(GetSourceFormatByIdWithActiveDimensionStructureTreeAsync)} " + $"operation failed. For further information see inner exception."; throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg, e); } } }
private async Task DeleteChildNodesOfDimensionStructureNodeAsync( DimensionStructureNode tree, MasterDataContext ctx, CancellationToken cancellationToken) { try { if (tree.ChildNodes.Any()) { foreach (DimensionStructureNode treeChildNode in tree.ChildNodes) { await DeleteChildNodesOfDimensionStructureNodeAsync( treeChildNode, ctx, cancellationToken) .ConfigureAwait(false); } } DimensionStructureNode dimensionStructureNode = await ctx.DimensionStructureNodes .FirstAsync( w => w.Id == tree.Id, cancellationToken) .ConfigureAwait(false); ctx.Entry(dimensionStructureNode).State = EntityState.Deleted; await ctx.SaveChangesAsync(cancellationToken) .ConfigureAwait(false); } catch (Exception e) { string msg = $"{nameof(MasterDataSourceFormatBusinessLogic)}." + $"{nameof(DeleteChildNodesOfDimensionStructureNodeAsync)} operation has failed. " + $"For further information see inner exception."; throw new MasterDataBusinessLogicSourceFormatDatabaseOperationException(msg, e); } }
public async Task Throw_WhenSourceFormatAlreadyHaveARootDimensionStructureNode() { // Arrange SourceFormat sourceFormat = await CreateSavedSourceFormatEntity().ConfigureAwait(false); DimensionStructureNode root = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); DimensionStructureNode second = await CreateSavedDimensionStructureNodeEntity().ConfigureAwait(false); await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sourceFormat.Id, root.Id) .ConfigureAwait(false); // Action Func <Task> action = async() => { await _masterDataBusinessLogic.MasterDataSourceFormatBusinessLogic .AddRootDimensionStructureNodeAsync(sourceFormat.Id, second.Id) .ConfigureAwait(false); }; // Assert action.Should().ThrowExactly <MasterDataBusinessLogicSourceFormatDatabaseOperationException>(); }