Skip to content

Commit

Permalink
Fixed issue where fk insert instruction was added even though it had …
Browse files Browse the repository at this point in the history
…previously been specified
  • Loading branch information
carl-berg committed Dec 8, 2020
1 parent d7f8487 commit fb384f1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
22 changes: 21 additions & 1 deletion DataDude.Tests/Inserts/AutoInsertFKTableTestscs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task Chain()
}

[Fact]
public async Task Chain_Sparsely_Specified()
public async Task Chain_Sparsely_Specified_Scenario_1()
{
var schema = new TestSchema();
var a = schema.AddTable("A");
Expand All @@ -47,5 +47,25 @@ public async Task Chain_Sparsely_Specified()
.Select(x => x.TableName)
.ShouldBe(new[] { "dbo.A", "B", "dbo.C", "D" });
}

[Fact]
public async Task Chain_Sparsely_Specified_Scenario_2()
{
var schema = new TestSchema();
var a = schema.AddTable("A");
var b = schema.AddTable("B").AddFk(a);
var c = schema.AddTable("C").AddFk(b);
var d = schema.AddTable("D").AddFk(c);

var context = new DataDudeContext() { Schema = schema };

context.Instructions.Add(new InsertInstruction("A"));
context.Instructions.Add(new InsertInstruction("D"));
await new AddMissingInsertInstructionsPreProcessor().PreProcess(context);
context.Instructions
.OfType<InsertInstruction>()
.Select(x => x.TableName)
.ShouldBe(new[] { "A", "dbo.B", "dbo.C", "D" });
}
}
}
2 changes: 1 addition & 1 deletion DataDude/DataDude.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Version>0.4.0-beta.1</Version>
<Version>0.4.0-beta.2</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public Task PreProcess(DataDudeContext context)
.Where(t => !toInsert.Values.Any(x => x.Contains(t)))
.ToList();

if (dependencies.Any())
{
toInsert.Add(instruction, new InsertInformation(table, dependencies));
}
toInsert.Add(instruction, new InsertInformation(table, dependencies));
}
}

Expand Down

0 comments on commit fb384f1

Please sign in to comment.