private static bool IsObjectDifferent(SyncObject aftObject, SyncObject salsaObject, FieldMapping mapping) { var aftValue = aftObject[mapping.AftField]; var salsValue = salsaObject[mapping.AftField]; if (aftValue == null && salsValue == null) return false; if (aftValue == null) return true; return !aftValue.Equals(salsValue); }
public static void CreateFieldMappings(FieldMapping fieldMapping) { using (var db = new AftDbContext()) { db.FieldMappings.Add(fieldMapping); db.SaveChanges(); } }
public void SetUp() { Config.Environment = Config.Test; _salsaClient = new Mock<ISalsaClient>(); TestUtils.RemoveSyncConfigForObjectType(ObjectType); TestUtils.CreateSyncConfig(ObjectType, SyncDirection.Export, 1); TestUtils.CreateSyncConfig(ObjectType, SyncDirection.Import, 2); TestUtils.RemoveFieldMappingsForObjectType(ObjectType); var mapping1 = new FieldMapping { AftField = "f1", DataType = DataType.String, ObjectType = ObjectType, MappingRule = "aftWins", SalsaField = "f1" }; var mapping2 = new FieldMapping { AftField = "First_Name", DataType = DataType.Int, ObjectType = ObjectType, MappingRule = "aftWins", SalsaField = "First_Name" }; TestUtils.CreateFieldMappings(mapping1); TestUtils.CreateFieldMappings(mapping2); _sanityChecker = new SanityChecker(_salsaClient.Object); }
public void SetUp() { Config.Environment = Config.Test; _mapperFactoryMock = new Mock<IMapperFactory>(); var mapping1 = new FieldMapping {AftField = "First_Name", SalsaField = "First_Name", DataType = DataType.String}; var mapping2 = new FieldMapping {AftField = "Last_Name", SalsaField = "Last_Name", DataType = DataType.String}; var mapping3 = new FieldMapping { AftField = "ProcessedDate", DataType = DataType.DateTime }; var mapping4 = new FieldMapping {AftField = "Email", DataType = DataType.String}; var mapping5 = new FieldMapping {AftField = "PE_Pub", DataType = DataType.Boolean}; _mapper = new Mapper(ObjectType, new List<FieldMapping>{mapping1, mapping2, mapping3, mapping4, mapping5}); _repository = new QueueRepository(_mapperFactoryMock.Object); _syncObject = new SyncObject(ObjectType); TestUtils.ClearAllQueues(); }
public void SetUp() { Config.Environment = Config.Test; TestUtils.RemoveSyncConfigForObjectType(ObjectType); TestUtils.CreateSyncConfig(ObjectType, SyncDirection.Export, 1); TestUtils.CreateSyncConfig(ObjectType, SyncDirection.Import, 2); TestUtils.RemoveFieldMappingsForObjectType(ObjectType); TestUtils.CreateEmptyTable(_afttosalsaqueue); TestUtils.CreateEmptyTable(_afttosalsaqueueHistory); TestUtils.CreateEmptyTable(_salsatoaftqueue); TestUtils.CreateEmptyTable(_salsatoaftqueueHistory); var mapping1 = new FieldMapping {AftField = "f1", DataType = DataType.String, ObjectType = ObjectType, MappingRule = "aftWins", SalsaField = "f1"}; var mapping2 = new FieldMapping {AftField = "First_Name", DataType = DataType.Int, ObjectType = ObjectType, MappingRule = "aftWins", SalsaField = "First_Name"}; TestUtils.CreateFieldMappings(mapping1); TestUtils.CreateFieldMappings(mapping2); _result = new SanityChecker(new SalsaClient()).VerifyQueues(); }
public void ShouldAlwaysSaveObjectForNewObject() { var key = 1234; SyncObject salsaObj = null; var salsaXml = XElement.Parse("<item></item>"); var primaryFieldMapping = new FieldMapping{AftField = "Email", SalsaField = "email"}; var mappings = new List<FieldMapping>{new FieldMapping{SalsaField = "Email"}, new FieldMapping{SalsaField = "Address"}}; var aftObj = new SyncObject(ObjectType) {SalsaKey = 0}; aftObj["Email"] = "*****@*****.**"; var nameValues = new NameValueCollection(); _mapperMock.SetupGet(m => m.PrimaryKeyMapping).Returns(primaryFieldMapping); _mapperMock.SetupGet(m => m.Mappings).Returns(mappings); _salsaClient.Setup(s => s.GetObjectBy(ObjectType, primaryFieldMapping.SalsaField, aftObj[primaryFieldMapping.AftField].ToString(), It.IsAny<IEnumerable<string>>())).Returns(salsaXml); _mapperMock.Setup(m => m.ToAft(salsaXml)).Returns(salsaObj); _mapperMock.Setup(m => m.ToSalsa(aftObj, salsaObj)).Returns(nameValues); _salsaClient.Setup(s => s.Save(ObjectType, nameValues)).Returns(key.ToString); var saved = _repository.Save(aftObj); Assert.IsTrue(saved); Assert.AreEqual(key, aftObj.SalsaKey); }
private static bool IsSalsaFieldBlank(SyncObject salsaObject, FieldMapping fieldMapping) { if (fieldMapping.DataType.EqualsIgnoreCase(DataType.Boolean)) return false; //blank cannot be applied to bool in salsa; return salsaObject[fieldMapping.AftField] == null; }
public void ShouldNotSaveObjectIfObjectsAreIdentical() { var salsaObj = new SyncObject(ObjectType); var salsaXml = XElement.Parse("<item></item>"); var primaryFieldMapping = new FieldMapping { AftField = "Email", SalsaField = "email" }; var mappings = new List<FieldMapping> { new FieldMapping { SalsaField = "Email" }, new FieldMapping { SalsaField = "Address" } }; var aftObj = new SyncObject(ObjectType) { SalsaKey = 0 }; aftObj["Email"] = "*****@*****.**"; var nameValues = new NameValueCollection(); _mapperMock.SetupGet(m => m.PrimaryKeyMapping).Returns(primaryFieldMapping); _mapperMock.SetupGet(m => m.Mappings).Returns(mappings); _salsaClient.Setup(s => s.GetObjectBy(ObjectType, primaryFieldMapping.SalsaField, aftObj[primaryFieldMapping.AftField].ToString(), It.IsAny<IEnumerable<string>>())).Returns(salsaXml); _mapperMock.Setup(m => m.ToAft(salsaXml)).Returns(salsaObj); _objectComparator.Setup(m => m.AreIdentical(aftObj, salsaObj, mappings)).Returns(true); var saved = _repository.Save(aftObj); _salsaClient.Verify(s => s.Save(ObjectType, nameValues), Times.Never()); Assert.IsFalse(saved); }
public void ShouldHandleExceptionWhenSavingObject() { var id = 7890; var supporter = new SyncObject(ObjectType) {QueueId = id,}; supporter["Email"] = "*****@*****.**"; var primaryFieldMapping = new FieldMapping {AftField = "Email", SalsaField = "email"}; _mapperMock.SetupGet(m => m.PrimaryKeyMapping).Returns(primaryFieldMapping); var error = new Exception("test error"); _salsaClient.Setup(s => s.GetObjectBy(ObjectType, primaryFieldMapping.SalsaField, supporter["Email"].ToString(), It.IsAny<IEnumerable<string>>())) .Throws(error); _repository.Save(supporter); }
private bool CanMatch(DataColumn column, FieldMapping mapping, string syncDirection) { if (syncDirection.EqualsIgnoreCase(SyncDirection.Export) && mapping.MappingRule.EqualsIgnoreCase(MappingRules.readOnly)) return true; if (syncDirection.EqualsIgnoreCase(SyncDirection.Import) && (mapping.MappingRule.EqualsIgnoreCase(MappingRules.writeOnly) ||mapping.MappingRule.EqualsIgnoreCase(MappingRules.writeOnlyNewMembership))) return true; if (!_typeMappings.Keys.Contains(column.DataType.Name)) { Logger.Debug("Cannot find type:" + column.DataType.Name); return false; } return column.ColumnName.EqualsIgnoreCase(mapping.AftField) && _typeMappings[column.DataType.Name].EqualsIgnoreCase(mapping.DataType); }
private void SetFieldValueToSalsa(SyncObject aftObject, FieldMapping fieldMapping, NameValueCollection result) { var converter = DataTypeConverter.GetConverter(fieldMapping.DataType); result[fieldMapping.SalsaField] = converter.MakeSalsaValue(aftObject[fieldMapping.AftField]); }