Ejemplo n.º 1
0
        public void Put()
        {
            int Id = 0;

            //Arrange
            using (var ctx = new JournalDbContext(DbOptions))
            {
                var controller = new ArticleController(new ArticleService(ctx), MapperConfig.Configure());

                //Act
                var result         = controller.Get();
                var okObjectResult = result as OkObjectResult;
                var model          = okObjectResult.Value as IEnumerable <ArticleModel>;

                Id = model.First().Id;

                controller.Put(model.First().Id, new ArticleModel
                {
                    Id    = model.First().Id,
                    Title = "Sudoku"
                });
            }

            //Assert
            using (var ctx = new JournalDbContext(DbOptions))
            {
                Assert.Equal(2, ctx.Articles.Count());
                Assert.Equal("Sudoku", ctx.Articles.Where(a => a.Id == Id).Single().Title);
            }
        }
        public void SetUp()
        {
            _contextMock = new Mock <IDbContext>();

            _compiler = new TestCompiler();
            _runner   = new TestRunner();
            var scores = new Collection <Score> {
            };

            scores.Add(new Score {
                Assignment = new Assignment {
                    Id = 1
                }
            });
            _participant = new Participant {
                Id = 1, Email = "", Scores = scores, UserSetting = null
            };
            Progress progress = new Progress {
                Assignment = new Assignment {
                    Id = 1, MaxSolveTime = 1000, RunCodeInput = "test", RunCodeOuput = "test"
                }, Id = 1, StartTime = DateTime.Now, Participant = _participant
            };

            _participant.Progress = progress;
            _controller           = new ScoresController(_contextMock.Object, _compiler, _runner, _participant);
            MapperConfig.Configure();
        }
Ejemplo n.º 3
0
        public void Put()
        {
            //Arrange
            using (var ctx = new JournalDbContext(DbOptions))
            {
                var controller = new IssueController(new IssueService(ctx), MapperConfig.Configure());

                //Act
                var result         = controller.Get();
                var okObjectResult = result as OkObjectResult;
                var model          = okObjectResult.Value as IEnumerable <IssueModel>;

                controller.Put(model.Single().Id, new IssueModel
                {
                    Id                = 6,
                    AllTime           = 474,
                    Volume            = 45,
                    Number            = 3,
                    Name              = "Téli szám",
                    CopyNumber        = 800,
                    ExpectedPageCount = 36
                });
            }

            //Assert
            using (var ctx = new JournalDbContext(DbOptions))
            {
                Assert.Equal(1, ctx.Issues.Count());
                Assert.Equal("Téli szám", ctx.Issues.Include(i => i.IssueDetails).Single().IssueDetails.Name);
            }
        }
Ejemplo n.º 4
0
        public void GetByIssueId()
        {
            using (var ctx = new JournalDbContext(DbOptions))
            {
                //Arrange
                var issueController = new IssueController(new IssueService(ctx), MapperConfig.Configure());
                var controller      = new ArticleController(new ArticleService(ctx), MapperConfig.Configure());

                //Act
                var issueResult         = issueController.Get();
                var issueOkObjectResult = issueResult as OkObjectResult;
                var issueModel          = issueOkObjectResult.Value as IEnumerable <IssueModel>;

                var result = controller.GetByIssue(issueModel.Single().AllTime);

                //Assert
                var okObjectResult = result as OkObjectResult;
                Assert.NotNull(okObjectResult);

                var model = okObjectResult.Value as IEnumerable <ArticleModel>;
                Assert.NotNull(model);

                Assert.Equal(2, model.Count());
            }
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAutoMapper();
            MapperConfig.Configure();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), o =>
                                                                              o.EnableRetryOnFailure()));

            services.AddScoped <IPostService, PostService>();
            services.AddScoped <ITagService, TagService>();
            services.AddScoped <IPostTagService, PostTagService>();
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IFileUploadService, FileUploadService>();
            services.AddScoped(typeof(IBaseRepository <>), typeof(BaseRepository <>));

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath = "/auth/login";
            });
        }
Ejemplo n.º 6
0
        // 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
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <MyBookContext>(options =>
            {
                options
                .UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
                .UseLoggerFactory(new LoggerFactory().AddConsole());
            });

            services.AddSingleton(MapperConfig.Configure());
            services.AddTransient <IBookService, BookService>();

            services.AddMvc(o => o.MaxModelValidationErrors = 50)
            .AddJsonOptions(json => json.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);

            services.AddSwaggerGen(o =>
            {
                o.SwaggerDoc("v1", new Info
                {
                    Title   = "MyBooks API",
                    Version = "v1",
                    Contact = new Contact
                    {
                        Email = "*****@*****.**",
                        Name  = "Daniel Toth"
                    }
                });
                o.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyBooks.Api.xml"));
                o.DescribeAllEnumsAsStrings();
            });
        }
Ejemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <JournalDbContext>(o =>
                                                     o.UseSqlServer(Configuration.GetConnectionString(nameof(JournalDbContext)))
                                                     .UseLoggerFactory(new LoggerFactory().AddDebug())
                                                     );
            services.AddIdentity <ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores <JournalDbContext>()
            .AddDefaultTokenProviders();
            services.AddTransient <JournalDataSeeder>();
            services.AddTransient <JournalSeedData>();

            services.AddSingleton <IMapper>(MapperConfig.Configure());
            services.AddScoped <IEmailSender, EmailSender>();

            services.AddScoped <IIssueService, IssueService>();
            services.AddScoped <IArticleService, ArticleService>();
            services.AddScoped <ITodoService, TodoService>();
            services.AddScoped <INoteService, NoteService>();

            services.AddMvc();

            services.AddApiVersioning(o => o.AssumeDefaultVersionWhenUnspecified = true);

            services.Configure <AuthMessageSenderOptions>(Configuration);
        }
Ejemplo n.º 8
0
        public void Add()
        {
            //Arrange
            using (var ctx = new JournalDbContext(DbOptions))
            {
                //Arrange
                var issueController = new IssueController(new IssueService(ctx), MapperConfig.Configure());
                var controller      = new ArticleController(new ArticleService(ctx), MapperConfig.Configure());

                //Act
                var issueResult         = issueController.Get();
                var issueOkObjectResult = issueResult as OkObjectResult;
                var issueModel          = issueOkObjectResult.Value as IEnumerable <IssueModel>;

                //Act
                controller.Post(new ArticleModel()
                {
                    IssueId = issueModel.Single().Id,
                    Title   = "Receptek"
                });
            }

            //Assert
            using (var ctx = new JournalDbContext(DbOptions))
            {
                var iss = ctx.Articles.ToList();
                Assert.Equal(3, ctx.Articles.Count());
            }
        }
Ejemplo n.º 9
0
        public static void Initialize()
        {
            var cfg = new MapperConfigurationExpression();

            MapperConfig.Configure(cfg);
            Mapper.Initialize(cfg);
        }
        /// <summary>
        /// Добавляет сервисы BLL слоя
        /// </summary>
        /// <param name="services">сервисы</param>
        /// <returns>коллекция сервисов</returns>
        public static IServiceCollection AddLogicServicesCollection(this IServiceCollection services)
        {
            MapperConfig.Configure();
            services.AddScoped <IMessageService, MessageOperationService>();
            services.AddScoped <IUserOperationService, UserOperationService>();

            return(services);
        }
        static void Main(string[] args)
        {
            Serialize();
            MapperConfig.Configure();
            Map();

            Console.ReadKey();
        }
 public void Init()
 {
     _contextMock = new Mock <IDbContext>();
     _WebSecurity = new Mock <IWebSecurity>();
     _logmod      = new LogonModel();
     _controller  = new AssignmentController(_contextMock.Object);
     MapperConfig.Configure();
 }
Ejemplo n.º 13
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     MapperConfig.Configure();
 }
Ejemplo n.º 14
0
 protected void Application_Start()
 {
     AutofacConfig.ConfigureContainer();
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     MapperConfig.Configure();
 }
Ejemplo n.º 15
0
 static LotServiceTest()
 {
     try
     {
         Mapper.Initialize(cfg =>
                           MapperConfig.Configure(cfg)
                           );
     }
     catch { }
 }
Ejemplo n.º 16
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            //Database.SetInitializer<LMSContext>(null);
            MapperConfig.Configure();
            Startup.Start();
        }
Ejemplo n.º 17
0
 public static void Bootstrap()
 {
     RouteConfigurator.RegisterRoutes(RouteTable.Routes);
     ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(IoC.Container));
     WindsorConfig.Configure();
     AwesomeConfig.Configure();
     MapperConfig.Configure();
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     Globals.PicturesPath = HttpContext.Current.Server.MapPath("~/pictures");
     new Worker().Start();
 }
Ejemplo n.º 18
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            var config = GlobalConfiguration.Configuration;

            config.Formatters.JsonFormatter.SerializerSettings.Formatting =
                Formatting.Indented;

            MapperConfig.Configure();
        }
Ejemplo n.º 19
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     AutofacWebApiConfig.DependencyBuilder();
     MapperConfig.Configure();
     log4net.Config.XmlConfigurator.Configure();
 }
Ejemplo n.º 20
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //WebApiConfig.Register(GlobalConfiguration.Configuration);
            MapperConfig.Configure();

            GlobalConfiguration.Configuration.EnsureInitialized();
        }
Ejemplo n.º 21
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            MapperConfig.Configure();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
            DIConfig.RegisterTypes();
            DatabaseConfig.InitializeDatabase();
        }
Ejemplo n.º 22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <ILogService, LogService>();
            services.AddTransient <IRoomService, RoomService>();
            services.AddTransient <IDeviceService, DeviceService>();
            services.AddTransient <ICommunicationUnitService, CommunicationUnitService>();
            services.AddSingleton <IMapper>(MapperConfig.Configure());

            services.AddMvc();
            services.AddSignalR();
            // services.AddDbContext<HeatingContext>(opt => opt.UseSqlServer(@"Server = (localdb)\mssqllocaldb; Database=HeatingController;Trusted_Connection=True;"));
            services.AddDbContextPool <HeatingContext>(                                                                   // replace "YourDbContext" with the class name of your DbContext
                //options => options.UseMySql("Server=192.168.43.143;Database=HeatingController;User=heatingcontroluser;Password=1werwerwer;", // replace with your Connection String
                options => options.UseMySql("Server=localhost;Database=HeatingController;User=root;Password=1werwerwer;", // replace with your Connection String
                                            mySqlOptions =>
            {
                mySqlOptions.ServerVersion(new Version(8, 0, 15), ServerType.MySql);         // replace with your Server Version and Type
            }
                                            ));
            services.AddDbContextPool <ApplicationDbContext>(
                // options => options.UseMySql("Server=192.168.43.143;Database=Identity;User=heatingcontroluser;Password=1werwerwer;", // replace with your Connection String
                options => options.UseMySql("Server=localhost;Database=Identity;User=root;Password=1werwerwer;", // replace with your Connection String
                                            mySqlOptions =>
            {
                mySqlOptions.ServerVersion(new Version(8, 0, 15), ServerType.MySql);
            }
                                            ));
            services.AddIdentity <ApplicationUser, IdentityRole>(options =>
            {
                options.Password.RequireDigit           = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 0;
                options.Password.RequireLowercase       = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequireNonAlphanumeric = false;
            })
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.ConfigureApplicationCookie(options => options.LoginPath = "/Login/");
            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.KnownProxies.Add(IPAddress.Parse("192.168.43.143"));
            });

            services.AddSignalR(o =>
            {
                o.EnableDetailedErrors = true;
            });
        }
Ejemplo n.º 23
0
        protected void Application_Start()
        {
            //var builder = new ContainerBuilder();
            //builder.RegisterType<AdoUserRepository>().As<IRepository<User>>();
            //builder.RegisterControllers(Assembly.GetExecutingAssembly());
            //var container = builder.Build();
            //DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            MapperConfig.Configure();
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Ejemplo n.º 24
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <ICourseRepository, CourseRepository>();
            services.AddTransient <IEnrollmentRepository, EnrollmentRepository>();
            services.AddTransient <IExerciseRepository, ExerciseRepository>();
            services.AddTransient <ILanguageRepository, LanguageRepository>();
            services.AddTransient <ITestRepository, TestRepository>();
            services.AddTransient <IUserRepository, UserRepository>();

            services.AddTransient <ICourseManager, CourseManager>();
            services.AddTransient <IEnrollmentManager, EnrollmentManager>();
            services.AddTransient <IExerciseManager, ExerciseManager>();
            services.AddTransient <ILanguageManager, LanguageManager>();
            services.AddTransient <ITestManager, TestManager>();
            services.AddTransient <IUserManager, UserManager>();

            services.AddSingleton(MapperConfig.Configure());

            services.AddDbContext <LynnDb>(options =>
                                           options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity <ApplicationUser, ApplicationRole>()
            .AddEntityFrameworkStores <LynnDb>()
            .AddDefaultTokenProviders();

            services.AddMvc();

            services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddInMemoryPersistedGrants()
            .AddInMemoryIdentityResources(Config.GetIdentityResources())
            .AddInMemoryApiResources(Config.GetApiResources())
            .AddInMemoryClients(Config.GetClients())
            .AddAspNetIdentity <ApplicationUser>()
            .AddProfileService <ProfileService>();

            services.AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority            = "http://localhost:57770";
                options.RequireHttpsMetadata = false;
                options.ApiName = "lynnapi";
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("GuruOnly", policy => policy.RequireClaim("Level", "Guru"));
            });
        }
Ejemplo n.º 25
0
        public static void Bootstrap()
        {
            RouteConfigurator.RegisterRoutes(RouteTable.Routes);
            ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(IoC.Container));
            WindsorConfig.Configure();
            AwesomeConfig.Configure();
            MapperConfig.Configure();
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            FilterProviders.Providers.Add(new AntiForgeryTokenFilter());
            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;

            Globals.PicturesPath = HttpContext.Current.Server.MapPath("~/pictures");
            new Worker().Start();
        }
Ejemplo n.º 26
0
        protected void Application_Start()
        {
            //System.Data.Entity.Database.SetInitializer(new DMS.Domain.SampleData());

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            FluentValidationModelValidatorProvider.Configure();
            ValidatorOptions.ResourceProviderType = typeof(ValidationResources);
            MapperConfig.Configure(AutoMapper.Mapper.Configuration);
            Database.SetInitializer <DMSDbContext>(new DevDbInitializer());
        }
        protected void Application_Start()
        {
            GlobalConfiguration.Configuration.MessageHandlers.Add(new MessageLoggingHandler());

            AppContext.InitializeContainer(typeof(AppBusiness).Assembly, typeof(AppRepository).Assembly);

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            MapperConfig.Configure();

            AppBusiness.Start();
        }
Ejemplo n.º 28
0
        public void SetUp()
        {
            _contextMock = new Mock <IDbContext>();
            _participant = new Participant {
                Id = 1, Email = "", Scores = null, UserSetting = null
            };
            Progress progress = new Progress {
                Assignment = new Assignment {
                    Id = 1, MaxSolveTime = 1000
                }, Id = 1, StartTime = DateTime.Now, Participant = _participant
            };

            _participant.Progress = progress;
            _controller           = new ProgressController(_contextMock.Object, _participant);
            MapperConfig.Configure();
        }
Ejemplo n.º 29
0
        public void SetUp()
        {
            _contextMock = new Mock <IDbContext>();
            var scores = new Collection <Score> {
                new Score {
                    Assignment = new Assignment {
                        Id = 1
                    }
                }
            };

            _controller = new AssignmentsController(_contextMock.Object, new Participant {
                Id = 1, Scores = scores
            });
            MapperConfig.Configure();
        }
Ejemplo n.º 30
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("AllowSpecificOrigin",
                                  builder =>
                {
                    builder.WithOrigins("http://*****:*****@"Server=(localdb)\mssqllocaldb;Database=QuizAPI;Trusted_Connection=True;"));

            services.AddIdentity <QuizUser, IdentityRole>(options =>
            {
                options.Cookies.ApplicationCookie.LoginPath = "/Account/Login";
            })
            .AddEntityFrameworkStores <QuizDbContext>();

            services.AddScoped <QuizDbContext>();
            services.AddScoped <QuestionManager>();
            services.AddTransient <IQuizService, QuizService>();

            services.AddMvc();

            services.AddDistributedMemoryCache();

            services.AddSession(options =>
            {
                options.IdleTimeout    = TimeSpan.FromSeconds(10000);
                options.CookieHttpOnly = true;
            });

            services.AddSingleton <ITempDataProvider, CookieTempDataProvider>();

            services.AddSwaggerGen(o =>
            {
                o.SwaggerDoc("v1", new Info {
                    Title = "Quiz API", Version = "v1"
                });
            });
        }