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
            });
        }
        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
            });
        }
Exemple #3
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
            });
        }
Exemple #4
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     InjectionConfig.Configure();
 }
Exemple #5
0
        public void Configuration(IAppBuilder app)
        {
            //app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            var container = InjectionConfig.Configure();

            MappingConfig.Register();
        }
        public void TestInit()
        {
            kernel = InjectionConfig.CreateKernel();
            var dbContext = kernel.Get <MsSqlDbContext>();

            dbContext.Users.Add(dbUser);
            dbContext.SaveChanges();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var builder         = new ContainerBuilder();
            var injectionConfig = new InjectionConfig(builder);
            var container       = builder.Build();
            var gameEngine      = container.Resolve <IEngine>();

            gameEngine.Start();
        }
        public void TestInit()
        {
            kernel = InjectionConfig.CreateKernel();
            MsSqlDbContext dbContext = kernel.Get <MsSqlDbContext>();


            dbContext.Categories.Add(dbCategory);
            dbContext.SaveChanges();
        }
Exemple #9
0
        public void TestInit()
        {
            kernel = InjectionConfig.CreateKernel();
            MsSqlDbContext dbContext = kernel.Get <MsSqlDbContext>();


            dbContext.Products.Add(dbProduct);
            dbContext.SaveChanges();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            InjectionConfig.Configure(services);
            GlobalExceptionHandlerMiddlewareExtensions.AddGlobalExceptionHandlerMiddleware(services);

            services.AddDbContext <DatabaseContext>(options =>
                                                    options.UseSqlServer(Configuration.GetConnectionString("DatabaseContext")));
        }
Exemple #11
0
        public void Setup()
        {
            Configuration           = Mock.Of <IConfiguration>();
            CancellationTokenSource = new CancellationTokenSource();
            Clients      = new Dictionary <string, ChatClient>();
            LastMessages = new Dictionary <string, List <string> >();
            InjectionConfig.ConfigureServices(Configuration);
            ChatApplication = InjectionConfig.Get <ChatApplication>();

            Task.Run(async() =>
            {
                await ChatApplication.StartAsync(CancellationTokenSource.Token);
            });
        }
Exemple #12
0
        static async Task Main(string[] args)
        {
            IConfiguration configuration = CreateConfiguration(args);

            InjectionConfig.ConfigureServices(configuration);

            InjectionConfig.Get <ICommunicator <string> >().OnClientConnected    += Communicator_OnClientConnected;
            InjectionConfig.Get <ICommunicator <string> >().OnClientDisconnected += Communicator_OnClientDisconnected;
            InjectionConfig.Get <ICommunicator <string> >().OnClientSendCommand  += Communicator_OnClientSendCommand;

            Console.WriteLine($"Starting Chat Server...");

            await InjectionConfig.Get <ChatApplication>().StartAsync();
        }
Exemple #13
0
        public void EfRepository_ShouldUpdateComputer_IfValid()
        {
            // Arrange
            kernel = InjectionConfig.CreateKernel();
            var dbContext = kernel.Get <MsSqlDbContext>();

            var efRepository   = kernel.Get <IEfRepository <Computer> >();
            var computersCount = dbContext.Set <Computer>().Count();


            // Act
            efRepository.Update(secondDbComputer);
            dbContext.SaveChanges();

            // Assert
            Assert.IsInstanceOf <Computer>(secondDbComputer);
        }
        public void ComputersService_ShouldAddComputer_IfValid()
        {
            // Arrange
            kernel = InjectionConfig.CreateKernel();
            var dbContext = kernel.Get <MsSqlDbContext>();

            var computersService           = kernel.Get <IComputersService>();
            var computersCountBeforeAdding = computersService.GetAll().ToList().Count();

            // Act
            dbContext.Computers.Add(secondDbComputer);
            dbContext.SaveChanges();

            var computersCountAfterAdding = computersService.GetAll().ToList().Count();


            // Assert
            Assert.AreEqual(computersCountAfterAdding, computersCountBeforeAdding + 1);
        }
Exemple #15
0
        public void LaptopsService_ShouldAddLaptop_IfValid()
        {
            // Arrange
            kernel = InjectionConfig.CreateKernel();
            var dbContext = kernel.Get <MsSqlDbContext>();

            var laptopsService           = kernel.Get <ILaptopsService>();
            var laptopsCountBeforeAdding = laptopsService.GetAll().ToList().Count();

            // Act
            dbContext.Laptops.Add(secondDbLaptop);
            dbContext.SaveChanges();

            var laptopsCountAfterAdding = laptopsService.GetAll().ToList().Count();


            // Assert
            Assert.AreEqual(laptopsCountAfterAdding, laptopsCountBeforeAdding + 1);
        }
        public void DisplaysService_ShouldAddDisplay_IfValid()
        {
            // Arrange
            kernel = InjectionConfig.CreateKernel();
            var dbContext = kernel.Get <MsSqlDbContext>();

            var displaysService           = kernel.Get <IDisplaysService>();
            var displaysCountBeforeAdding = displaysService.GetAll().ToList().Count();

            // Act
            dbContext.Displays.Add(secondbDisplay);
            dbContext.SaveChanges();

            var displaysCountAfterAdding = displaysService.GetAll().ToList().Count();


            // Assert
            Assert.AreEqual(displaysCountAfterAdding, displaysCountBeforeAdding + 1);
        }
Exemple #17
0
        public void EfRepository_ShouldDeleteComputer_IfValid()
        {
            // Arrange
            kernel = InjectionConfig.CreateKernel();
            var dbContext = kernel.Get <MsSqlDbContext>();

            var efRepository   = kernel.Get <IEfRepository <Computer> >();
            var computersCount = dbContext.Set <Computer>().Count();


            // Act
            efRepository.Delete(secondDbComputer);
            dbContext.SaveChanges();

            var computersCountAfterDeleting = dbContext.Set <Computer>().Count();


            // Assert
            Assert.AreEqual(computersCount, computersCountAfterDeleting);
        }
Exemple #18
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")
                                             );
        }
        public void ThrowDbEntityValidationException_WhenInvalidDataIsSended_WhenSaveChangesIsCalled()
        {
            // Arrange
            var computer = new Computer()
            {
                RAM = 100
            };

            try
            {
                // Act
                kernel = InjectionConfig.CreateKernel();
                var dbContext = kernel.Get <MsSqlDbContext>();

                dbContext.Computers.Add(computer);
                dbContext.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Assert
                Assert.IsInstanceOf <DbEntityValidationException>(ex);
            }
        }
Exemple #20
0
        public PluginHTTPInjectUC(PluginParameters pPluginParams)
        {
            InitializeComponent();

            #region DATAGRID HEADER

            DataGridViewTextBoxColumn cTypeCol = new DataGridViewTextBoxColumn();
            cTypeCol.DataPropertyName = "Type";
            cTypeCol.Name             = "Type";
            cTypeCol.HeaderText       = "Type";
            cTypeCol.ReadOnly         = true;
            cTypeCol.Width            = 70;
            DGV_Inject.Columns.Add(cTypeCol);

            DataGridViewTextBoxColumn cReqHostCol = new DataGridViewTextBoxColumn();
            cReqHostCol.DataPropertyName = "RequestedHost";
            cReqHostCol.Name             = "RequestedHost";
            cReqHostCol.HeaderText       = "Requested host";
            cReqHostCol.ReadOnly         = true;
            cReqHostCol.Width            = 250;
            DGV_Inject.Columns.Add(cReqHostCol);

            DataGridViewTextBoxColumn cReqURLCol = new DataGridViewTextBoxColumn();
            cReqURLCol.DataPropertyName = "RequestedURL";
            cReqURLCol.Name             = "RequestedURL";
            cReqURLCol.HeaderText       = "Requested URL";
            cReqURLCol.ReadOnly         = true;
            cReqURLCol.Width            = 250;
            DGV_Inject.Columns.Add(cReqURLCol);


            DataGridViewTextBoxColumn cInjHostNameCol = new DataGridViewTextBoxColumn();
            cInjHostNameCol.DataPropertyName = "InjectedHost";
            cInjHostNameCol.Name             = "InjectedHost";
            cInjHostNameCol.HeaderText       = "Injected host";
            cInjHostNameCol.ReadOnly         = true;
            cInjHostNameCol.AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
            DGV_Inject.Columns.Add(cInjHostNameCol);

            DataGridViewTextBoxColumn cInjURLNameCol = new DataGridViewTextBoxColumn();
            cInjURLNameCol.DataPropertyName = "InjectedURL";
            cInjURLNameCol.Name             = "InjectedURL";
            cInjURLNameCol.HeaderText       = "Injected URL/file";
            cInjURLNameCol.ReadOnly         = true;
            cInjURLNameCol.Width            = 250;
            DGV_Inject.Columns.Add(cInjURLNameCol);


            DataGridViewTextBoxColumn cInjURLFullPathCol = new DataGridViewTextBoxColumn();
            cInjURLFullPathCol.DataPropertyName = "InjectedFileFullPath";
            cInjURLFullPathCol.Name             = "InjectedFileFullPath";
            cInjURLFullPathCol.HeaderText       = String.Empty;
            cInjURLFullPathCol.ReadOnly         = true;
            //      cInjURLNameCol.Width = 250;
            cInjURLFullPathCol.Visible = false;
            DGV_Inject.Columns.Add(cInjURLFullPathCol);

            cInjectedURLs         = new BindingList <InjectedURLRecord>();
            DGV_Inject.DataSource = cInjectedURLs;

            #endregion

            RB_Redirect.Checked = true;
            RB_Redirect_CheckedChanged(null, null);

            /*
             * Plugin configuration
             */
            PluginParameters = pPluginParams;
            String lBaseDir    = String.Format(@"{0}\", (PluginParameters != null) ? PluginParameters.PluginDirectoryFullPath : Directory.GetCurrentDirectory());
            String lSessionDir = (PluginParameters != null) ? PluginParameters.SessionDirectoryFullPath : String.Format("{0}sessions", lBaseDir);

            Config = new PluginProperties()
            {
                BaseDir           = lBaseDir,
                SessionDir        = lSessionDir,
                PluginName        = "HTTP inject",
                PluginDescription = "Injecting data packets in an established HTTP data connection.",
                PluginVersion     = "0.5",
                Ports             = "TCP:80;",
                IsActive          = true
            };


            /*
             * Proxy server configuration
             */
            cConfigParams = new InjectionConfig
            {
                isDebuggingOn      = (PluginParameters != null) ? PluginParameters.HostApplication.IsDebuggingOn() : false,
                BasisDirectory     = Config.BaseDir,
                onWebServerExit    = onMicroWebExited,
                InjectionRulesPath = (PluginParameters != null) ? PluginParameters.HostApplication.GetAPEInjectionRulesFile() : String.Empty
            };

            cTask = TaskFacade.getInstance(cConfigParams, this);
            DomainFacade.getInstance(cConfigParams, this).addObserver(this);
        }