public async Task GetEmployeesTest() { MyMaps.Initialize(); _IEmployeeRepository = new EmployeeRepository(); EmployeeLogic obj = new EmployeeLogic(_IEmployeeRepository); var respuesta = obj.GetAll(); Assert.IsTrue(respuesta.Result.Count() > 1); MyMaps.TearDown(); }
public async Task GetEmployeesByIdTest() { MyMaps.Initialize(); int expectedvalue = 1; _IEmployeeRepository = new EmployeeRepository(); EmployeeLogic obj = new EmployeeLogic(_IEmployeeRepository); var respuesta = obj.GetById(1); Assert.AreEqual(expectedvalue, respuesta.Result.Count()); MyMaps.TearDown(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>( options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")) ); services.AddMyDependencies(Configuration); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = Configuration["Auth:Url"]; options.RequireHttpsMetadata = false; options.ApiName = Configuration["Auth:ApiName"]; // Agregamos esto para especificar donde se encuentra el role options.RoleClaimType = ClaimTypes.Role; }); services.AddCors(options => { options.AddPolicy("AllowSpecificOrigin", builder => builder.AllowAnyHeader() .AllowAnyMethod() .AllowAnyOrigin() ); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Wimym.Api", Version = "v1" }); }); // Automapper config MyMaps.Initialize(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
// 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_1); services.AddTransient <IEmployeeRepository, EmployeeRepository>(); services.AddTransient <IEmployeeLogic, EmployeeLogic>(); services.AddSingleton(Configuration); services.AddSwaggerGen(options => { options.DescribeAllEnumsAsStrings(); options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info() { Title = "Hgaray MasGlobal Test", Version = "v1", Description = "Hgaray MasGlobal Test", TermsOfService = "Test" }); }); MyMaps.Initialize(); }
public void ConfigureServices(IServiceCollection services) { // services.AddHttpContextAccessor(); #region Current User //services.AddTransient<IHttpContextAccessor, HttpContextAccessor>(); services.AddHttpContextAccessor(); // services.AddTransient<ICurrentUserFactory, CurrentUserFactory>(); #endregion services.AddScoped <ICurrentUserFactory, CurrentUserFactory>(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddIdentity <ApplicationUser, IdentityRole>(cfg => { cfg.Tokens.AuthenticatorTokenProvider = TokenOptions.DefaultAuthenticatorProvider; cfg.SignIn.RequireConfirmedEmail = false; cfg.User.RequireUniqueEmail = true; cfg.Password.RequireDigit = false; cfg.Password.RequiredUniqueChars = 0; cfg.Password.RequireLowercase = false; cfg.Password.RequireNonAlphanumeric = false; cfg.Password.RequireUppercase = false; cfg.Password.RequiredLength = 6; }) .AddDefaultTokenProviders() .AddEntityFrameworkStores <DataContext>(); // services.AddDefaultIdentity<IdentityUser>().AddRoles<IdentityRole>() //.AddDefaultUI(UIFramework.Bootstrap4) // .AddEntityFrameworkStores<DataContext>(); services.AddAuthentication().AddCookie() .AddJwtBearer(cfg => { cfg.TokenValidationParameters = new TokenValidationParameters { ValidIssuer = this.Configuration["Tokens:Issuer"], ValidAudience = this.Configuration["Tokens:Audience"], IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(this.Configuration["Tokens:Key"])) }; }); services.AddDbContext <DataContext>(cfg => { cfg.UseSqlServer(this.Configuration.GetConnectionString("DefaultConnection")); }); //services.Configure<IISServerOptions>(options => //{ // options.AutomaticAuthentication = false; //}); services.AddMyDependencies(Configuration); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Wimym.Api", Version = "v1" }); }); // Automapper config MyMaps.Initialize(); //////Maintain only one instance of the string connection ////// SpaParameters.ApiUrl = Configuration["Api:Url"]; //////services.AddScoped<IAuthorizationHandler, ////// ContactIsOwnerAuthorizationHandler>(); //////services.AddSingleton<IAuthorizationHandler, ////// ContactAdministratorsAuthorizationHandler>(); //////services.AddSingleton<IAuthorizationHandler, ////// ContactManagerAuthorizationHandler>(); services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.ConfigureApplicationCookie(options => { options.LoginPath = "/Account/NotAuthorized"; options.AccessDeniedPath = "/Account/NotAuthorized"; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); ////services.AddMvc(config => ////{ //// // using Microsoft.AspNetCore.Mvc.Authorization; //// // using Microsoft.AspNetCore.Authorization; //// var policy = new AuthorizationPolicyBuilder() //// .RequireAuthenticatedUser() //// .Build(); //// config.Filters.Add(new AuthorizeFilter(policy)); ////}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }