From 5c8cca4142a5a5014ad222d1ea6456fa5d712d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 22 Dec 2020 16:30:13 +0300 Subject: [PATCH] Initial AbpPerfTest.WithoutAbp --- .../AbpPerfTest.WithoutAbp.csproj | 8 ++++ .../Controllers/BookController.cs | 37 +++++++++++++++ .../AbpPerfTest.WithoutAbp/Dtos/BookDto.cs | 15 ++++++ .../AbpPerfTest.WithoutAbp/Entities/Book.cs | 15 ++++++ .../EntityFramework/BookDbContext.cs | 27 +++++++++++ .../EntityFramework/BookDbContextFactory.cs | 29 ++++++++++++ .../20201222132615_Added_Books.Designer.cs | 47 +++++++++++++++++++ .../Migrations/20201222132615_Added_Books.cs | 31 ++++++++++++ .../Migrations/BookDbContextModelSnapshot.cs | 45 ++++++++++++++++++ .../AbpPerfTest.WithoutAbp/Program.cs | 8 +--- .../AbpPerfTest.WithoutAbp/Startup.cs | 28 +++++++---- .../AbpPerfTest.WithoutAbp/appsettings.json | 5 +- 12 files changed, 277 insertions(+), 18 deletions(-) create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/BookDto.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Entities/Book.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContext.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContextFactory.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.Designer.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.cs create mode 100644 test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/BookDbContextModelSnapshot.cs diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/AbpPerfTest.WithoutAbp.csproj b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/AbpPerfTest.WithoutAbp.csproj index f6851843e7..edf2ed6d58 100644 --- a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/AbpPerfTest.WithoutAbp.csproj +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/AbpPerfTest.WithoutAbp.csproj @@ -4,4 +4,12 @@ net5.0 + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs new file mode 100644 index 0000000000..2cb5d69164 --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AbpPerfTest.WithoutAbp.Dtos; +using AbpPerfTest.WithoutAbp.EntityFramework; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace AbpPerfTest.WithoutAbp.Controllers +{ + [Route("api/books")] + public class BookController : Controller + { + private readonly BookDbContext _bookDbContext; + + public BookController(BookDbContext bookDbContext) + { + _bookDbContext = bookDbContext; + } + + [HttpGet] + public async Task> GetListAsync() + { + var books = await _bookDbContext.Books.ToListAsync(); + + return books + .Select(b => new BookDto + { + Id = b.Id, + Name = b.Name, + Price = b.Price, + IsAvailable = b.IsAvailable + }) + .ToList(); + } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/BookDto.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/BookDto.cs new file mode 100644 index 0000000000..46ab9599dc --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/BookDto.cs @@ -0,0 +1,15 @@ +using System; + +namespace AbpPerfTest.WithoutAbp.Dtos +{ + public class BookDto + { + public Guid Id { get; set; } + + public string Name { get; set; } + + public float Price { get; set; } + + public bool IsAvailable { get; set; } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Entities/Book.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Entities/Book.cs new file mode 100644 index 0000000000..7a52830cf3 --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Entities/Book.cs @@ -0,0 +1,15 @@ +using System; + +namespace AbpPerfTest.WithoutAbp.Entities +{ + public class Book + { + public Guid Id { get; set; } + + public string Name { get; set; } + + public float Price { get; set; } + + public bool IsAvailable { get; set; } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContext.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContext.cs new file mode 100644 index 0000000000..92c5dc1cc1 --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContext.cs @@ -0,0 +1,27 @@ +using AbpPerfTest.WithoutAbp.Entities; +using Microsoft.EntityFrameworkCore; + +namespace AbpPerfTest.WithoutAbp.EntityFramework +{ + public class BookDbContext : DbContext + { + public DbSet Books { get; set; } + + public BookDbContext(DbContextOptions builderOptions) + : base(builderOptions) + { + + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity(b => + { + b.ToTable("Books"); + b.Property(x => x.Name).HasMaxLength(128); + }); + } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContextFactory.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContextFactory.cs new file mode 100644 index 0000000000..d92948fcbc --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContextFactory.cs @@ -0,0 +1,29 @@ +using System.IO; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Microsoft.Extensions.Configuration; + +namespace AbpPerfTest.WithoutAbp.EntityFramework +{ + public class BookDbContextFactory : IDesignTimeDbContextFactory + { + public BookDbContext CreateDbContext(string[] args) + { + var configuration = BuildConfiguration(); + + var builder = new DbContextOptionsBuilder() + .UseSqlServer(configuration.GetConnectionString("Default")); + + return new BookDbContext(builder.Options); + } + + private static IConfigurationRoot BuildConfiguration() + { + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false); + + return builder.Build(); + } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.Designer.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.Designer.cs new file mode 100644 index 0000000000..0fc7fef909 --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.Designer.cs @@ -0,0 +1,47 @@ +// +using System; +using AbpPerfTest.WithoutAbp.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace AbpPerfTest.WithoutAbp.Migrations +{ + [DbContext(typeof(BookDbContext))] + [Migration("20201222132615_Added_Books")] + partial class Added_Books + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("AbpPerfTest.WithoutAbp.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("IsAvailable") + .HasColumnType("bit"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Price") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.cs new file mode 100644 index 0000000000..cb5103c93c --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.cs @@ -0,0 +1,31 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace AbpPerfTest.WithoutAbp.Migrations +{ + public partial class Added_Books : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Books", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + Name = table.Column(type: "nvarchar(128)", maxLength: 128, nullable: true), + Price = table.Column(type: "real", nullable: false), + IsAvailable = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Books", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Books"); + } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/BookDbContextModelSnapshot.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/BookDbContextModelSnapshot.cs new file mode 100644 index 0000000000..9d494bb518 --- /dev/null +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/BookDbContextModelSnapshot.cs @@ -0,0 +1,45 @@ +// +using System; +using AbpPerfTest.WithoutAbp.EntityFramework; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace AbpPerfTest.WithoutAbp.Migrations +{ + [DbContext(typeof(BookDbContext))] + partial class BookDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("AbpPerfTest.WithoutAbp.Entities.Book", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("IsAvailable") + .HasColumnType("bit"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("nvarchar(128)"); + + b.Property("Price") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.ToTable("Books"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Program.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Program.cs index 6d42a4aa5e..b657f16862 100644 --- a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Program.cs +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Program.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; namespace AbpPerfTest.WithoutAbp { @@ -20,4 +14,4 @@ namespace AbpPerfTest.WithoutAbp Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); } -} \ No newline at end of file +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Startup.cs b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Startup.cs index 971d2625b8..cf2a61df14 100644 --- a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Startup.cs +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/Startup.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; +using AbpPerfTest.WithoutAbp.EntityFramework; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -12,13 +10,23 @@ namespace AbpPerfTest.WithoutAbp { public class Startup { - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + private readonly IConfiguration _configuration; + + public Startup(IConfiguration configuration) + { + _configuration = configuration; + } + public void ConfigureServices(IServiceCollection services) { + services.AddMvc(); + + services.AddDbContext(options => + { + options.UseSqlServer(_configuration.GetConnectionString("Default")); + }); } - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) @@ -30,8 +38,8 @@ namespace AbpPerfTest.WithoutAbp app.UseEndpoints(endpoints => { - endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); + endpoints.MapControllers(); }); } } -} \ No newline at end of file +} diff --git a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/appsettings.json b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/appsettings.json index d9d9a9bff6..7f6ca466b2 100644 --- a/test/AbpPerfTest/AbpPerfTest.WithoutAbp/appsettings.json +++ b/test/AbpPerfTest/AbpPerfTest.WithoutAbp/appsettings.json @@ -6,5 +6,8 @@ "Microsoft.Hosting.Lifetime": "Information" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=AbpPerfTest_WithoutAbp;Trusted_Connection=True;MultipleActiveResultSets=true" + } }