// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //Setup para configuração do Swagger SwaggerSetup.AddSwaggerSetup(services); //Setup para configuração do EF EntityFrameworkSetup.AddEntityFrameworkSetup(services, Configuration); //Setup para o JWT JwtBearerSetup.AddJwtBearerSetup(services, Configuration); //Setup para MongoDB MongoDbSetup.AddMongoDbSetup(services, Configuration); //Injecao de dependencia DependenxyInjection.Register(services); //Setup para MediatR MediatRSetup.AddMediatRSetup(services); //Setup para AutoMapper AutoMapperSetup.AddAutoMapperSetup(services); //Setup para o CORS CorsSetup.AddCorsSetup(services); }
public void GetAll_ValidatingObject() { List <Log> logs = new List <Log>(); logs.Add(new Log { Id = 2, Ip = "50.42.35.10", RecordedTime = DateTime.Now.AddDays(-1), UserAgent = "bla bla bla", DateCreated = DateTime.Now }); var logRepository = new Mock <ILogRepository>(); logRepository.Setup(x => x.GetAll()).Returns(logs); var autoMapperProfile = new AutoMapperSetup(); var mapperConfiguration = new MapperConfiguration(x => x.AddProfile(autoMapperProfile)); IMapper mapper = new Mapper(mapperConfiguration); _logService = new LogService(logRepository.Object, mapper); var result = _logService.Get(); Assert.True(result.Count > 0); }
public void Pessoa_GetByIdExiste() { // Arrange Pessoa pessoa = new Pessoa { Id = 1, Nome = "Luciano Brito", Prontuario = 5234646, DateCreaded = DateTime.Now, IsActive = true }; var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase("DefaultContext").Options; var contexto = new ApplicationContext(options); contexto.Pessoas.Add(pessoa); contexto.SaveChanges(); var _autoMapperProfile = new AutoMapperSetup(); var _configuration = new MapperConfiguration(x => x.AddProfile(_autoMapperProfile)); IMapper _mapper = new Mapper(_configuration); var repo = new PessoaRepository(contexto); var handler = new PessoaService(repo, _mapper); // Act PessoaViewModel result = handler.GetById(1); // Assert Assert.Equal("Luciano Brito", result.Nome); }
public void Delete_QuandousuarioNaoExisteRetornaNotFound() { // Arrage var usuario = new User { Id = 1, Name = "Luciano de Brito", Email = "*****@*****.**", DateCreaded = DateTime.Now, IsActive = true }; var options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase("DefaultContext").Options; var contexto = new ApplicationContext(options); contexto.Users.Add(usuario); contexto.SaveChanges(); var repo = new UserRepository(contexto); // Simulando IMapper var _autoMapperProfile = new AutoMapperSetup(); var _configuration = new MapperConfiguration(x => x.AddProfile(_autoMapperProfile)); IMapper _mapper = new Mapper(_configuration); // Usuário com Id = 2 string userId = "2"; var handler = new UserService(repo, _mapper); // Act var ex = Assert.Throws <Exception>(() => handler.Delete(userId)); // Assert Assert.Equal("User not found", ex.Message); }
public ActionResult _CustomerAccountPaymentsGridBind(int id) { ViewBag.CustomerId = id; var pymnts = _paymentService.GetPaymentsForCustomer(id).OrderByDescending(o => o.PaymentDate); return(View(new GridModel(AutoMapperSetup.MapList <Payment, PaymentVM>(pymnts).ToList()))); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { DatabaseSetup.AddDatabaseSetup(services, Configuration); IdentitySetup.AddIdentitySetup(services, Configuration); AuthenticationJwtSetup.AddAuthenticationJwtSetup(services, Configuration); AutoMapperSetup.AddAutoMapperSetup(services); DependencyInjectionSetup.AddDependencyInjectionSetup(services); SwaggerSetup.AddSwaggerSetup(services); // Determinar que a api vai chamar uma determinada controller services.AddMvc(options => { // configuração que obrigar que seja informado uma autenticação // garante que todas as requests sejam autenticadas var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) // Configuração para não retorna referencia cicular no json .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.AddCors(); }
public ActionResult _StockItemGridBind(int id) { var si = _stockInvSvc.GetInvoice(id).Items; var vm = AutoMapperSetup.MapList <StockInvoiceItem, StockInvoiceItemVM>(si); return(View(new GridModel(vm))); }
private static void CreateAgencyPhoneConfig() { AutoMapperSetup.CreateMapToEditableDto <AgencyPhone, AgencyPhoneDto> () .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.Phone.PhoneNumber)) .ForMember(dest => dest.PhoneExtensionNumber, opt => opt.MapFrom(src => src.Phone.PhoneExtensionNumber)) .ForMember(dest => dest.AgencyPhoneType, opt => opt.MapFrom(src => src.AgencyPhoneType)); }
public ActionResult _MakePayment(int id) { var vm = new MakePaymentVM(); var cust = _customerService.GetCustomer(id); if (!DoesCustomerHaveAccounts(id)) { vm.IsError = true; vm.ErrorMessage = "Payments can only be collected on Customers with existing Accounts"; } else { var rolledTransactions = _paymentService.GetRolledTransactions(id).Where(s => s.Amount != 0).OrderBy(s => s.BillCycle.Date); vm = new MakePaymentVM { CustomerId = id, PreferredPaymentSourceId = cust.PreferredPaymentSourceId, Balance = _transactionsService.GetBalanceForCustomer(id), RolledTransactions = AutoMapperSetup.MapList <PaymentService.RolledTransaction, RolledTransactionVM>( rolledTransactions).ToList(), CreditedAccountId = cust.CustomerAccounts.Min(c => c.CustomerAccountId), CustomerAccounts = cust.CustomerAccounts }; } return(PartialView(vm)); }
private static void SetupBillingOffice() { AutoMapperSetup.CreateMapToAbstractDto <BillingOffice, BillingOfficeAddressesDto> (); AutoMapperSetup.CreateMapToEditableDto <BillingOfficeAddress, BillingOfficeAddressDto> () .ForMember(dest => dest.FirstStreetAddress, opt => opt.MapFrom(src => src.Address.FirstStreetAddress)) .ForMember(dest => dest.SecondStreetAddress, opt => opt.MapFrom(src => src.Address.SecondStreetAddress)) .ForMember(dest => dest.CityName, opt => opt.MapFrom(src => src.Address.CityName)) .ForMember(dest => dest.StateProvince, opt => opt.MapFrom(src => src.Address.StateProvince)) .ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.Address.PostalCode.Code)) .ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.Address.Country)) .ForMember(dest => dest.CountyArea, opt => opt.MapFrom(src => src.Address.CountyArea)); AutoMapperSetup.CreateMapToAbstractDto <BillingOffice, BillingOfficePhonesDto> (); AutoMapperSetup.CreateMapToEditableDto <BillingOfficePhone, BillingOfficePhoneDto> () .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.Phone.PhoneNumber)) .ForMember(dest => dest.Extension, opt => opt.MapFrom(src => src.Phone.PhoneExtensionNumber)); AutoMapperSetup.CreateMapToEditableDto <BillingOffice, BillingOfficeProfileDto> () .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Profile.Name)) .ForMember(dest => dest.EffectiveDate, opt => opt.MapFrom(src => src.Profile.EffectiveDateRange.StartDate)) .ForMember(dest => dest.EndDate, opt => opt.MapFrom(src => src.Profile.EffectiveDateRange.EndDate)) .ForMember(dest => dest.EmailAddress, opt => opt.MapFrom(src => src.Profile.EmailAddress.Address)); AutoMapperSetup.CreateMapToAbstractDto <BillingOffice, BillingOfficeDto> () .ForMember(dest => dest.Profile, opt => opt.MapFrom(src => src)) .ForMember(dest => dest.Addresses, opt => opt.MapFrom(src => src)) .ForMember(dest => dest.PhoneNumbers, opt => opt.MapFrom(src => src)); AutoMapperSetup.CreateMapToAbstractDto <BillingOffice, BillingOfficeSummaryDto> () .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Profile.Name)); }
public void InitializeTest() { var mapper = new AutoMapperSetup().CreateAutoMapperConfig(); var configuration = new ConfigurationSetup().CreateConfiguration(); taxCalculator = new TaxCalculatorTaxJarApi(configuration, mapper); }
public void Get_ValidatingObject() { //Criando a lista com um objeto para que seja retornado pelo repository List <User> _users = new List <User>(); _users.Add(new User { Id = Guid.NewGuid(), Name = "Nicolas Fontes", Email = "*****@*****.**", DateCreated = DateTime.Now }); //Criando um objeto mock do UserRepository e configurando para retornar a lista criada anteriormente se chamar o método GetAll() var _userRepository = new Mock <IUserRepository>(); _userRepository.Setup(x => x.GetAll()).Returns(_users); //Criando um objeto mock do AutoMapper para que possamos converter o retorno para o tipo List<UserViewModel>() var _autoMapperProfile = new AutoMapperSetup(); var _configuration = new MapperConfiguration(x => x.AddProfile(_autoMapperProfile)); IMapper _mapper = new Mapper(_configuration); //Istanciando nossa classe de serviço novamente com os novos objetos mocks que criamos userService = new UserService(_userRepository.Object, _mapper); //Obtendo os valores do método Get para validar se vai retornar o objeto criado acima. var result = userService.Get(); //Validando se o retorno contém uma lista com objetos. Assert.True(result.Count > 0); }
private static void CreateAgencyIdentifierConfig() { AutoMapperSetup.CreateMapToEditableDto <Staff, StaffIdentifiersDto> (); AutoMapperSetup.CreateMapToEditableDto <StaffIdentifier, StaffIdentifierDto> () .ForMember( dest => dest.StartDate, opt => opt.MapFrom( src => src.EffectiveDateRange != null ? src.EffectiveDateRange.StartDate : null)) .ForMember( dest => dest.EndDate, opt => opt.MapFrom(src => src.EffectiveDateRange != null ? src.EffectiveDateRange.EndDate : null)); AutoMapperSetup.CreateMapToAbstractDto <Agency, AgencyIdentifiersDto> (); AutoMapperSetup.CreateMapToEditableDto <AgencyIdentifier, AgencyIdentifierDto> () .ForMember( dest => dest.StartDate, opt => opt.MapFrom( src => src.EffectiveDateRange != null ? src.EffectiveDateRange.StartDate : null)) .ForMember( dest => dest.EndDate, opt => opt.MapFrom(src => src.EffectiveDateRange != null ? src.EffectiveDateRange.EndDate : null)); }
private static void CreateAgencyAddressConfig() { AutoMapperSetup.CreateMapToEditableDto <Staff, StaffPhoneNumbersDto> (); AutoMapperSetup.CreateMapToEditableDto <StaffPhone, StaffPhoneNumberDto> () .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.Phone.PhoneNumber)) .ForMember(dest => dest.PhoneExtensionNumber, opt => opt.MapFrom(src => src.Phone.PhoneExtensionNumber)); AutoMapperSetup.CreateMapToEditableDto <Staff, StaffAddressesDto> (); AutoMapperSetup.CreateMapToEditableDto <StaffAddress, StaffAddressDto> () .ForMember(dest => dest.FirstStreetAddress, opt => opt.MapFrom(src => src.Address.FirstStreetAddress)) .ForMember(dest => dest.SecondStreetAddress, opt => opt.MapFrom(src => src.Address.SecondStreetAddress)) .ForMember(dest => dest.CityName, opt => opt.MapFrom(src => src.Address.CityName)) .ForMember(dest => dest.CountyArea, opt => opt.MapFrom(src => src.Address.CountyArea)) .ForMember(dest => dest.StateProvince, opt => opt.MapFrom(src => src.Address.StateProvince)) .ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.Address.PostalCode.Code)); AutoMapperSetup.CreateMapToAbstractDto <Agency, AgencyAddressesAndPhonesDto> () .ForMember(dest => dest.AddressesAndPhones, opt => opt.MapFrom(src => src.AddressesAndPhones)); AutoMapperSetup.CreateMapToEditableDto <AgencyAddressAndPhone, AgencyAddressAndPhoneDto> () .ForMember(dest => dest.AgencyAddressType, opt => opt.MapFrom(src => src.AgencyAddress.AgencyAddressType)) .ForMember(dest => dest.FirstStreetAddress, opt => opt.MapFrom(src => src.AgencyAddress.Address.FirstStreetAddress)) .ForMember(dest => dest.SecondStreetAddress, opt => opt.MapFrom(src => src.AgencyAddress.Address.SecondStreetAddress)) .ForMember(dest => dest.CityName, opt => opt.MapFrom(src => src.AgencyAddress.Address.CityName)) .ForMember(dest => dest.CountyArea, opt => opt.MapFrom(src => src.AgencyAddress.Address.CountyArea)) .ForMember(dest => dest.StateProvince, opt => opt.MapFrom(src => src.AgencyAddress.Address.StateProvince)) .ForMember(dest => dest.Country, opt => opt.MapFrom(src => src.AgencyAddress.Address.Country)) .ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.AgencyAddress.Address.PostalCode.Code)); }
private static void CreateStaffCredentialsDto() { AutoMapperSetup.CreateMapToEditableDto <Staff, StaffCredentialsDto> (); AutoMapperSetup.CreateMapToEditableDto <StaffCollegeDegree, StaffCollegeDegreeDto> (); AutoMapperSetup.CreateMapToEditableDto <StaffLicense, StaffLicenseDto> () .ForMember( dest => dest.StartDate, opt => opt.MapFrom( src => src.EffectiveDateRange != null ? src.EffectiveDateRange.StartDate : null)) .ForMember( dest => dest.EndDate, opt => opt.MapFrom(src => src.EffectiveDateRange != null ? src.EffectiveDateRange.EndDate : null)); AutoMapperSetup.CreateMapToEditableDto <StaffTrainingCourse, StaffTrainingCourseDto> (); AutoMapperSetup.CreateMapToEditableDto <StaffCertification, StaffCertificationDto> () .ForMember( dest => dest.StartDate, opt => opt.MapFrom( src => src.EffectiveDateRange != null ? src.EffectiveDateRange.StartDate : null)) .ForMember( dest => dest.EndDate, opt => opt.MapFrom(src => src.EffectiveDateRange != null ? src.EffectiveDateRange.EndDate : null)); }
public void ShouldBeValid() { var autoMapperSetup = new AutoMapperSetup(); autoMapperSetup.Run(); Mapper.AssertConfigurationIsValid(); }
public virtual ActionResult _DisplayPurchaseUnitContracts(int unitId, bool showExpired = false) { var uc = _purchaseUnitAndContracts.GetPurchaseUnitContracts(unitId).Where(c => (!c.IsExpiredToday() && !showExpired) || showExpired); var contractVms = AutoMapperSetup.MapList <ServiceContract, ServiceContractVM>(uc).ToList(); contractVms.ForEach(c => c.ExpiryWarning = ExpiryWarning(c.ExpiryDate)); return(View(new GridModel(contractVms))); }
public ActionResult _GetModelSpecificContracts(int id) { var modelContracts = _svc.GetModel(id).ModelSpecificContracts; var modelContractsVM = AutoMapperSetup.MapList <ModelSpecificContract, ModelSpecificContractVM>(modelContracts); return(View(new GridModel(modelContractsVM))); }
private static void SetupClaim() { AutoMapperSetup.CreateMapToAbstractDto <Domain.Billing.ClaimModule.Claim, ClaimSummaryDto> () .ForMember(dest => dest.PayorName, opt => opt.MapFrom(src => src.Payor.Name)) .ForMember(dest => dest.PatientFirstName, opt => opt.MapFrom(src => src.PatientAccount.Name.First)) .ForMember(dest => dest.PatientLastName, opt => opt.MapFrom(src => src.PatientAccount.Name.Last)) .ForMember(dest => dest.PayorType, opt => opt.MapFrom(src => src.ClaimBatch.PayorType.Name)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); AutoMapperSetup.AddAutoMapperSetup(services); SwaggerSetup.AddSwaggerSetup(services); DependencyInjectionSetup.AddDependencyInjectionSetup(services, Configuration); ApiSetup.AddApiSetup(services, Configuration); }
public ActionResult _DisplayRentedUnits(int id, bool?showRemoved) { ViewBag.CustomerAccountId = id; var pred = (showRemoved != null && showRemoved.Value) ? new Func <RentedUnit, bool>(c => true) : (c => c.RemovalDate == null); var units = ((RentalAccount)_accountService.GetAccount(id)).RentedUnits.Where(pred); return(View(new GridModel(AutoMapperSetup.MapList <RentedUnit, RentedUnitVM>(units).ToList()))); }
public static HttpConfiguration Configure() { AutoMapperSetup.Setup(); var webApiConfiguration = new HttpConfiguration(); webApiConfiguration.MapHttpAttributeRoutes(); return(webApiConfiguration); }
private static void CreateAgencySummaryConfig() { AutoMapperSetup.CreateMapToAbstractDto <Agency, AgencySummaryDto> () .ForMember(dest => dest.AddressesAndPhones, opt => opt.MapFrom(src => src.AddressesAndPhones)) .ForMember(dest => dest.DisplayName, opt => opt.MapFrom(src => src.AgencyProfile.AgencyName.DisplayName)); AutoMapperSetup.CreateMapToAbstractDto <Agency, AgencyDisplayNameDto> () .ForMember(dest => dest.DisplayName, opt => opt.MapFrom(src => src.AgencyProfile.AgencyName.DisplayName)); }
/// <summary> /// Creates the map to gpra dto. /// </summary> /// <typeparam name="TSource">The type of the source.</typeparam> /// <typeparam name="TDestination">The type of the destination.</typeparam> /// <returns>A <see cref="AutoMapper.IMappingExpression<TSource,TDestination>"/></returns> public static IMappingExpression <TSource, TDestination> CreateMapToGpraDto <TSource, TDestination> () where TSource : GpraInterviewSectionBase where TDestination : GpraDtoBase { return(AutoMapperSetup.CreateMapToEditableDto <TSource, TDestination> () .ForMember(dest => dest.GpraInterviewKey, opt => opt.Ignore()) .ForMember(dest => dest.Key, opt => opt.Ignore()) .ForMember(dest => dest.GpraNonResponseFilters, opt => opt.MapFrom(src => src.GetFiltersDictionary()))); }
/// <summary> /// Executes this instance. /// </summary> public void Execute() { CreateLookupValueDtoConfig(); CreateMetadataDtoConfig(); AutoMapperSetup.CreateMapToAbstractDto <CodedConcept, CodedConceptDto> () .ForMember(dest => dest.Key, opt => opt.Ignore()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false; AutoMapperSetup.SetupAutoMapper(); DependencyResolver.SetResolver(InitializeDepedencyResolver()); }
private static void CreateAgencyDtoConfig() { AutoMapperSetup.CreateMapToAbstractDto <Agency, AgencyProfileDto> (); AutoMapperSetup.CreateMapToAbstractDto <Agency, AgencyDto> () .ForMember(dest => dest.AgencyProfile, opt => opt.MapFrom(src => src)) .ForMember(dest => dest.AddressesAndPhones, opt => opt.MapFrom(src => src)) .ForMember(dest => dest.AgencyIdentifiers, opt => opt.MapFrom(src => src)) .ForMember(dest => dest.AgencyContacts, opt => opt.MapFrom(src => src)) .ForMember(dest => dest.AgencyFrequentlyAskedQuestions, opt => opt.MapFrom(src => src)); }
private static void CreateStaffSummaryAddressDtoConfig() { AutoMapperSetup.CreateMapToAbstractDto <StaffIdentifier, StaffIdentifierSummaryDto> (); AutoMapperSetup.CreateMapToAbstractDto <StaffAddress, StaffAddressSummaryDto> () .ForMember(dest => dest.FirstStreetAddress, opt => opt.MapFrom(src => src.Address.FirstStreetAddress)) .ForMember(dest => dest.SecondStreetAddress, opt => opt.MapFrom(src => src.Address.SecondStreetAddress)) .ForMember(dest => dest.CityName, opt => opt.MapFrom(src => src.Address.CityName)) .ForMember(dest => dest.StateProvince, opt => opt.MapFrom(src => src.Address.StateProvince)) .ForMember(dest => dest.PostalCode, opt => opt.MapFrom(src => src.Address.PostalCode.Code)); }
public ActionResult _SelectAvailableStock(int id) { var selForInvVM = new SelectStockForInvoiceVM { StockInvoiceId = id, SelectedStock = AutoMapperSetup.MapList <Stock, SelectableStockVM>(_stockInvSvc.GetSelectableStock()).ToList() }; Session["_availableForStock"] = selForInvVM.SelectedStock; return(PartialView(selForInvVM)); }
public ActionResult _DisplayRentalContracts(int id, bool?showExpired) { var cu = _contractService.GetCustomerAccount(id); var pred = (showExpired != null && showExpired.Value) ? new Func <Contract, bool>(c => true) : (c => c.ExpiryDate >= DateTime.Today || c.ExpiryDate == null); return (View( new GridModel( AutoMapperSetup.MapList <RentalContract, EditRentedContractVM>( cu.AttachedContracts.Where(pred).ToList().ConvertAll(c => (RentalContract)c))))); }