/// <summary>
        /// Creates a pledge configuration from the specified api configuration.
        /// </summary>
        /// <param name="apiConfig">The API configuration.</param>
        /// <returns></returns>
        public static IConfiguration CreatePledgeConfiguration(Configuration apiConfig)
        {
            var pledgeConfig = new BaseConfiguration
            {
                Id = apiConfig.Id,
                VersionId = apiConfig.VersionId,
                Name = apiConfig.Name,
                Author = apiConfig.Author,
                Description = apiConfig.Description,
                Rules = ReconstructRules(apiConfig.Rules),
                Model = new BaseDocument
                {
                    InputType = apiConfig.InputSchema.IsDelimited ? DocumentType.Delimited : DocumentType.FixedLength,
                    OutputType = apiConfig.OutputSchema.IsDelimited ? DocumentType.Delimited : DocumentType.FixedLength,
                    InputDelimiter = apiConfig.InputSchema.Delimiter,
                    OutputDelimiter = apiConfig.OutputSchema.Delimiter,
                    InputHasHeader = apiConfig.InputSchema.HasHeaderRow,
                    OutputHasHeader = apiConfig.OutputSchema.HasHeaderRow,
                    InputSchema = RebuildSchema(apiConfig.InputSchema.Rows),
                    OutputSchema = RebuildSchema(apiConfig.InputSchema.Rows, apiConfig.OutputSchema.Rows),
                    VirtualColumnOffset = apiConfig.VirtualColumnOffset,
                    Options = new ConfigurationOptions
                    {
                        OutputAllRecords = apiConfig.Options.OutputAllRecords,
                        OutputErrorCode = apiConfig.Options.OutputErrorCode,
                        OutputErrorDescription = apiConfig.Options.OutputErrorDescription,
                        UseInputSettingsForErrors = apiConfig.Options.UseInputSettingsForErrors
                    }
                }
            };

            return pledgeConfig;
        }
        public void SaveConfiguration(Configuration configuration)
        {
            var coreConfiguration = ModelTransformer.CreatePledgeConfiguration(configuration);
            var user = AuthenticationManager.User;

            _pledgeManager.SaveConfiguration(coreConfiguration, user.Identity.Name);
        }
        /// <summary>
        /// Creates the API configuration.
        /// </summary>
        /// <param name="pledgeConfig">The pledge configuration.</param>
        /// <returns></returns>
        public static Configuration CreateApiConfiguration(IConfiguration pledgeConfig)
        {
            var apiConfig = new Configuration
            {
                Id = pledgeConfig.Id,
                VersionId = pledgeConfig.VersionId,
                IsPersisted = true,
                Name = pledgeConfig.Name,
                Author = pledgeConfig.Author,
                Description = pledgeConfig.Description,
                VirtualColumnOffset = pledgeConfig.Model.VirtualColumnOffset,
                InputSchema = new Schema
                {
                    IsDelimited = pledgeConfig.Model.InputType == DocumentType.Delimited,
                    Delimiter = pledgeConfig.Model.InputDelimiter,
                    HasHeaderRow = pledgeConfig.Model.InputHasHeader,
                    Rows = pledgeConfig.Model.InputSchema.Select(item => new SchemaRow
                        {
                            InputHeader = item.ColumnName,
                            InputHeaderAlias = item.ColumnNameAlias,
                            InputIndex = item.ColumnIndex,
                            InputNumber = item.ColumnNumber,
                            InputLength = item.ColumnLength,
                            IsVirtual = item.IsVirtual
                    }).ToList()
                },
                OutputSchema = new Schema
                {
                    IsDelimited = pledgeConfig.Model.OutputType == DocumentType.Delimited,
                    Delimiter = pledgeConfig.Model.OutputDelimiter,
                    HasHeaderRow = pledgeConfig.Model.OutputHasHeader,
                    Rows = pledgeConfig.Model.OutputSchema.Select(item => new SchemaRow
                        {
                            InputHeader = item.InputColumnName,
                            InputHeaderAlias = item.ColumnNameAlias,
                            InputIndex = item.InputColumnIndex,
                            OutputHeader = item.ColumnName,
                            OutputIndex = item.ColumnIndex,
                            OutputNumber = item.ColumnNumber,
                            OutputLength = item.ColumnLength,
                            IsSelected = item.IsSelected,
                            IsVirtual = item.IsVirtual
                    }).ToList()
                },
                Rules = DeconstructRules(pledgeConfig),
                Options = new Options
                {
                    OutputAllRecords = pledgeConfig.Model.Options.OutputAllRecords,
                    OutputErrorCode = pledgeConfig.Model.Options.OutputErrorCode,
                    OutputErrorDescription = pledgeConfig.Model.Options.OutputErrorDescription,
                    UseInputSettingsForErrors = pledgeConfig.Model.Options.UseInputSettingsForErrors
                }
            };

            return apiConfig;
        }
Exemple #4
0
        internal static Mock<IAuthenticationManager> Initialize(MoqMockingKernel kernel)
        {
            Configuration = new Configuration
            {
                Id = Guid.Empty,
                VersionId = 1,
                Name = "",
                Author = "Test",
                Description = "Test",
                InputSchema = new Schema
                {
                    Delimiter = "-",
                    Rows = new List<SchemaRow>()
                },
                OutputSchema = new Schema
                {
                    Delimiter = "@",
                    Rows = new List<SchemaRow>()
                },
                Rules = new List<RuleSet>(),
                Options = new Options
                {
                    OutputAllRecords = true,
                    OutputErrorCode = true,
                    OutputErrorDescription = true,
                    UseInputSettingsForErrors = true
                }
            };

            Job = new RemoteJob
            {
                JobId = Guid.NewGuid(),
                JobName = "Unit test Job",
                IngestMediumSettings = new SerializableDictionary<string, string>
                {
                    {PledgeGlobal.NamespaceKey, typeof (FakeIngest).AssemblyQualifiedName},
                    {PledgeGlobal.ImportFolderKey, UnitTestHelper.FakeIngestProperty},
                    {PledgeGlobal.FilePatternKey, UnitTestHelper.FakeIngestValue}
                },
                PledgeSettings = new SerializableDictionary<string, string>
                {
                    {PledgeGlobal.NamespaceKey, PledgeGlobal.BuiltInPledge},
                    {PledgeGlobal.ClientId, Guid.NewGuid().ToString()}
                },
                EgestMediumSettings = new SerializableDictionary<string, string>
                {
                    {PledgeGlobal.NamespaceKey, typeof (FakeEgest).AssemblyQualifiedName},
                    {PledgeGlobal.PassPrefixKey, UnitTestHelper.FakeEgestProperty},
                    {PledgeGlobal.FailPrefixKey, UnitTestHelper.FakeEgestValue}
                }
            };

            var claims = new List<Claim>
            {
                new Claim(SecurityGlobal.UserGroupClaim, FakeUserGroupManager.IdGroupB.ToString()),
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", FakeUserGroupManager.IdUser2.ToString())
            };

            var identity = kernel.GetMock<IIdentity>();
            identity.Setup(mock => mock.IsAuthenticated).Returns(true);
            identity.Setup(mock => mock.Name).Returns(FakeRepository.UserName);

            var claimsIdentity = new ClaimsIdentity(identity.Object, claims);

            var user = new ClaimsPrincipal(claimsIdentity);

            var authenticationManager = kernel.GetMock<IAuthenticationManager>();
            authenticationManager.Setup(mock => mock.User).Returns(user);

            return authenticationManager;
        }