Exemplo n.º 1
0
        public ReportTemplateReportTemplateTag Convert(string source, ReportTemplateReportTemplateTag destination, ResolutionContext autoMapperContext)
        {
            var rt = context.ReportTemplateTags
                     .SingleOrDefault(rt1 => rt1.Name == source);

            if (rt == null)
            {
                rt = new ReportTemplateTag {
                    Name = source
                };
                context.ReportTemplateTags.Add(rt);
            }

            ReportTemplateReportTemplateTag rtrtt = null;

            if (autoMapperContext.Items.TryGetValue("Id", out object value))
            {
                var reportId = System.Convert.ToInt32(value);
                rtrtt = context.ReportTemplateReportTemplateTags
                        .SingleOrDefault(rtrtt1 => rtrtt1.ReportTemplateTagId == rt.Id && rtrtt1.ReportTemplateId == reportId);
            }

            if (rtrtt == null)
            {
                rtrtt = new ReportTemplateReportTemplateTag
                {
                    ReportTemplateTag = rt
                };
                context.ReportTemplateReportTemplateTags.Add(rtrtt);
            }

            return(rtrtt);
        }
Exemplo n.º 2
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity <ReportTemplateReportTemplateTag>()
            .HasKey(rtti => new { rtti.ReportTemplateId, rtti.ReportTemplateTagId });

            builder.Entity <ReportTemplateReportTemplateTag>()
            .HasOne(rtti => rtti.ReportTemplate)
            .WithMany(rtti => rtti.Tags)
            .HasForeignKey(rtti => rtti.ReportTemplateId);

            builder.Entity <ReportTemplateReportTemplateTag>()
            .HasOne(rtti => rtti.ReportTemplateTag)
            .WithMany(rtt => rtt.Reports)
            .HasForeignKey(rtti => rtti.ReportTemplateTagId);

            var tags = new ReportTemplateTag[]
            {
                new ReportTemplateTag {
                    Id = 1, Name = "Scenario"
                },
                new ReportTemplateTag {
                    Id = 2, Name = "Count"
                },
                new ReportTemplateTag {
                    Id = 3, Name = "Status"
                },
                new ReportTemplateTag {
                    Id = 4, Name = "Unused"
                }
            };

            builder.Entity <ReportTemplateTag>().HasData(tags);

            var reports = new ReportTemplate[] {
                new ReportTemplate {
                    Id               = 1,
                    Name             = "Test Execution Result By Test Scenario",
                    Description      = "The test execution result by test scenario",
                    Tags             = null,
                    CreationDate     = new DateTime(2018, 5, 15),
                    LastModifiedDate = new DateTime(2018, 5, 15),
                    ThumbnailImage   = "/Sample-data/TestExecutionResultByTestScenario/thumbnail.png",
                    FullSizeImage    = "/Sample-data/TestExecutionResultByTestScenario/image.png",
                    PdfFile          = "/Sample-data/TestExecutionResultByTestScenario/TestExecutionResultByTestScenario.pdf",
                    ZipFile          = "/Sample-data/TestExecutionResultByTestScenario/TestExecutionResultByTestScenario.zip",
                },
                new ReportTemplate
                {
                    Id               = 2,
                    Name             = "Total Count Of Defects On Each Day Sorted By Status",
                    Description      = "The total count of defects on each day sorted by status",
                    Tags             = null,
                    CreationDate     = new DateTime(2018, 5, 15),
                    LastModifiedDate = new DateTime(2018, 5, 15),
                    ThumbnailImage   = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/thumbnail.png",
                    FullSizeImage    = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/image.png",
                    PdfFile          = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/TotalCountOfDefectsOnEachDaySortedByStatus.pdf",
                    ZipFile          = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/TotalCountOfDefectsOnEachDaySortedByStatus.zip",
                }
            };

            builder.Entity <ReportTemplate>().HasData(reports);

            builder.Entity <ReportTemplateReportTemplateTag>().HasData(new ReportTemplateReportTemplateTag[]
            {
                new ReportTemplateReportTemplateTag
                {
                    ReportTemplateId    = reports[0].Id,
                    ReportTemplateTagId = tags[0].Id
                },
                new ReportTemplateReportTemplateTag
                {
                    ReportTemplateId    = reports[0].Id,
                    ReportTemplateTagId = tags[2].Id
                },
                new ReportTemplateReportTemplateTag
                {
                    ReportTemplateId    = reports[1].Id,
                    ReportTemplateTagId = tags[1].Id
                }
            });

            var tablesToIgnore = new string[] { "AspNet", "OpenId" };

            foreach (var item in builder.Model.GetEntityTypes())
            {
                if (!tablesToIgnore.Any(t => item.Relational().TableName.StartsWith(t)))
                {
                    item.Relational().TableName =
                        $"API_{ item.Relational().TableName }";
                }
            }
        }
Exemplo n.º 3
0
        internal static void PopulateTestData(ApplicationDbContext applicationDbContext)
        {
            var tags = new ReportTemplateTag[]
            {
                new ReportTemplateTag {
                    Id = 1001, Name = "Scenario"
                },
                new ReportTemplateTag {
                    Id = 1002, Name = "Count"
                },
                new ReportTemplateTag {
                    Id = 1003, Name = "Status"
                },
                new ReportTemplateTag {
                    Id = 1004, Name = "Unused"
                }
            };

            if (!applicationDbContext.ReportTemplateTags.Any())
            {
                applicationDbContext.ReportTemplateTags.AddRange(tags);
            }


            var reports = new ReportTemplate[] {
                new ReportTemplate {
                    Id               = 1001,
                    Name             = "Test Execution Result By Test Scenario",
                    Description      = "The test execution result by test scenario",
                    Tags             = null,
                    CreationDate     = new DateTime(2018, 5, 15),
                    LastModifiedDate = new DateTime(2018, 5, 15),
                    ThumbnailImage   = "/Sample-data/TestExecutionResultByTestScenario/thumbnail.png",
                    FullSizeImage    = "/Sample-data/TestExecutionResultByTestScenario/image.png",
                    PdfFile          = "/Sample-data/TestExecutionResultByTestScenario/TestExecutionResultByTestScenario.pdf",
                    ZipFile          = "/Sample-data/TestExecutionResultByTestScenario/TestExecutionResultByTestScenario.zip",
                },
                new ReportTemplate
                {
                    Id               = 1002,
                    Name             = "Total Count Of Defects On Each Day Sorted By Status",
                    Description      = "The total count of defects on each day sorted by status",
                    Tags             = null,
                    CreationDate     = new DateTime(2018, 5, 15),
                    LastModifiedDate = new DateTime(2018, 5, 15),
                    ThumbnailImage   = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/thumbnail.png",
                    FullSizeImage    = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/image.png",
                    PdfFile          = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/TotalCountOfDefectsOnEachDaySortedByStatus.pdf",
                    ZipFile          = "/Sample-data/TotalCountOfDefectsOnEachDaySortedByStatus/TotalCountOfDefectsOnEachDaySortedByStatus.zip",
                }
            };

            if (!applicationDbContext.ReportTemplates.Any())
            {
                applicationDbContext.ReportTemplates.AddRange(reports);
            }

            if (!applicationDbContext.ReportTemplateReportTemplateTags.Any())
            {
                applicationDbContext.ReportTemplateReportTemplateTags.AddRange(new ReportTemplateReportTemplateTag[]
                {
                    new ReportTemplateReportTemplateTag
                    {
                        ReportTemplateId    = reports[0].Id,
                        ReportTemplateTagId = tags[0].Id
                    },
                    new ReportTemplateReportTemplateTag
                    {
                        ReportTemplateId    = reports[0].Id,
                        ReportTemplateTagId = tags[2].Id
                    },
                    new ReportTemplateReportTemplateTag
                    {
                        ReportTemplateId    = reports[1].Id,
                        ReportTemplateTagId = tags[1].Id
                    }
                });
            }

            applicationDbContext.SaveChanges();
        }