public void soft_delete_only_updates_parent_type() { var dto = new ParentDto { ParentKey = 1, OneToManyChildDto = new[] { new OneToManyChildDto { ChildKey = 2 } } }; var cache = new DtoMetadataCache(); var builder = new TransactionBuilder(cache); var scripts = builder.BuildUpdateScripts(dto, null, true); Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts."); var script = scripts[0]; var sql = script.Buffer.ToString(); Assert.IsTrue(sql.Contains("UPDATE dbo.[Parent]"), "No update on parent."); Assert.AreEqual(1, Regex.Matches(sql, "UPDATE").Count, "Unexpected number of UPDATEs."); Assert.AreEqual(0, Regex.Matches(sql, "INSERT").Count, "Should be no INSERTs."); Assert.AreEqual(0, Regex.Matches(sql, "DELETE").Count, "Should be no DELETEs."); Assert.AreEqual(0, Regex.Matches(sql, "SELECT").Count, "Should be no SELECTs."); }
public void update_with_special_data_in_parent_is_invalid() { var oldDto = new GuidParentSpecialDto { ParentKey = Guid.NewGuid(), OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = Guid.NewGuid() } } }; var newDto = new GuidParentSpecialDto { ParentKey = oldDto.ParentKey, ParentName = "ParentNameUpdated", OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = oldDto.OneToManyChildDto[0].ChildKey, Name = "Maximum Whoopee! Enabled" } } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, newDto, 2, 2, 0, 2, 0, 2, 0, 2, 0, false); }
public TypePropertyMap( DtoMetadataCache cache, IEnumerable <Type> types) { var typeSet = new HashSet <Type>(); foreach (var type in types.Where(type => !typeSet.Contains(type))) { typeSet.Add(type); } int index = 0; foreach (var type in types) { _entries.Add(new TypePropertyMapEntry( cache, type, AliasGenerator.GenerateAliasFor(type, index), index, typeSet, types)); ++index; } }
public void update_of_parent_and_non_fk_columns_in_child_with_special_data_in_child_is_invalid() { var oldDto = new ParentDto { ParentKey = 1, OneToManySpecialChildDto = new [] { new OneToManySpecialChildDto { ChildKey = 2 } } }; var newDto = new ParentDto { ParentKey = 1, ParentName = "ParentNameUpdated", OneToManySpecialChildDto = new [] { new OneToManySpecialChildDto { ChildKey = 2, Name = "Maximum Whoopee! Enabled" } } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, newDto, 2, 2, 0, 2, 0, 2, 0, 2, 0, false); }
public void insert_with_no_reference_data_inserts_in_parent_and_child() { var newDto = new GuidParentDto { OneToManyChildDto = new [] { new GuidOneToManyChildDto() } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0); var list = new List<BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected number of commands."); var command = list[0] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected table name for parent."); command = list[1] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManyChildDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected table name for child."); }
public void insert_with_no_reference_data_inserts_in_parent_and_child() { var newDto = new GuidParentDto { OneToManyChildDto = new [] { new GuidOneToManyChildDto() } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0); var list = new List <BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected number of commands."); var command = list[0] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected table name for parent."); command = list[1] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManyChildDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected table name for child."); }
public void insert_with_fk_on_child_no_reference_data_inserts_rows_in_parent_and_child() { var newDto = new GuidParentDto() { OneToOneChildDtoWithFk = new GuidOneToOneChildDtoWithFk() }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0); var list = new List <BaseCommand>(commands); var parentInsert = list [0] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, parentInsert.Operation.ValueMetadata.TableName, "Unexpected parent table name."); var childInsert = list [1] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToOneChildDtoWithFk)).TableName, childInsert.Operation.ValueMetadata.TableName, "Unexpected child table name."); }
public void delete_with_no_reference_data_deletes_in_child_and_parent() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = Guid.NewGuid() } } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2); var list = new List <BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected number of commands."); var command = list[0] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManyChildDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected child table name."); command = list[1] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected parent table name."); }
private void update_updates_in_parent_and_maybe_child <T>( T oldDto, T newDto, Type childDtoType, int expectedDifferenceCount, bool updatesChildDto, bool assertOnCounts = true) { var counts = updatesChildDto ? 2 : 1; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, newDto, expectedDifferenceCount, counts, 0, counts, 0, counts, 0, counts, 0, assertOnCounts); var list = new List <BaseCommand>(commands); if (updatesChildDto) { var childUpdate = list [0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(childDtoType).TableName, childUpdate.Operations.FirstOrDefault().OwnerMetadata.TableName, "Unexpected child table name."); } var parentUpdate = list [counts - 1] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(T)).TableName, parentUpdate.Operations.FirstOrDefault().OwnerMetadata.TableName, "Unexpected parent table name."); }
public void update_with_reference_data_in_parent_and_child_is_invalid() { var oldDto = new ParentReferenceDto { ParentKey = 1, OneToManyReferenceChildDto = new [] { new OneToManyReferenceChildDto { ChildKey = 2 } } }; var newDto = new ParentReferenceDto { ParentKey = 1, ParentName = "ParentNameUpdated", OneToManyReferenceChildDto = new [] { new OneToManyReferenceChildDto { ChildKey = 2, Name = "Maximum Whoopee! Enabled" } } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, newDto, 2, 2, 0, 2, 0, 2, 0, 2, 0, false); }
public void update_with_special_data_in_child_updates_parent() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto { ChildKey = Guid.NewGuid() } } }; var newDto = new GuidParentDto { ParentKey = oldDto.ParentKey, ParentName = "ParentNameUpdated", OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto { ChildKey = oldDto.OneToManySpecialChildDto[0].ChildKey } } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, newDto, 1, 1, 0, 1, 0, 1, 0, 1, 0); var list = new List <BaseCommand>(commands); var command = list[0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operations.FirstOrDefault().TableName); Assert.AreEqual( 1, command.Operations.Count(), "Unexpected number of operations."); }
public void insert_with_fk_on_child_and_special_data_in_child_inserts_in_parent_and_updates_child() { var newDto = new GuidParentDto() { OneToOneSpecialChildDtoWithFk = new GuidOneToOneSpecialChildDtoWithFk() }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, null, newDto, 2, 2, 1, 1, 0, 2, 1, 1, 0); var list = new List <BaseCommand>(commands); var parentInsert = list [0] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, parentInsert.Operation.ValueMetadata.TableName, "Unexpected parent table name."); var childUpdate = list [1] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToOneSpecialChildDtoWithFk)).TableName, childUpdate.Operations.FirstOrDefault().ValueMetadata.TableName, "Unexpected child table name."); }
public void update_both_with_fk_on_child_and_reference_data_in_child_is_invalid() { var parentKey = Guid.NewGuid(); var oldDto = new GuidParentDto() { ParentKey = parentKey, OneToOneReferenceChildDtoWithFk = new GuidOneToOneReferenceChildDtoWithFk { ParentKey = parentKey } }; var newDto = new GuidParentDto() { ParentKey = parentKey, ParentName = "Breaking", OneToOneReferenceChildDtoWithFk = new GuidOneToOneReferenceChildDtoWithFk { ParentKey = parentKey, Name = "Bad" } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, newDto, 2, 2, 0, 2, 0, 2, 0, 2, 0, false); }
private void delete_deletes_from_parent_and_maybe_child <T>( T oldDto, Type childDtoType, bool deletesFromChild) { var counts = deletesFromChild ? 2 : 1; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, default(T), 2, counts, 0, 0, counts, counts, 0, 0, counts); var list = new List <BaseCommand>(commands); var parentDelete = list [0] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(T)).TableName, parentDelete.Operation.ValueMetadata.TableName, "Unexpected parent table name."); if (deletesFromChild) { var childDelete = list [1] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(childDtoType).TableName, childDelete.Operation.ValueMetadata.TableName, "Unexpected child table name."); } }
public void delete_with_special_data_in_child_updates_child_and_deletes_parent() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto { ChildKey = Guid.NewGuid() } } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, null, 2, 2, 0, 1, 1, 2, 0, 1, 1); var list = new List <BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected command count."); var update = list[0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManySpecialChildDto)).TableName, update.Operations.FirstOrDefault().ValueMetadata.TableName, "Unexpected child table name."); var delete = list[1] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, delete.Operation.ValueMetadata.TableName); }
protected IEnumerable <BaseCommand> GetCommands <T>( DtoMetadataCache cache, T oldDto, T newDto, int expectedDifferenceCount, int expectedOperationCount, int expectedInsertOperations, int expectedUpdateOperations, int expectedDeleteOperations, int expectedCommandCount, int expectedInsertCommands, int expectedUpdateCommands, int expectedDeleteCommands, bool assertOnCounts = true) { var differ = new Differ(cache); var differences = differ.Diff(oldDto, newDto); if (assertOnCounts) { Assert.AreEqual(expectedDifferenceCount, differences.Count(), "Unexpected number of differences."); } var operationBuilder = new OperationBuilder(); var operations = operationBuilder.Build(differences); var commandBuilder = new CommandBuilder(); var commands = commandBuilder.Coalesce(operations); if (assertOnCounts) { Assert.AreEqual(expectedOperationCount, operations.Count(), "Unexpected number of operations."); var counts = CountItemsByType(operations); CheckCount(counts, typeof(InsertOperation), expectedInsertOperations); CheckCount(counts, typeof(UpdateOperation), expectedUpdateOperations); CheckCount(counts, typeof(DeleteOperation), expectedDeleteOperations); Assert.AreEqual(expectedCommandCount, commands.Count(), "Unexpected number of commands."); counts = CountItemsByType(commands); CheckCount(counts, typeof(InsertCommand), expectedInsertCommands); CheckCount(counts, typeof(UpdateCommand), expectedUpdateCommands); CheckCount(counts, typeof(DeleteCommand), expectedDeleteCommands); } var scriptBuilder = new ScriptBuilder(cache); var transactionScript = scriptBuilder.Build(commands); Assert.IsNotNull(transactionScript, "#badtimes - null transaction script"); Assert.IsTrue(transactionScript.Count > 0, "Should be at least one script."); foreach (var script in transactionScript) { Assert.IsTrue(script.Buffer.Length > 0, "#badtimes - empty transaction script"); } CheckNoReferenceTypesInParameters(transactionScript); return(commands); }
public void insert_with_reference_data_in_parent_and_child_is_invalid() { var newDto = new GuidParentReferenceDto { OneToManyReferenceChildDto = new [] { new GuidOneToManyReferenceChildDto() } }; var cache = new DtoMetadataCache(); GetCommands(cache, null, newDto, 2, 2, 1, 1, 0, 2, 1, 1, 0, false); }
public void insert_with_special_data_in_parent_and_reference_data_in_child_is_invalid() { var newDto = new GuidParentSpecialDto() { ManyToManyReferenceChildDto = new [] { new GuidManyToManyReferenceChildDto() } }; var cache = new DtoMetadataCache(); GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0, false); }
public void insert_with_reference_data_in_parent_is_invalid() { var newDto = new ParentReferenceDto() { ManyToManyChildDto = new [] { new ManyToManyChildDto() } }; var cache = new DtoMetadataCache(); GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0, false); }
public void insert_with_fk_on_child_and_reference_data_in_child_is_invalid() { var newDto = new ParentDto() { OneToOneReferenceChildDtoWithFk = new OneToOneReferenceChildDtoWithFk() }; var cache = new DtoMetadataCache(); GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0); }
public void insert_with_fk_on_child_and_reference_data_in_both_parent_and_child_is_invalid() { var newDto = new GuidParentReferenceDto { OneToOneReferenceChildDtoWithFk = new GuidOneToOneReferenceChildDtoWithFk() }; var cache = new DtoMetadataCache(); GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0, false); }
public void insert_with_special_data_in_parent_is_invalid() { var newDto = new GuidParentSpecialDto { OneToManyChildDto = new [] { new GuidOneToManyChildDto() } }; var cache = new DtoMetadataCache(); GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0, false); }
private void delete_deletes_from_parent <T>(T oldDto, bool assertOnCounts = true) { var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, default(T), 2, 1, 0, 0, 1, 1, 0, 0, 1, assertOnCounts); var list = new List <BaseCommand>(commands); var command = list[0] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(T)).TableName, command.Operation.ValueMetadata.TableName); }
private void insert_inserts_in_parent_and_link(GuidParentDto newDto, string manyToManyPropertyName) { var cache = new DtoMetadataCache(); var commands = GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0); var list = new List <BaseCommand>(commands); var command = list [0] as InsertCommand; Assert.AreEqual(cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected table name"); command = list [1] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).WriteableProperties.Where(p => p.ColumnName == manyToManyPropertyName).FirstOrDefault().GetAttribute <ManyToManyAttribute>().SchemaQualifiedLinkTableName, command.Operation.OwnerPropertyMetadata.GetAttribute <ManyToManyAttribute>().SchemaQualifiedLinkTableName, "Unexpected table name"); }
private void insert_inserts_in_parent <T>(T parentDto, bool assertOnCounts = true) { var cache = new DtoMetadataCache(); var commands = GetCommands(cache, default(T), parentDto, 2, 1, 1, 0, 0, 1, 1, 0, 0, assertOnCounts); var list = new List <BaseCommand>(commands); var command = list[0] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(T)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected parent table name."); }
protected IList <IScript> Generate <T>(T oldDto, T newDto, int expectedScriptCount) { var cache = new DtoMetadataCache(); var builder = new TransactionBuilder(cache); var scripts = builder.BuildUpdateScripts(oldDto, newDto); Assert.AreEqual( expectedScriptCount, scripts.Count, "Unexpected number of scripts."); return(scripts); }
private void update_on_mostly_readonly_child_updates_parent <T>(T oldDto, T newDto, bool assertOnCounts = true) { var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, newDto, 1, 1, 0, 1, 0, 1, 0, 1, 0, assertOnCounts); var list = new List <BaseCommand>(commands); var command = list [0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operations.FirstOrDefault().OwnerMetadata.TableName, "Unexpected parent table name."); }
public void delete_with_reference_data_in_parent_and_child_is_invalid() { var oldDto = new GuidParentReferenceDto { ParentKey = Guid.NewGuid(), OneToManyReferenceChildDto = new [] { new GuidOneToManyReferenceChildDto { ChildKey = Guid.NewGuid() } } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2, false); }
public void delete_with_special_data_in_parent_is_invalid() { var oldDto = new GuidParentSpecialDto { ParentKey = Guid.NewGuid(), OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = Guid.NewGuid() } } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2, false); }
public void delete_with_reference_data_in_parent_is_invalid() { var oldDto = new ParentReferenceDto { ParentKey = 1, OneToManyChildDto = new [] { new OneToManyChildDto { ChildKey = 1 } } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2, false); }
public void delete_with_fk_on_child_and_reference_data_in_both_parent_and_child_is_invalid() { var oldDto = new ParentReferenceDto { ParentKey = 43432, OneToOneReferenceChildDtoWithFk = new OneToOneReferenceChildDtoWithFk { ParentKey = 43432 } }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2, false); }
public TypePropertyMap( DtoMetadataCache cache, IEnumerable<Type> types) { var typeSet = new HashSet<Type>(); foreach (var type in types.Where(type => !typeSet.Contains(type))) { typeSet.Add(type); } int index = 0; foreach (var type in types) { _entries.Add(new TypePropertyMapEntry( cache, type, AliasGenerator.GenerateAliasFor(type, index), index, typeSet)); ++index; } }
public void update_with_no_reference_data_updates_in_parent_and_child() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = Guid.NewGuid() } } }; var newDto = new GuidParentDto { ParentKey = oldDto.ParentKey, ParentName = "ParentNameUpdated", OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = oldDto.OneToManyChildDto[0].ChildKey, Name = "Maximum Whoopee! Enabled" } } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, newDto, 2, 2, 0, 2, 0, 2, 0, 2, 0); var list = new List<BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected number of commands."); var command = list[0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManyChildDto)).TableName, command.TableName, "Unexpected child table name."); Assert.AreEqual( "ChildKey", command.PrimaryKeyColumn, "Unexpected child primary key column."); Assert.AreEqual( 1, command.Operations.Count(), "Unexpected number of update operations on child table."); Assert.AreEqual( "Name", command.Operations.FirstOrDefault().OwnerPropertyMetadata.ColumnName, "Unexpected column for child table UPDATE."); Assert.AreEqual( newDto.OneToManyChildDto[0].Name, command.Operations.FirstOrDefault().Value, "Unexpected child column value."); command = list[1] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.TableName, "Unexpected parent table name."); Assert.AreEqual( "ParentKey", command.PrimaryKeyColumn, "Unexpected parent primary key column."); Assert.AreEqual( 1, command.Operations.Count(), "Unexpected number of update operations on child table."); Assert.AreEqual( "ParentName", command.Operations.FirstOrDefault().OwnerPropertyMetadata.ColumnName, "Unexpected column for parent table UPDATE."); Assert.AreEqual( newDto.ParentName, command.Operations.FirstOrDefault().Value, "Unexpected parent column value."); }
public void delete_with_reference_data_in_parent_and_child_is_invalid() { var oldDto = new GuidParentReferenceDto { ParentKey = Guid.NewGuid(), OneToManyReferenceChildDto = new [] { new GuidOneToManyReferenceChildDto { ChildKey = Guid.NewGuid() }} }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2, false); }
public void delete_with_special_data_in_child_updates_child_and_deletes_parent() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto { ChildKey = Guid.NewGuid() } } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, null, 2, 2, 0, 1, 1, 2, 0, 1, 1); var list = new List<BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected command count."); var update = list[0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManySpecialChildDto)).TableName, update.Operations.FirstOrDefault().ValueMetadata.TableName, "Unexpected child table name."); var delete = list[1] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, delete.Operation.ValueMetadata.TableName); }
public void insert_with_special_data_in_child_inserts_in_parent_and_updates_child() { var newDto = new GuidParentDto { OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto() } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, null, newDto, 2, 2, 1, 1, 0, 2, 1, 1, 0); var list = new List<BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected number of commands."); var insert = list[0] as InsertCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, insert.Operation.ValueMetadata.TableName, "Unexpected table name for parent."); var update = list[1] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManySpecialChildDto)).TableName, update.Operations.FirstOrDefault().ValueMetadata.TableName, "Unexpected table owner name for child update."); Assert.AreEqual( "OneToManySpecialChildDto", update.Operations.FirstOrDefault().ColumnName, "Unexpected owner's column name for child update."); Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManySpecialChildDto)).TableName, update.Operations.FirstOrDefault().ValueMetadata.TableName, "Unexected child table name."); }
public void update_with_special_data_in_child_updates_parent() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto { ChildKey = Guid.NewGuid() } } }; var newDto = new GuidParentDto { ParentKey = oldDto.ParentKey, ParentName = "ParentNameUpdated", OneToManySpecialChildDto = new [] { new GuidOneToManySpecialChildDto { ChildKey = oldDto.OneToManySpecialChildDto[0].ChildKey } } }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, newDto, 1, 1, 0, 1, 0, 1, 0, 1, 0); var list = new List<BaseCommand>(commands); var command = list[0] as UpdateCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operations.FirstOrDefault().TableName); Assert.AreEqual( 1, command.Operations.Count(), "Unexpected number of operations."); }
public void delete_with_no_reference_data_deletes_in_child_and_parent() { var oldDto = new GuidParentDto { ParentKey = Guid.NewGuid(), OneToManyChildDto = new [] { new GuidOneToManyChildDto { ChildKey = Guid.NewGuid() }} }; var cache = new DtoMetadataCache(); var commands = GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2); var list = new List<BaseCommand>(commands); Assert.AreEqual( 2, list.Count, "Unexpected number of commands."); var command = list[0] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidOneToManyChildDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected child table name."); command = list[1] as DeleteCommand; Assert.AreEqual( cache.GetMetadataFor(typeof(GuidParentDto)).TableName, command.Operation.ValueMetadata.TableName, "Unexpected parent table name."); }
public ExplicitTransitiveBackReferenceResolver(DtoMetadataCache cache) { _cache = cache; }
public void delete_with_reference_data_in_parent_is_invalid() { var oldDto = new ParentReferenceDto { ParentKey = 1, OneToManyChildDto = new [] { new OneToManyChildDto { ChildKey = 1 }} }; var cache = new DtoMetadataCache(); GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2, false); }
public ScriptBuilder(DtoMetadataCache dtoMetadataCache) { _dtoMetadataCache = dtoMetadataCache; }