Пример #1
0
        static MappingTest()
        {
            var mf = new DefaultMapperFactory();
            var sp = new Mock <IServiceProvider>();

            sp.Setup(s => s.GetService(typeof(IMapperFactory))).Returns(mf);

            var serviceScope = new Mock <IServiceScope>();

            serviceScope.Setup(x => x.ServiceProvider).Returns(sp.Object);

            var serviceScopeFactory = new Mock <IServiceScopeFactory>();

            serviceScopeFactory
            .Setup(x => x.CreateScope())
            .Returns(serviceScope.Object);

            sp.Setup(x => x.GetService(typeof(IServiceScopeFactory)))
            .Returns(serviceScopeFactory.Object);
            ServiceProviderMock = sp;

            MappingExtensions.Configure("default", cfg =>
            {
                cfg.CreateMap <TestClass1, TestClass2>()
                .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.Id.ToString()));
            });

            MappingExtensions.Build(sp.Object);
        }
 public static SchemaAttribute CreateComplexAttribute(
     string name,
     string description,
     List <SchemaAttribute> subAttributes,
     string type              = Common.Constants.SchemaAttributeTypes.String,
     bool multiValued         = false,
     bool required            = false,
     bool caseExact           = false,
     string mutability        = Common.Constants.SchemaAttributeMutability.ReadWrite,
     string returned          = Common.Constants.SchemaAttributeReturned.Default,
     string uniqueness        = Common.Constants.SchemaAttributeUniqueness.None,
     string[] referenceTypes  = null,
     string[] canonicalValues = null,
     bool isCommon            = false)
 {
     return(new SchemaAttribute
     {
         Id = Guid.NewGuid().ToString(),
         Name = name,
         MultiValued = multiValued,
         Description = description,
         Required = required,
         CaseExact = caseExact,
         Mutability = mutability,
         Returned = returned,
         Uniqueness = uniqueness,
         ReferenceTypes = MappingExtensions.ConcatList(referenceTypes),
         CanonicalValues = MappingExtensions.ConcatList(canonicalValues),
         Children = subAttributes,
         IsCommon = isCommon,
         Type = Common.Constants.SchemaAttributeTypes.Complex
     });
 }
Пример #3
0
        public void test_un_mappable_types()
        {
            var properties = typeof(TypeWithNoMappableProperties).GetProperties();

            properties.Should().NotBeEmpty();
            properties.Should().NotContain(c => MappingExtensions.IsMappableProperty(c));
        }
Пример #4
0
        /// <summary>
        /// Basic file receiver for .NET Core
        /// </summary>
        /// <param name="id">Owner Id</param>
        /// <param name="files">Files to add to attachments</param>
        /// <returns></returns>
        public IActionResult OwnerIdAttachmentsPostAsync(int id, IList <IFormFile> files)
        {
            // validate the bus id
            bool exists = _context.Owners.Any(a => a.Id == id);

            if (exists)
            {
                Owner owner = _context.Owners
                              .Include(x => x.Attachments)
                              .First(a => a.Id == id);

                AddFilesToAttachments(owner.Attachments, files);

                _context.Owners.Update(owner);
                _context.SaveChanges();

                List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(owner.Attachments);

                return(new ObjectResult(result));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Пример #5
0
        /// <summary>
        ///     Configures the services to add to the ASP.NET Core Injection of Control (IoC) container. This method gets
        ///     called by the ASP.NET runtime. See
        ///     http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
        /// </summary>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCorrelationIdFluent();
            services.AddCustomCaching();
            services.AddCustomOptions(configuration);
            services.AddCustomRouting();
            services.AddCustomResponseCompression();
            services.AddCustomStrictTransportSecurity();
            services.AddCustomHealthChecks();
            services.AddHttpContextAccessor();
            services.AddMediatR(Assembly.GetExecutingAssembly());
            services.AddMvcCore()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddAuthorization()
            .AddJsonFormatters()
            .AddCustomJsonOptions(this.hostingEnvironment)
            .AddCustomCors()
            .AddCustomMvcOptions(this.hostingEnvironment);

            //services.ConfigureCors();
            services.AddCustomGraphQL(hostingEnvironment);
            services.ConfigureMySqlContext(configuration);
            services.ConfigureUnitOfWork();
            services.ConfigureDomainService();
            services.ConfigureApplicationService();
            services.ConfigureProjectSchemas();
            services.ConfigureMediatr();
            services.BuildServiceProvider();
            services.ConfigureAuthentication(configuration);
            MappingExtensions.ConfigureMapping();
        }
Пример #6
0
        /// <summary>
        ///  Basic file receiver for .NET Core
        /// </summary>
        /// <param name="id">SchoolBus Owner Id</param>
        /// <param name="files">Files to add to attachments</param>
        /// <returns></returns>
        public IActionResult SchoolbusownersIdAttachmentsPostAsync(int id, IList <IFormFile> files)
        {
            // validate the bus id
            bool exists = _context.SchoolBusOwners.Any(a => a.Id == id);

            if (exists)
            {
                SchoolBusOwner schoolBusOwner = _context.SchoolBusOwners
                                                .Include(x => x.Attachments)
                                                .Include(x => x.Contacts)
                                                .Include(x => x.District.Region)
                                                .Include(x => x.History)
                                                .Include(x => x.Notes)
                                                .Include(x => x.PrimaryContact)
                                                .First(a => a.Id == id);

                AddFilesToAttachments(schoolBusOwner.Attachments, files);

                _context.SchoolBusOwners.Update(schoolBusOwner);
                _context.SaveChanges();

                List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(schoolBusOwner.Attachments);

                return(new ObjectResult(result));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Пример #7
0
        public async Task <bool> Update(ResourceSet resourceSet)
        {
            using (var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false))
            {
                try
                {
                    var record = await _context.ResourceSets.FirstOrDefaultAsync(r => r.Id == resourceSet.Id).ConfigureAwait(false);

                    if (record == null)
                    {
                        return(false);
                    }

                    record.Name    = resourceSet.Name;
                    record.Scopes  = MappingExtensions.GetConcatenatedList(resourceSet.Scopes);
                    record.Type    = resourceSet.Type;
                    record.Uri     = resourceSet.Uri;
                    record.IconUri = resourceSet.IconUri;
                    await _context.SaveChangesAsync().ConfigureAwait(false);

                    transaction.Commit();
                    return(true);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(false);
                }
            }
        }
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddHttpContextAccessor();
     services.ConfigureAuthenticationServices(Configuration);
     services.ConfigureApplicationServices(Configuration, WebHostEnvironment);
     services.ConfigureLoggingServices(Configuration);
     MappingExtensions.ConfigureMappingServices();
 }
Пример #9
0
        public void AddNode(ScriptableNodeMapData scriptableNode)
        {
            NodeMapData objNode = ScriptableMapper.GetNode(scriptableNode);

            GraphComponents graphComponents = GraphManager.Instance.DefaultGraphComponentsInstance;

            MappingExtensions.AddNode(graphComponents, CreationType.Live, objNode);
        }
 public void Configure(AnyServiceConfig config)
 {
     MappingExtensions.AddConfiguration(config.MapperName, cfg =>
     {
         cfg.CreateMap <CategoryModel, Category>()
         .ForMember(dest => dest.AdminComment, mo => mo.Ignore());
     });
 }
Пример #11
0
        public override void Load()
        {
            MappingExtensions.ConfigureMappingServices();

            LoadConfiguration <Spine>("SELECT * FROM configuration.get_spine_configuration()", "Spine");
            LoadConfiguration <General>("SELECT * FROM configuration.get_general_configuration()", "General");
            LoadConfiguration <Sso>("SELECT * FROM configuration.get_sso_configuration()", "SingleSignOn");
            LoadConfiguration <Email>("SELECT * FROM configuration.get_email_configuration()", "Email");
        }
        public void ToClientSurveyAnswerReturnsTitleAndSlug()
        {
            var clientSurveyAnswer = MappingExtensions.ToSurveyAnswer(new SurveyAnswer {
                Title = "testtitle", SlugName = "slugname"
            });

            Assert.AreEqual("testtitle", clientSurveyAnswer.Title);
            Assert.AreEqual("slugname", clientSurveyAnswer.SlugName);
        }
Пример #13
0
            public override async Task <Unit> Handle(UpdateCharacterAction action, CancellationToken aCancellationToken)
            {
                var response = await this.httpService.PutJson("api/Characters/Update", action.Character);

                if (response.IsOk)
                {
                    MappingExtensions.To(response.Data, this.CharacterState.Character);
                }

                return(await Unit.Task);
            }
Пример #14
0
        private void GatewayProviderServiceOnSaved(IGatewayProviderService sender, SaveEventArgs <IGatewayProviderSettings> args)
        {
            var key      = new Guid(Constants.GatewayProviderSettingsKey);
            var provider = args.SavedEntities.FirstOrDefault(x => key == x.Key && !x.HasIdentity);

            if (provider == null)
            {
                return;
            }

            MappingExtensions.SaveProcessorSettings(provider.ExtendedData, new SagePayProcessorSettings());
        }
        private void SetMappings(NHibernate.Cfg.Configuration configuration)
        {
            var mapper = new ModelMapper();

            mapper.AddMappings(MappingExtensions.GetMappingsAssembly <TDbContext>().GetTypes());

            var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();

            configuration.AddMapping(mappings);

            SchemaMetadataUpdater.QuoteTableAndColumns(configuration, new MsSql2012Dialect());
        }
Пример #16
0
        public void MapToViewModel_WithValidModel_ReturnsChequeViewModel()
        {
            var cm = new ChequeModel
            {
                PayeeName    = "John Doe",
                DollarAmount = 1234.56,
                IssueDate    = DateTime.Now
            };

            var vm = MappingExtensions.MapToViewModel(cm);

            vm.Should().NotBeNull();
        }
        public void ToClientQuestionAnswerReturnsAnswer()
        {
            var clientQuestionAnswer = MappingExtensions.ToQuestionAnswer(new QuestionAnswer
            {
                QuestionText = "questiontext",
                Answer       = "answervalue",
                QuestionType = "SimpleText"
            });

            Assert.AreEqual("questiontext", clientQuestionAnswer.QuestionText);
            Assert.AreEqual("answervalue", clientQuestionAnswer.Answer);
            Assert.AreEqual(Client.Models.QuestionType.SimpleText, clientQuestionAnswer.QuestionType);
        }
Пример #18
0
        /// <summary>
        /// Basic file receiver for .NET Core
        /// </summary>
        /// <param name="id">Owner Id</param>
        /// <param name="files">Files to add to attachments</param>
        /// <returns></returns>
        public IActionResult OwnerIdAttachmentsPostAsync(int id, IList <IFormFile> files)
        {
            // validate the bus id
            bool exists = _context.Owners.Any(a => a.Id == id);

            if (exists)
            {
                Owner owner = _context.Owners
                              .Include(x => x.Attachments)
                              .First(a => a.Id == id);

                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        Attachment attachment = new Attachment();

                        // strip out extra info in the file name
                        if (!string.IsNullOrEmpty(file.FileName))
                        {
                            attachment.FileName = Path.GetFileName(file.FileName);
                        }

                        // allocate storage for the file and create a memory stream
                        attachment.FileContents = new byte[file.Length];

                        using (MemoryStream fileStream = new MemoryStream(attachment.FileContents))
                        {
                            file.CopyTo(fileStream);
                        }

                        attachment.Type     = GetType(attachment.FileName);
                        attachment.MimeType = GetMimeType(attachment.Type);

                        owner.Attachments.Add(attachment);
                    }
                }

                _context.SaveChanges();

                List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(owner.Attachments);

                return(new ObjectResult(result));
            }

            // record not found
            return(new StatusCodeResult(404));
        }
        public BaseTest()
        {
            var config = new MapperConfiguration(options =>
            {
                options.AddProfile <MappingProfile>();
                options.AddProfile <GeneratedMappingProfile>();
            });

            Mapper = config.CreateMapper();

            DomainToEntityFactory.Configure(Mapper);
            EntityToDomainFactory.Configure(Mapper);
            ResponseFactory.Configure(Mapper);
            ApiToDomainFactory.Configure(Mapper);
            MappingExtensions.Configure(Mapper);
        }
Пример #20
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            MappingExtensions.ConfigureMappingServices();
            builder.Services.AddScoped <IDataService, DataService>();
            builder.Services.AddScoped <IConfigurationService, ConfigurationService>();
            builder.Services.AddScoped <IBlobService, BlobService>();
            builder.Services.AddScoped <IImportService, ImportService>();
            builder.Services.AddScoped <ISplunkService, SplunkService>();

            var configuration = builder.GetContext().Configuration;

            builder.Services.AddLogging(loggingBuilder => LoggingExtensions.ConfigureLoggingServices(loggingBuilder, configuration));
            builder.Services.AddHttpClient("SplunkApiClient", options => Configuration.Infrastructure.HttpClient.HttpClientExtensions.ConfigureHttpClient(options))
            .ConfigurePrimaryHttpMessageHandler(() => Configuration.Infrastructure.HttpClient.HttpClientExtensions.CreateHttpMessageHandler());
            builder.Services.AddSmtpClientServices(configuration);
        }
Пример #21
0
        /// <summary>
        /// Get attachments associated with a project
        /// </summary>
        /// <remarks>Returns attachments for a particular Project</remarks>
        /// <param name="id">id of Project to fetch attachments for</param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>

        public virtual IActionResult ProjectsIdAttachmentsGetAsync(int id)
        {
            bool exists = _context.Projects.Any(a => a.Id == id);

            if (exists)
            {
                Project project = _context.Projects
                                  .Include(x => x.Attachments)
                                  .First(a => a.Id == id);
                var result = MappingExtensions.GetAttachmentListAsViewModel(project.Attachments);
                return(new ObjectResult(result));
            }

            // record not found
            return(new StatusCodeResult(404));
        }
Пример #22
0
        /// <summary>
        /// Get attachments associated with a project
        /// </summary>
        /// <remarks>Returns attachments for a particular Project</remarks>
        /// <param name="id">id of Project to fetch attachments for</param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>
        public virtual IActionResult ProjectsIdAttachmentsGetAsync(int id)
        {
            bool exists = _context.Projects.Any(a => a.Id == id);

            if (exists)
            {
                Project project = _context.Projects
                                  .Include(x => x.Attachments)
                                  .First(a => a.Id == id);

                List <AttachmentViewModel> result = MappingExtensions.GetAttachmentListAsViewModel(project.Attachments);

                return(new ObjectResult(new HetsResponse(result)));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Пример #23
0
        /// <summary>
        /// Executes the JavaScript function specified by <paramref name="callbackName"/>
        /// </summary>
        /// <param name="sender">The NodeViewModel that raised the event</param>
        /// <param name="callbackName">The name of the JavaScript function to execute</param>
        private static void ExecuteNodeJSCallback(object sender, string callbackName)
        {
            //TODO:  VALIDATE CALLBACK
            try
            {
                NodeViewModelBase     nodeVM                = (NodeViewModelBase)sender;
                NodeMapData           nodeMapData           = MappingExtensions.GetNode(nodeVM);
                ScriptableNodeMapData scriptableNodeMapData = ScriptableMapper.GetNode(nodeMapData);

                HtmlPage.Window.Invoke(callbackName, scriptableNodeMapData);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Unable to find the '" + callbackName + "' method in the host application", "Unknown callback", MessageBoxButton.OK);
                // Swallow error for now
                //TODO:  LOG THIS CASE
            }
        }
Пример #24
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Returns attachments for a particular SchoolBus</remarks>
        /// <param name="id">id of SchoolBus to fetch attachments for</param>
        /// <response code="200">OK</response>
        /// <response code="404">SchoolBus not found</response>

        public virtual IActionResult SchoolbusesIdAttachmentsGetAsync(int id)
        {
            bool exists = _context.SchoolBuss.Any(a => a.Id == id);

            if (exists)
            {
                SchoolBus schoolBus = _context.SchoolBuss
                                      .Include(x => x.Attachments)
                                      .First(a => a.Id == id);
                var result = MappingExtensions.GetAttachmentListAsViewModel(schoolBus.Attachments);
                return(new ObjectResult(result));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Пример #25
0
        public static List <TPage> GetAllDataWithMap(string whereQuery)
        {
            string baseWhereQuery = " Where IsDeleted=0";

            if (!string.IsNullOrEmpty(whereQuery))
            {
                baseWhereQuery = baseWhereQuery + " AND " + whereQuery;
            }

            ReturnOutput returnOutput = new ReturnOutput();

            var repository = BaseCommonRepository <T> .BaseRepository();

            var data = repository.Find(baseWhereQuery, ref returnOutput);

            var retVal = MappingExtensions.ToModel <T, TPage>(data.ToList());

            return(retVal);
        }
Пример #26
0
        public async Task <Result> EditAsync(IEnumerable <TModel> models, CancellationToken cancellationToken = default)
        {
            var modelList = models.ToList();

            var ids        = modelList.Select(m => m.Id).ToList();
            var entityList = await FindEntityListAsync(e => ids.Contains(e.Id), cancellationToken);

            var modifiedList = modelList.ToModifiedList <TEntity, TModel, TKey>(entityList, MapToModel);

            var result = await BeforeEditAsync(modifiedList, entityList, cancellationToken);

            if (result.Failed)
            {
                return(result);
            }

            MappingExtensions.Map(modelList, entityList, MapToEntity);

            await AfterMappingAsync(modelList, entityList, cancellationToken);

            result = await EventBus.TriggerEditingEventAsync <TModel, TKey>(modifiedList, cancellationToken);

            if (result.Failed)
            {
                return(result);
            }

            await UpdateEntityListAsync(entityList, cancellationToken);

            MappingExtensions.Map(entityList, modelList, MapToModel);

            result = await AfterEditAsync(modifiedList, entityList, cancellationToken);

            if (result.Failed)
            {
                return(result);
            }

            result = await EventBus.TriggerEditedEventAsync <TModel, TKey>(modifiedList, cancellationToken);

            return(result);
        }
            public void Execute()
            {
                for (int i = 0; i < ConvertedData.Length; i++)
                {
                    NoteData note = PlacementHelper.ConvertNoteDataWithVanillaMethod(RawData[i], LineOffset);

                    note.TransformData.Speed = NoteJumpSpeed;

                    if (UsesNoodleExtensions)
                    {
                        note = NoodleExtensions.ConvertNoteData(note, RawData[i], LineOffset);
                    }
                    else if (UsesMappingExtensions)
                    {
                        note = MappingExtensions.ConvertNoteData(note, RawData[i], LineOffset);
                    }

                    ConvertedData[i] = note;
                }
            }
Пример #28
0
        public async Task <Result> CreateAsync(IEnumerable <TModel> models, CancellationToken cancellationToken = default)
        {
            var modelList = models.ToList();

            var result = await BeforeCreateAsync(modelList, cancellationToken);

            if (result.Failed)
            {
                return(result);
            }

            var entityList = modelList.MapReadOnlyList <TModel, TEntity>(MapToEntity);

            await AfterMappingAsync(modelList, entityList, cancellationToken);

            result = await EventBus.TriggerCreatingEventAsync <TModel, TKey>(modelList, cancellationToken);

            if (result.Failed)
            {
                return(result);
            }

            await CreateEntityListAsync(entityList, cancellationToken);

            MappingExtensions.Map(entityList, modelList, MapToModel);

            result = await AfterCreateAsync(modelList, cancellationToken);

            if (result.Failed)
            {
                return(result);
            }

            result = await EventBus.TriggerCreatedEventAsync <TModel, TKey>(modelList, cancellationToken);

            return(result);
        }
Пример #29
0
        protected void LoadAll <T>(Dictionary <string, Condition> filter, Action <List <T> > completion) where T : DynamoDBMapper.Model.Model, new()
        {
            var request = new ScanRequest
            {
                TableName = TableName()
            };

            if (filter != null && filter.Count > 0)
            {
                request.ScanFilter = filter;
            }

            _ddbClient.ScanAsync(request, (result) =>
            {
                List <T> results = new List <T>();
                foreach (Dictionary <string, AttributeValue> item
                         in result.Response.Items)
                {
                    T instance = MappingExtensions.MapModel <T>(item);
                    results.Add(instance);
                }
                completion(results);
            });
        }
Пример #30
0
        public void MapToViewModel_WithNullModel_ReturnsNull()
        {
            var vm = MappingExtensions.MapToViewModel((ChequeModel)null);

            vm.Should().BeNull();
        }