Browse Source

Initial AbpPerfTest.WithoutAbp

pull/6762/head
Halil İbrahim Kalkan 6 years ago
parent
commit
5c8cca4142
  1. 8
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/AbpPerfTest.WithoutAbp.csproj
  2. 37
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Controllers/BookController.cs
  3. 15
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Dtos/BookDto.cs
  4. 15
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Entities/Book.cs
  5. 27
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContext.cs
  6. 29
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/EntityFramework/BookDbContextFactory.cs
  7. 47
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.Designer.cs
  8. 31
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.cs
  9. 45
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/BookDbContextModelSnapshot.cs
  10. 8
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Program.cs
  11. 28
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/Startup.cs
  12. 5
      test/AbpPerfTest/AbpPerfTest.WithoutAbp/appsettings.json

8
test/AbpPerfTest/AbpPerfTest.WithoutAbp/AbpPerfTest.WithoutAbp.csproj

@ -4,4 +4,12 @@
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.1" />
</ItemGroup>
</Project> </Project>

37
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<List<BookDto>> 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();
}
}
}

15
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; }
}
}

15
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; }
}
}

27
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<Book> Books { get; set; }
public BookDbContext(DbContextOptions<BookDbContext> builderOptions)
: base(builderOptions)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Book>(b =>
{
b.ToTable("Books");
b.Property(x => x.Name).HasMaxLength(128);
});
}
}
}

29
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<BookDbContext>
{
public BookDbContext CreateDbContext(string[] args)
{
var configuration = BuildConfiguration();
var builder = new DbContextOptionsBuilder<BookDbContext>()
.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();
}
}
}

47
test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/20201222132615_Added_Books.Designer.cs

@ -0,0 +1,47 @@
// <auto-generated />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsAvailable")
.HasColumnType("bit");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.Property<float>("Price")
.HasColumnType("real");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

31
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<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true),
Price = table.Column<float>(type: "real", nullable: false),
IsAvailable = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Books");
}
}
}

45
test/AbpPerfTest/AbpPerfTest.WithoutAbp/Migrations/BookDbContextModelSnapshot.cs

@ -0,0 +1,45 @@
// <auto-generated />
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<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsAvailable")
.HasColumnType("bit");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("nvarchar(128)");
b.Property<float>("Price")
.HasColumnType("real");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

8
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.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace AbpPerfTest.WithoutAbp namespace AbpPerfTest.WithoutAbp
{ {
@ -20,4 +14,4 @@ namespace AbpPerfTest.WithoutAbp
Host.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
} }
} }

28
test/AbpPerfTest/AbpPerfTest.WithoutAbp/Startup.cs

@ -1,10 +1,8 @@
using System; using AbpPerfTest.WithoutAbp.EntityFramework;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -12,13 +10,23 @@ namespace AbpPerfTest.WithoutAbp
{ {
public class Startup public class Startup
{ {
// This method gets called by the runtime. Use this method to add services to the container. private readonly IConfiguration _configuration;
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public Startup(IConfiguration configuration)
{
_configuration = configuration;
}
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc();
services.AddDbContext<BookDbContext>(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) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
if (env.IsDevelopment()) if (env.IsDevelopment())
@ -30,8 +38,8 @@ namespace AbpPerfTest.WithoutAbp
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); endpoints.MapControllers();
}); });
} }
} }
} }

5
test/AbpPerfTest/AbpPerfTest.WithoutAbp/appsettings.json

@ -6,5 +6,8 @@
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"ConnectionStrings": {
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=AbpPerfTest_WithoutAbp;Trusted_Connection=True;MultipleActiveResultSets=true"
}
} }

Loading…
Cancel
Save