public void MappingTest() { string connectionString = DbTest.CreateEmptyDatabase(); DbMigrations.Run(connectionString); Order o; using (OrderContext ctx = new OrderContext(connectionString)) { IOrderRepository orderRepository = new OrderRepository(ctx, new FakeBus()); o = new OrderFactory(new TestNumberGenerator(), new TestBus()).Create("12", "client123"); o.AddProduct(TestSeeding.ProductId); orderRepository.Save(o); } using (OrderContext ctx = new OrderContext(connectionString)) { IOrderRepository orderRepository = new OrderRepository(ctx, new FakeBus()); Order o2 = orderRepository.Get(o.Id); Assert.True(o2.SameAs(o)); } }
public void ConcurrencyTest() { string connectionString = DbTest.CreateEmptyDatabase(); DbMigrations.Run(connectionString); Order o; OrderContext ctx = new OrderContext(connectionString); OrderContext ctx2 = new OrderContext(connectionString); IOrderRepository orderRepository = new OrderRepository(ctx, new FakeBus()); IOrderRepository orderRepository2 = new OrderRepository(ctx2, new FakeBus()); o = new OrderFactory(new TestNumberGenerator(), new TestBus()).Create("12", "client123"); o.AddProduct(TestSeeding.ProductId); orderRepository.Save(o); Order concurrencyOrder1 = orderRepository.Get(o.Id); Order concurrencyOrder2 = orderRepository2.Get(o.Id); concurrencyOrder1.AddProduct(TestSeeding.Product2Id); concurrencyOrder2.AddProduct(TestSeeding.Product3Id); orderRepository.Save(concurrencyOrder1); Assert.Throws <DbUpdateConcurrencyException>(() => orderRepository2.Save(concurrencyOrder2)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddSingleton<IConfiguration>(); var migrationAssembly = typeof(Startup).Assembly.GetName().Name; var webOrigin = Configuration["ApplicationSettings:WebClientOrigin"]; services.AddCors(options => { options.AddPolicy("defaultCorsPolicy", policy => { policy.WithOrigins(webOrigin) .AllowAnyHeader() .AllowAnyMethod(); }); }); services.AddControllers() .AddMvcOptions(options => { options.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()); }); var connection = Configuration.GetConnectionString("BorrowPgConnection"); services.AddDbContext <BorrowContext>(options => options.UseNpgsql(connection, sqlOptions => sqlOptions.MigrationsAssembly(migrationAssembly) ) ); services.AddHttpClients(Configuration); //Configure Application User services.AddIdentity <AppUser, IdentityRole>(config => { //prevents instant sign in upon immediate registration config.SignIn.RequireConfirmedEmail = true; }) .AddEntityFrameworkStores <BorrowContext>() .AddDefaultTokenProviders(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); services.AddAutoMapper(assemblies); services.AddScoped <ICategoryService, CategoryService>(); services.AddScoped <ICategoryRepository, CategoryRepository>(); services.AddScoped <IPaymentPlan, PaymentPlanRepository>(); services.AddScoped <IPaymentPlanService, PaymentPlanService>(); services.AddScoped <IProductRepository, ProductRepository>(); services.AddScoped <IProductService, ProductService>(); services.AddScoped <IBrandService, BrandService>(); services.AddScoped <IBrandRepository, BrandRepository>(); DbMigrations.EnsureSeedData(connection); }
public void Setup() { string connectionString = DbTest.CreateEmptyDatabase(); DbMigrations.Run(connectionString); _smtpClient = new SmtpTestClient(); Bootstrap.Run(new string[0], builder => { builder.RegisterInstance(_smtpClient).AsImplementedInterfaces(); }, connectionString); _clientId = "aaa111"; }