public ReviewTest() { var mapperConfig = new MapperConfiguration(cfg => cfg.AddMaps(ProfileRegistration.GetProfiles())); _mapper = mapperConfig.CreateMapper(); _reviewGenerator = new ReviewGenerator(new GameGenerator()); _fakeRepository = new Mock <IReviewRepository>(); _fakeUnitOfWork = new Mock <IUnitOfWork>(); _fakeUnitOfWork.Setup(m => m.ReviewRepository).Returns(_fakeRepository.Object); _controller = new ReviewController(_fakeUnitOfWork.Object, _mapper); }
public GameTest() { var mapperConfig = new MapperConfiguration(cfg => cfg.AddMaps(ProfileRegistration.GetProfiles())); _mapper = mapperConfig.CreateMapper(); _gameGenerator = new GameGenerator(); _mockRepository = new Mock <IGameRepository>(); _mockUnitOfWork = new Mock <IUnitOfWork>(); _mockUnitOfWork.Setup(m => m.GameRepository).Returns(_mockRepository.Object); _controller = new GameController(_mockUnitOfWork.Object, _mapper); }
// 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.AddHealthChecks(); // TODO: Permitir que a implementação seja escolhida por Settings services.AddGenerators(); services.AddMemoryPersistence(); services.AddAutoMapper(ProfileRegistration.GetProfiles()); services.AddMvc(); GitHubSettings = _configuration.GetSection(nameof(GitHubSettings)).Get <GitHubSettings>(); // TODO: Criar uma extension para facilitar a vida if (GitHubSettings == null) { throw new ArgumentNullException(nameof(GitHubSettings), "GitHub OAuth settings were not found. Did you forget to edit your appSettings.json?"); } services .AddAuthentication(opt => { opt.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; opt.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; opt.DefaultChallengeScheme = "GitHub"; }) .AddCookie() .AddGitHub("GitHub", opt => { opt.ClientId = GitHubSettings.ClientId; opt.ClientSecret = GitHubSettings.ClientSecret; opt.CallbackPath = new PathString(GitHubSettings.CallbackPath); opt.SaveTokens = true; opt.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); opt.ClaimActions.MapJsonKey(ClaimTypes.Name, "name"); opt.ClaimActions.MapJsonKey("urn:github:login", "login"); opt.ClaimActions.MapJsonKey("urn:github:url", "html_url"); opt.ClaimActions.MapJsonKey("urn:github:avatar", "avatar_url"); opt.Events = new OAuthEvents { OnCreatingTicket = async context => { var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken); var response = await context.Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, context.HttpContext.RequestAborted); response.EnsureSuccessStatusCode(); var user = JObject.Parse(await response.Content.ReadAsStringAsync()); context.RunClaimActions(user); } }; }); // Armazenando as configurações do GitHub para uso Futuro services.Configure <GitHubSettings>(_configuration.GetSection(nameof(GitHubSettings))); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "NetCore Playground API", Description = "API para testes com .NET Core 2.2", Contact = new Contact { Name = "Rodolpho Alves", Url = @"https://github.com/rodolphocastro", Email = "*****@*****.**" } // TODO: Algum dia colocar um e-mail válido :shrug: }); c.AddSecurityDefinition("GitHub", new OAuth2Scheme { Type = "oauth2", Flow = "accessCode", AuthorizationUrl = "https://github.com/login/oauth/authorize", TokenUrl = "https://github.com/login/oauth/access_token" }); c.OperationFilter <SecurityRequirementsOperationFilter>(); }); }
public ReviewViewModelsTest() { var mapperConfig = new MapperConfiguration(cfg => cfg.AddMaps(ProfileRegistration.GetProfiles())); _mapper = mapperConfig.CreateMapper(); }