예제 #1
0
        public void Upsert(ConnectorProductAttributeMapping connectorProductAttributeMapping)
        {
            Validate(connectorProductAttributeMapping);
            ValidateProperties(connectorProductAttributeMapping.Properties);

            var status = ConnectorProductAttributeRepository.Upsert(new ConnectorProductAttribute
            {
                ConnectorID          = connectorProductAttributeMapping.Connector.ConnectorID,
                DefaultValue         = TypeConverterService.Default[connectorProductAttributeMapping.ProductAttributeType].ConvertToString(connectorProductAttributeMapping.DefaultValue),
                IsFilter             = connectorProductAttributeMapping.IsFilter,
                ProductAttributeID   = connectorProductAttributeMapping.ProductAttribute.AttributeID,
                ProductAttributeType = connectorProductAttributeMapping.ProductAttributeType.FullName
            });

            var connectorProductAttribute = ConnectorProductAttributeRepository.GetSingle(
                connectorProductAttributeMapping.Connector.ConnectorID,
                connectorProductAttributeMapping.ProductAttribute.AttributeID,
                connectorProductAttributeMapping.IsFilter);

            if (status == RepositoryOperationStatus.Created)
            {
                foreach (var connectorProductAttributeSettingTemplate in ConnectorProductAttributeSettingTemplateRepository.GetMultiple(connectorProductAttributeMapping.Connector.ConnectorSystemID))
                {
                    var templateSettingCode = connectorProductAttributeSettingTemplate.Code;

                    if (!connectorProductAttributeMapping.Properties.ContainsKey(templateSettingCode))
                    {
                        var templateSettingType = Type.GetType(connectorProductAttributeSettingTemplate.Type);

                        if (templateSettingType != null)
                        {
                            var templateSettingValue = TypeConverterService.ConvertFromString(templateSettingType, connectorProductAttributeSettingTemplate.Value);

                            connectorProductAttributeMapping.Properties[templateSettingCode] = templateSettingValue;
                        }
                    }
                }
            }

            SynchronizeProperties(connectorProductAttribute, connectorProductAttributeMapping.Properties);
        }
예제 #2
0
        public void GetSingle()
        {
            var repository = new ConnectorProductAttributeSettingTemplateRepository(Connection);

            var connectorSystemID    = GetConnectorSystemID();
            var settingTemplate      = default(ConnectorProductAttributeSettingTemplate);
            var settingTemplateCode  = "UNIT_TEST_GET_SINGLE";
            var settingTemplateType  = typeof(Guid).FullName;
            var settingTemplateValue = Guid.NewGuid().ToString();

            ExecuteCommand("INSERT INTO {0} ([ConnectorSystemID], [Code], [Type], [Value]) VALUES ({1}, '{2}', '{3}', '{4}')"
                           , ConnectorProductAttributeSettingTableName
                           , connectorSystemID
                           , settingTemplateCode
                           , settingTemplateType
                           , settingTemplateValue);

            try
            {
                settingTemplate = repository.GetSingle(connectorSystemID, settingTemplateCode);

                Assert.NotNull(settingTemplate);
                Assert.Equal(settingTemplate.ConnectorSystemID, connectorSystemID);
                Assert.Equal(settingTemplate.Code, settingTemplateCode);
                Assert.Equal(settingTemplate.Type, settingTemplateType);
                Assert.Equal(settingTemplate.Value, settingTemplateValue);
            }
            finally
            {
                ExecuteCommand("DELETE FROM {0} WHERE [ConnectorSystemID] = {1} AND [Code] = '{2}'"
                               , ConnectorProductAttributeSettingTableName
                               , connectorSystemID
                               , settingTemplateCode);
            }

            settingTemplate = repository.GetSingle(connectorSystemID, settingTemplateCode);

            Assert.Null(settingTemplate);
        }