private ControllerWithContext <SplitController> CreateController()
        {
            var services = new ServiceCollection();

            services
            .AddEntityFramework()
            .AddInMemoryDatabase()
            .AddDbContext <PayMeBackContext>(optionsBuilder => optionsBuilder.UseInMemoryDatabase());

            InjectionConfig.ConfigureCustomServices(services);

            var serviceProvider = services.BuildServiceProvider();
            var context         = CreateContext(serviceProvider);

            services.AddTransient <IGenericRepository <Split>, GenericRepository <Split> >(provider => new GenericRepository <Split>(context));

            var mapper       = serviceProvider.GetService <IMapper>();
            var splitService = serviceProvider.GetService <ISplitService>();

            var splitController = new SplitController(mapper, splitService);

            var claims = new List <Claim> {
                new Claim(ClaimTypes.NameIdentifier, "1")
            };
            var httpContext = new DefaultHttpContext();

            httpContext.User = new ClaimsPrincipal(new ClaimsIdentity(claims));
            splitController.ActionContext.HttpContext = httpContext;

            return(new ControllerWithContext <SplitController> {
                Controller = splitController, Context = context
            });
        }
Ejemplo n.º 2
0
        private ControllerWithContext <UserController> CreateController()
        {
            var services = new ServiceCollection();

            services
            .AddEntityFramework()
            .AddInMemoryDatabase()
            .AddDbContext <PayMeBackContext>(optionsBuilder => optionsBuilder.UseInMemoryDatabase());

            InjectionConfig.ConfigureCustomServices(services);

            var serviceProvider = services.BuildServiceProvider();
            var context         = CreateContext(serviceProvider);

            var dateTimeProviderMock = new Mock <IDateTimeProvider>();

            dateTimeProviderMock.Setup(d => d.Now()).Returns(new DateTime(2020, 6, 1, 12, 0, 0, DateTimeKind.Utc));
            services.AddSingleton <IDateTimeProvider, DateTimeProvider>(provider => (DateTimeProvider)dateTimeProviderMock.Object);

            services.AddTransient <IGenericRepository <AppUser>, GenericRepository <AppUser> >(provider => new GenericRepository <AppUser>(context));

            var mapper      = serviceProvider.GetService <IMapper>();
            var userService = serviceProvider.GetService <IUserService>();

            var userController = new UserController(mapper, userService);

            return(new ControllerWithContext <UserController> {
                Controller = userController, Context = context
            });
        }
        private ControllerWithContext <ContactController> CreateController()
        {
            var services = new ServiceCollection();

            services
            .AddEntityFramework()
            .AddInMemoryDatabase()
            .AddDbContext <PayMeBackContext>(optionsBuilder => optionsBuilder.UseInMemoryDatabase());

            InjectionConfig.ConfigureCustomServices(services);

            var serviceProvider = services.BuildServiceProvider();
            var context         = CreateContext(serviceProvider);

            services.AddTransient <IGenericRepository <Split>, GenericRepository <Split> >(provider => new GenericRepository <Split>(context));
            services.AddTransient <IGenericRepository <SplitContact>, GenericRepository <SplitContact> >(provider => new GenericRepository <SplitContact>(context));

            var mapper       = serviceProvider.GetService <IMapper>();
            var splitService = serviceProvider.GetService <IContactService>();

            var contactController = new ContactController(mapper, splitService);

            return(new ControllerWithContext <ContactController> {
                Controller = contactController, Context = context
            });
        }
Ejemplo n.º 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc()
            .AddJsonOptions(options => {
                options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            });

            services.AddCors();

            InjectionConfig.ConfigureCustomServices(services);

            //var connection = @"Server=(localdb)\mssqllocaldb;Database=PayMeBack_dev;Trusted_Connection=True";
            var connection = @"Server=192.168.1.4\sqlexpress;Database=PayMeBack_dev;User Id=sa;Password=Bonjour1;";

            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <PayMeBackContext>(options => options
                                             .UseSqlServer(connection)
                                             .MigrationsAssembly("PayMeBack.Backend.Repository")
                                             );
        }