public void update_with_reference_data_in_child_is_invalid()
        {
            var oldDto = new GuidParentDto
            {
                ParentKey = Guid.NewGuid(),
                OneToManyReferenceChildDto = new [] { new GuidOneToManyReferenceChildDto
                                                      {
                                                          ChildKey = Guid.NewGuid()
                                                      } }
            };

            var newDto = new GuidParentDto
            {
                ParentKey  = oldDto.ParentKey,
                ParentName = "ParentNameUpdated",
                OneToManyReferenceChildDto = new [] { new GuidOneToManyReferenceChildDto
                                                      {
                                                          ChildKey = oldDto.OneToManyReferenceChildDto[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 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 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 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_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_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 update_of_parent_and_non_fk_columns_in_child_with_special_data_in_child_is_invalid()
        {
            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,
                                                        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_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 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);
        }
        public void insert_with_special_data_in_child_inserts_in_parent_and_link_table()
        {
            var newDto = new GuidParentDto {
                ManyToManySpecialChildDto = new [] { new GuidManyToManySpecialChildDto() }
            };

            insert_inserts_in_parent_and_link(newDto, "ManyToManySpecialChildDto");
        }
Beispiel #11
0
        public void delete_with_special_data_in_child_deletes_from_parent()
        {
            var oldDto = new GuidParentDto
            {
                ManyToOneSpecialChildDto = new GuidManyToOneSpecialChildDto()
            };

            delete_deletes_from_parent(oldDto);
        }
        public void delete_with_no_reference_data_deletes_from_link_table_and_parent()
        {
            var oldDto = new GuidParentDto {
                ParentKey          = Guid.NewGuid(),
                ManyToManyChildDto = new [] { new GuidManyToManyChildDto() }
            };

            delete_deletes_from_link_table_and_parent(oldDto, typeof(GuidManyToManyChildDto));
        }
        public void delete_with_special_data_in_child_deletes_from_link_table_and_parent()
        {
            var oldDto = new GuidParentDto {
                ParentKey = Guid.NewGuid(),
                ManyToManySpecialChildDto = new [] { new GuidManyToManySpecialChildDto() }
            };

            delete_deletes_from_link_table_and_parent(oldDto, typeof(GuidManyToManySpecialChildDto));
        }
        public void insert_with_no_reference_data_inserts_in_parent_and_link_table()
        {
            var newDto = new GuidParentDto
            {
                ManyToManyChildDto = new [] { new GuidManyToManyChildDto() }
            };

            insert_inserts_in_parent_and_link(newDto, "ManyToManyChildDto");
        }
Beispiel #15
0
        public void insert_with_reference_data_in_child_inserts_in_parent()
        {
            var newDto = new GuidParentDto
            {
                ManyToOneReferenceChildDto = new GuidManyToOneReferenceChildDto()
            };

            insert_inserts_in_parent(newDto);
        }
Beispiel #16
0
        public void insert_with_special_data_in_child_inserts_in_parent()
        {
            var newDto = new GuidParentDto
            {
                ManyToOneSpecialChildDto = new GuidManyToOneSpecialChildDto()
            };

            insert_inserts_in_parent(newDto);
        }
Beispiel #17
0
        public void delete_with_no_reference_data_deletes_from_parent()
        {
            var oldDto = new GuidParentDto
            {
                ManyToOneChildDto = new GuidManyToOneChildDto()
            };

            delete_deletes_from_parent(oldDto);
        }
        public void delete_with_fk_on_parent_and_reference_data_in_child_deletes_in_parent_only()
        {
            var oldDto = new GuidParentDto
            {
                OneToOneReferenceChildDtoNoFk = new GuidOneToOneReferenceChildDtoNoFk()
            };

            delete_deletes_from_parent_and_maybe_child(oldDto, typeof(GuidOneToOneReferenceChildDtoNoFk), false);
        }
        public void insert_with_fk_on_parent_no_reference_data_inserts_rows_in_child_and_parent()
        {
            var newDto = new GuidParentDto
            {
                OneToOneChildDtoNoFk = new GuidOneToOneChildDtoNoFk()
            };

            insert_maybe_inserts_in_child_and_always_in_parent(newDto, typeof(GuidOneToOneChildDtoNoFk), true);
        }
        public void delete_with_fk_on_parent_no_reference_data_deletes_rows_in_child_and_parent()
        {
            var oldDto = new GuidParentDto
            {
                OneToOneChildDtoNoFk = new GuidOneToOneChildDtoNoFk()
            };

            delete_deletes_from_parent_and_maybe_child(oldDto, typeof(GuidOneToOneChildDtoNoFk), true);
        }
        public void insert_with_reference_data_in_child_is_invalid()
        {
            var newDto = new GuidParentDto {
                OneToManyReferenceChildDto = new [] { new GuidOneToManyReferenceChildDto() }
            };

            var cache = new DtoMetadataCache();

            GetCommands(cache, null, newDto, 2, 2, 1, 1, 0, 2, 1, 1, 0);
        }
        public void insert_with_fk_on_child_and_reference_data_in_child_is_invalid()
        {
            var newDto = new GuidParentDto()
            {
                OneToOneReferenceChildDtoWithFk = new GuidOneToOneReferenceChildDtoWithFk()
            };

            var cache = new DtoMetadataCache();

            GetCommands(cache, null, newDto, 2, 2, 2, 0, 0, 2, 2, 0, 0);
        }
        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");
        }
        public void delete_with_reference_data_in_child_is_invalid()
        {
            var oldDto = new GuidParentDto
            {
                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);
        }
        public void delete_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 cache = new DtoMetadataCache();

            GetCommands(cache, oldDto, null, 2, 2, 0, 0, 2, 2, 0, 0, 2);
        }
        public void update_with_fk_on_parent_and_reference_data_in_child_updates_in_parent_only()
        {
            var oldDto = new GuidParentDto
            {
                ParentKey = Guid.NewGuid(),
                OneToOneReferenceChildDtoNoFk = new GuidOneToOneReferenceChildDtoNoFk()
            };

            var newDto = new GuidParentDto
            {
                ParentKey  = oldDto.ParentKey,
                ParentName = "I will fight you",
                OneToOneReferenceChildDtoNoFk = new GuidOneToOneReferenceChildDtoNoFk()
            };

            update_updates_in_parent_and_maybe_child(oldDto, newDto, typeof(GuidOneToOneChildDtoNoFk), 1, false);
        }
        public void update_parent_with_special_data_in_child_updates_parent()
        {
            var oldDto = new GuidParentDto {
                ParentKey = Guid.NewGuid(),
                ManyToManySpecialChildDto = new [] { new GuidManyToManySpecialChildDto() }
            };

            var newDto = new GuidParentDto {
                ParentKey  = oldDto.ParentKey,
                ParentName = "Wibble",
                ManyToManySpecialChildDto = new [] { new GuidManyToManySpecialChildDto
                                                     {
                                                         ChildKey = oldDto.ManyToManySpecialChildDto[0].ChildKey
                                                     } }
            };

            update_updates_parent_only(oldDto, newDto);
        }
        public void update_with_no_reference_data_updates_child_and_parent()
        {
            var oldDto = new GuidParentDto {
                ParentKey          = Guid.NewGuid(),
                ManyToManyChildDto = new [] { new GuidManyToManyChildDto() }
            };

            var newDto = new GuidParentDto {
                ParentKey          = oldDto.ParentKey,
                ParentName         = "Wibble",
                ManyToManyChildDto = new [] { new GuidManyToManyChildDto
                                              {
                                                  ChildKey = oldDto.ManyToManyChildDto[0].ChildKey,
                                                  Name     = "Wobble"
                                              } }
            };

            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);

            var command = list[0] as UpdateCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(GuidManyToManyChildDto)).TableName,
                command.TableName,
                "Unexpected table name.");

            Assert.AreEqual(
                "Name",
                command.Operations.FirstOrDefault().OwnerPropertyMetadata.ColumnName,
                "Unexpected column name.");

            command = list[1] as UpdateCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(GuidParentDto)).TableName,
                command.TableName,
                "Unexpected table name.");

            Assert.AreEqual(
                "ParentName",
                command.Operations.FirstOrDefault().OwnerPropertyMetadata.ColumnName);
        }
        public void update_parent_and_non_fk_column_in_child_with_special_data_in_child_is_invalid()
        {
            var oldDto = new GuidParentDto {
                ParentKey = Guid.NewGuid(),
                ManyToManySpecialChildDto = new [] { new GuidManyToManySpecialChildDto() }
            };

            var newDto = new GuidParentDto {
                ParentKey  = oldDto.ParentKey,
                ParentName = "Wibble",
                ManyToManySpecialChildDto = new [] { new GuidManyToManySpecialChildDto {
                                                         ChildKey = oldDto.ManyToManySpecialChildDto[0].ChildKey,
                                                         Name     = "Wobble"
                                                     } }
            };

            var cache = new DtoMetadataCache();

            GetCommands(cache, oldDto, newDto, 2, 2, 0, 2, 0, 1, 0, 1, 0, false);
        }
        public void update_with_fk_on_parent_no_reference_data_updates_rows_in_child_and_parent()
        {
            var oldDto = new GuidParentDto
            {
                ParentKey            = Guid.NewGuid(),
                OneToOneChildDtoNoFk = new GuidOneToOneChildDtoNoFk()
            };

            var newDto = new GuidParentDto
            {
                ParentKey            = oldDto.ParentKey,
                ParentName           = "I will fight you",
                OneToOneChildDtoNoFk = new GuidOneToOneChildDtoNoFk
                {
                    Name = "On the beaches"
                }
            };

            update_updates_in_parent_and_maybe_child(oldDto, newDto, typeof(GuidOneToOneChildDtoNoFk), 2, true);
        }