Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ public abstract class Step
public string Name { get; set; }
public int StepGroupId { get; set; }
public virtual StepGroup StepGroup { get; set; }
public virtual ICollection<StepInput> StepInputs { get; set; } = new HashSet<StepInput>();
}
public class CheckingStep : Step { }
public class InstructionStep : Step { }
public abstract class AbstractStep : Step { }

public class StepInput
{
public int Id { get; set; }
public int StepId { get; set; }
public string Input { get; set; }
public virtual Step Step { get; set; }
}
public class StepGroupModel
{
public int Id { get; set; }
Expand All @@ -29,17 +36,27 @@ public abstract class StepModel
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<StepInputModel> StepInputs { get; set; } = new HashSet<StepInputModel>();
}
public class CheckingStepModel : StepModel { }
public class InstructionStepModel : StepModel { }
public abstract class AbstractStepModel : StepModel { }
public class StepInputModel
{
public int Id { get; set; }
public int StepId { get; set; }
public string Input { get; set; }
public StepModel Step { get; set; }
}

public class Context : LocalDbContext
{
public DbSet<StepGroup> StepGroups { get; set; }

public DbSet<Step> Steps { get; set; }

public DbSet<StepInput> StepInputs { get; set; }

public DbSet<CheckingStep> CheckingSteps { get; set; }

public DbSet<InstructionStep> InstructionSteps { get; set; }
Expand All @@ -51,6 +68,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasOne(d => d.StepGroup).WithMany(p => p.Steps)
.HasForeignKey(d => d.StepGroupId);
});

modelBuilder.Entity<StepInput>(entity =>
{
entity.HasOne(d => d.Step).WithMany(p => p.StepInputs)
.HasForeignKey(d => d.StepId);
});
}
}

Expand All @@ -66,6 +89,7 @@ protected override MapperConfiguration CreateConfiguration()
.IncludeBase<Step, StepModel>();
cfg.CreateMap<AbstractStep, AbstractStepModel>()
.IncludeBase<Step, StepModel>();
cfg.CreateMap<StepInput, StepInputModel>();
});
}

Expand All @@ -80,7 +104,14 @@ protected override void Seed(Context context)
{
new InstructionStep
{
Name = "InstructionStep"
Name = "InstructionStep",
StepInputs = new List<StepInput>
{
new StepInput
{
Input = "Input"
}
}
},
new CheckingStep
{
Expand All @@ -101,4 +132,12 @@ public void ProjectCollectionWithElementInheritingAbstractClass()
steps[0].ShouldBeOfType<CheckingStepModel>().Name.ShouldBe("CheckingStep");
steps[1].ShouldBeOfType<InstructionStepModel>().Name.ShouldBe("InstructionStep");
}

[Fact]
public void ProjectIncludingPolymorphicElement()
{
using var context = new Context();
var stepInput = ProjectTo<StepInputModel>(context.StepInputs).Single();
stepInput.Step.ShouldBeOfType<InstructionStepModel>().Name.ShouldBe("InstructionStep");
}
}