public AutoMapperProfileTests() { var autoMapperProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(x => x.AddProfile(autoMapperProfile)); _mapper = new Mapper(configuration); }
public async void Register_Ok() { var profile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(profile)); IMapper mapper = new Mapper(configuration); var mockRepo = new Mock <IUserRepository>(); mockRepo.Setup(p => p.GetByEmailAsync("*****@*****.**")).Returns(Task.FromResult <User>(null)); var mockOpt = new Mock <IOptions <AppSettings> >(); mockOpt.Setup(opt => opt.Value).Returns(new AppSettings() { Secret = "fedaf7d8863b48e197b9287d492b708e" }); UserService userService = new UserService(mockRepo.Object); UsersController controller = new UsersController(userService, mapper, mockOpt.Object); var userModel = new UserModel() { Email = "*****@*****.**", Password = "******", IsAdmin = false, Role = "user" }; var response = await controller.Register(userModel); Assert.True(response is OkObjectResult); var okRequest = response as OkObjectResult; Assert.IsType <UserModel>(okRequest.Value); }
/// <summary> /// Constructor /// </summary> public AutoMapperImpl(MappingCollection typeMap) : base(typeMap) { var profile = new AutoMapperProfile(typeMap); var mapperConfiguration = new AutoMapper.MapperConfiguration(cfg => cfg.AddProfile(profile)); this.Mapper = mapperConfiguration.CreateMapper(); }
public async Task <IActionResult> PutAsync([FromBody] PessoaFisicaDto item) { PessoaFisica pessoaFisica = AutoMapperProfile.Map <PessoaFisicaDto, PessoaFisica>(item); await pessoaFisicaService.Put <PessoaFisicaValidator>(pessoaFisica); return(new OkObjectResult(item)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Database string conn = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=PartyCoinDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(conn)); //Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "PartyCoinWebAPI", Version = "v1" }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please enter JWT with Bearer into field", Name = "Authorization", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", Enumerable.Empty <string>() }, }); }); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); // Add application services. services.AddTransient <IEmailSender, EmailSender>(); services.AddAutoMapper(); AutoMapperProfile autoMapper = new AutoMapperProfile(); services.AddMvc(); }
public static Mapper CreateMapperProfile() { var myProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); return(new Mapper(configuration)); }
public IActionResult Post([FromBody] PessoaFisicaDto item) { var pessoaFisica = AutoMapperProfile.Map <PessoaFisicaDto, PessoaFisica>(item); var retorno = pessoaFisicaService.Post <PessoaFisicaValidator>(pessoaFisica); return(new OkObjectResult(retorno.Id)); }
public static IMapper RetornarMapper() { var profile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(profile)); return(configuration.CreateMapper()); }
public void TestMethod1() { var mockEmployeeBusiness = new Mock <IEmployeeBusiness>(); var mockRepo = new Mock <IGenericRepository <Employee> >(); AutoMapperProfile.Run(); var mockMapper = new Mock <IMapper>(); IQueryable <Employee> employees = new Employee[] { new Employee() { FirstName = "Alejandro", Id = 1, ContractType = new ContractType { Id = 1 }, Salary = 200 } }.AsQueryable(); mockRepo.Setup(repo => repo.GetAll()).Returns(employees); IPaymentFactory paymentFac = new PaymentFactory(); IEmployeeBusiness _employeeBusiness = new EmployeeBusiness(mockRepo.Object, paymentFac); var model = _employeeBusiness.Get(1); //Salary = 200 //MonthlySalary (MonthtlySalary * 12) // 200 * 12 = 2400 Assert.IsTrue(model.AnnualSalary.Equals(2400)); }
public void MapperConfigurationsShouldBeValid() { var myProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); configuration.AssertConfigurationIsValid(); }
public IMapper TestMapper; // Mapper to use for the test fixture /// <summary> /// Configure the test fixture /// </summary> public AutoMapperTestsFixture() { // Initialise the mapper with the correct namespace AutoMapperProfile.Initialise(); // Create the test mapper TestMapper = new Mapper(Mapper.Configuration); }
public static void CreateMap(AutoMapperProfile profile) { profile.CreateMap <Message, MessagePM>() .ForMember(pm => pm.SenderFullName, opt => opt.Ignore()) .ForMember(pm => pm.ReceiverFullName, opt => opt.Ignore()) .ForMember(pm => pm.CreateDateString, opt => opt.Ignore()); profile.CreateMap <MessagePM, Message>(); }
public AirportSearchQueryHandlerTest(QueryTestFixture fixture) { _context = fixture.Context; var myProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); _mapper = new Mapper(configuration); }
public static void Initialize() { if (!testsInitialized) { AutoMapperProfile.RegisterMappings(typeof(IService).Assembly); testsInitialized = true; } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ContainerConfig.RegisterContainer(GlobalConfiguration.Configuration); AutoMapperProfile.Run(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config"))); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapperProfile.Run(); }
internal static void SetupIoC(this IServiceCollection serviceCollection, AppSettings appSettings, IConfiguration configuration) { InternalDependenciesProfile.Bootstrap(serviceCollection); CommonProfile.Register(serviceCollection, appSettings, configuration); StorageProfile.Register(serviceCollection, appSettings); LoggingProfile.RegisterApiLogger(serviceCollection, "Api"); MediatRProfile.Register(serviceCollection, typeof(Startup).Assembly); AutoMapperProfile.Register(serviceCollection, typeof(Startup).Assembly); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapperProfile.Run(); DependencyResolver.SetResolver(new NinjectResolver()); }
public static void CreateMap(AutoMapperProfile profile) { profile.CreateMap <Comment, CommentInfoPM>() .ForMember(pm => pm.SenderFullName, opt => opt.Ignore()) .ForMember(pm => pm.CreateDateString, opt => opt.Ignore()) .ForMember(pm => pm.ContentTitle, opt => opt.MapFrom(model => model.Content.Title)); profile.CreateMap <CommentInfoPM, Comment>(); profile.CreateMap <CommentRegistrationPM, Comment>(); }
static DtoMapperCfgs() { var prf1 = new AutoMapperProfile(); MapperConfiguration mapcfg1 = new MapperConfiguration(mapcfg => { mapcfg.AddProfile(prf1); }); Utils.InitialMapper(mapcfg1.CreateMapper()); }
private void AddAutoMapper(IUnityContainer container) { var config = new MapperConfiguration(cfg => { var profile = new AutoMapperProfile(container); cfg.AddProfile(profile); }); var mapper = config.CreateMapper(); container.RegisterInstance(typeof(IMapper), mapper); }
public void SetUp() { var profile = new AutoMapperProfile(); var config = new MapperConfiguration(cfg => { cfg.AddProfile(profile); }); _mapper = config.CreateMapper(); _userService = new MockUserService(); _controller = new UsersController(_userService, _mapper); }
public static void CreateMap(AutoMapperProfile profile) { profile.CreateMap <BlogGeneralSettingsPM, Blog>(); profile.CreateMap <Blog, BlogGeneralSettingsPM>(); profile.CreateMap <Blog, ShortBlogInfoPM>(); profile.CreateMap <Blog, BlogInfoPM>() .ForMember(pm => pm.CreatorFullName, opt => opt.Ignore()); profile.CreateMap <Blog, BlogInfoForGenerateLinkPM>(); }
public void SetUp() { _eventRepository = new Mock <IEventRepository>(); var myProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); _mapper = new Mapper(configuration); _eventService = new EventService(_eventRepository.Object, _mapper); }
public KeywordServiceTests() { _dbContextMock = new Mock <SearchAggregatorContext>(); _keywordRepositoryMock = new Mock <IKeywordRepository>(); _resourceRepositoryMock = new Mock <IResourceRepository>(); Profile myProfile = new AutoMapperProfile(); var mapper = new Mapper(new MapperConfiguration(cfg => cfg.AddProfile(myProfile))); _service = new KeywordService(_keywordRepositoryMock.Object, _resourceRepositoryMock.Object, _dbContextMock.Object, mapper); }
private static ServiceProvider BuildContainer(IServiceCollection serviceCollection, bool isIntegrationTests) { var(config, appSettings) = isIntegrationTests ? BuildAppSettings() : BuildFakeAppSettings(); RegisterTestDependencies(serviceCollection, appSettings); StorageProfile.Register(serviceCollection, appSettings); CommonProfile.Register(serviceCollection, appSettings, config); MediatRProfile.Register(serviceCollection); AutoMapperProfile.Register(serviceCollection); return(serviceCollection.BuildServiceProvider()); }
public void Setup() { _repository = new Mock <IStarWarsRepository>(); _logger = new Logger <CharactersController>(new LoggerFactory()); var myProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); _mapper = new Mapper(configuration); _controller = new CharactersController(_repository.Object, _mapper, _logger); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc(); services.AddAutoMapper(); AutoMapperProfile.config(); var builder = new Autofac.ContainerBuilder(); builder.Populate(services); builder.RegisterModule(new AutoFacResolver(Configuration.GetConnectionString("DefaultConnection"))); var container = builder.Build(); return(container.Resolve <IServiceProvider>()); }
public void Setup() { AutoMapperProfile myProfile = new AutoMapperProfile(); MapperConfiguration configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); mapper = new Mapper(configuration); var options = new DbContextOptionsBuilder <DataContext>() .UseInMemoryDatabase(databaseName: "BooksDatabase") .Options; dbContext = new DataContext(options); }
private AutoMock GetMock() { var myProfile = new AutoMapperProfile(); var configuration = new MapperConfiguration(cfg => cfg.AddProfile(myProfile)); IMapper mapper = new Mapper(configuration); var mock = AutoMock.GetLoose(); mock.Provide(mapper); return(mock); }