示例#1
0
        public void delete_with_special_data_in_child_updates_child_and_deletes_parent()
        {
            var oldDto = new ParentDto
            {
                ParentKey = 532,
                OneToManySpecialChildDto = new [] { new OneToManySpecialChildDto {
                                                        ChildKey = 1
                                                    } }
            };

            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(OneToManySpecialChildDto)).TableName,
                update.Operations.FirstOrDefault().ValueMetadata.TableName,
                "Unexpected child table name.");

            var delete = list[1] as DeleteCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(ParentDto)).TableName,
                delete.Operation.ValueMetadata.TableName);
        }
示例#2
0
        public void insert_with_fk_on_child_and_special_data_in_child_inserts_in_parent_and_updates_child()
        {
            var newDto = new ParentDto()
            {
                OneToOneSpecialChildDtoWithFk = new OneToOneSpecialChildDtoWithFk()
            };

            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(ParentDto)).TableName,
                parentInsert.Operation.ValueMetadata.TableName,
                "Unexpected parent table name.");

            var childUpdate = list [1] as UpdateCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(OneToOneSpecialChildDtoWithFk)).TableName,
                childUpdate.Operations.FirstOrDefault().ValueMetadata.TableName,
                "Unexpected child table name.");
        }
示例#3
0
        public void update_with_special_data_in_child_updates_parent()
        {
            var oldDto = new ParentDto
            {
                ParentKey = 1,
                OneToManySpecialChildDto = new [] { new OneToManySpecialChildDto {
                                                        ChildKey = 1
                                                    } }
            };

            var newDto = new ParentDto
            {
                ParentKey  = 1,
                ParentName = "ParentNameUpdated",
                OneToManySpecialChildDto = new [] { new OneToManySpecialChildDto {
                                                        ChildKey = 1
                                                    } }
            };

            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(ParentDto)).TableName,
                command.Operations.FirstOrDefault().TableName);

            Assert.AreEqual(
                1,
                command.Operations.Count(),
                "Unexpected number of operations.");
        }
示例#4
0
        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 ParentDto GetByUserName(string username)
        {
            ApplicationUser user      = db.AuthRepository.FindUserByUsername(username);
            ParentDto       parentDto = new ParentDto();

            //foreach (var role in user.Roles)
            //{
            //    string name = role.RoleId;
            //    string RoleName = user.Roles.First(r => r.Id == role.RoleId).Name;
            //}
            //string rolee = parent.Roles.(x => x.RoleId).ToString();
            //var roleStore = new RoleStore<IdentityRole>(db.ParentsRepository);
            //var roleMngr = new RoleManager<IdentityRole>(roleStore);

            //var roles = roleMngr.Roles.ToList();
            //if (user != null)
            //{
            //    if (user.Roles.FirstOrDefault(x => x.RoleId == role) != null)
            //    {
            //        parentDto.Username = user.UserName;
            //        parentDto.Surname = user.LastName;
            //        parentDto.Name = user.FirstName;
            //        parentDto.Email = user.Email;
            //        return parentDto;
            //    }
            //}
            return(null);
        }
示例#6
0
        public void update_with_reference_data_in_child_is_invalid()
        {
            var oldDto = new ParentDto
            {
                ParentKey = 1,
                OneToManyReferenceChildDto = new [] { new OneToManyReferenceChildDto
                                                      {
                                                          ChildKey = 2
                                                      } }
            };

            var newDto = new ParentDto
            {
                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);
        }
示例#7
0
        public void insert_with_no_reference_data_inserts_in_parent_and_child()
        {
            var newDto = new ParentDto {
                OneToManyChildDto = new [] { new OneToManyChildDto() }
            };

            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(ParentDto)).TableName,
                command.Operation.ValueMetadata.TableName,
                "Unexpected table name for parent.");

            command = list[1] as InsertCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(OneToManyChildDto)).TableName,
                command.Operation.ValueMetadata.TableName,
                "Unexpected table name for child.");
        }
示例#8
0
        public void delete_with_no_reference_data_deletes_in_child_and_parent()
        {
            var oldDto = new ParentDto
            {
                ParentKey         = 1,
                OneToManyChildDto = new [] { new OneToManyChildDto {
                                                 ChildKey = 1
                                             } }
            };

            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(OneToManyChildDto)).TableName,
                command.Operation.ValueMetadata.TableName,
                "Unexpected child table name.");

            command = list[1] as DeleteCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(ParentDto)).TableName,
                command.Operation.ValueMetadata.TableName,
                "Unexpected parent table name.");
        }
示例#9
0
        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 insert_existing_reference_data_child_with_fk_on_parent_inserts_parent_and_not_child()
        {
            var logger = CreateMockLogger();

            var newDto = new ParentDto
            {
                OneToOneReferenceChildDtoNoFk = new OneToOneReferenceChildDtoNoFk
                {
                    ChildKey = 100,
                    Name     = "You, sir, are drunk!"
                }
            };

            try
            {
                using (var connection = new SqlConnection())
                {
                    connection.Create(newDto);
                }
            }
            catch (InvalidOperationException)
            {
                // Do nothing because we deliberately didn't open the connection
            }

            var scripts = logger.Scripts;

            Assert.AreEqual(1, scripts.Count, "Unexpected number of scripts.");

            var sql = scripts[0].Buffer.ToString();

            Assert.IsTrue(sql.Contains("INSERT INTO dbo.[Parent]"), "No INSERT on parent.");
            Assert.IsTrue(!sql.Contains("INSERT INTO dbo.OneToOneReferenceChildNoFk"), "Should be no INSERT on child.");
        }
示例#11
0
        public void insert_with_fk_on_child_no_reference_data_inserts_rows_in_parent_and_child()
        {
            var newDto = new ParentDto()
            {
                OneToOneChildDtoWithFk = new OneToOneChildDtoWithFk()
            };

            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(ParentDto)).TableName,
                parentInsert.Operation.ValueMetadata.TableName,
                "Unexpected parent table name.");

            var childInsert = list [1] as InsertCommand;

            Assert.AreEqual(
                cache.GetMetadataFor(typeof(OneToOneChildDtoWithFk)).TableName,
                childInsert.Operation.ValueMetadata.TableName,
                "Unexpected child table name.");
        }
        public StudentDto StudentToStudentDto(Student student)
        {
            StudentDto user      = db.StudentsRepository.StudentToStudentDto(student);
            ParentDto  parentDto = new ParentDto();

            if (user == null)
            {
                return(null);
            }
            /*komentar*/
            //if (student.Parents.Count() > 0)
            //{
            //    foreach (var parent in student.Parents)
            //    {
            //        parentDto = db.ParentsRepository.ParentToParentDto(parent);
            //        user.Parents.Add(parentDto);
            //    }
            //}
            //if (student.Marks.Count() != 0)
            //{
            //    foreach (var mark in student.Marks)
            //    {
            //        MarkDto markDto = db.MarksRepository.MarkToDto(mark);
            //        user.Marks.Add(markDto);
            //    }
            //}
            //user.Class = db.ClassesRepository.ClassToDto(student.Class);
            /*komentar*/
            return(user);
        }
示例#13
0
        public void update_both_with_fk_on_child_and_reference_data_in_child_is_invalid()
        {
            var oldDto = new ParentDto()
            {
                ParentKey = 943982,
                OneToOneReferenceChildDtoWithFk = new OneToOneReferenceChildDtoWithFk
                {
                    ParentKey = 943982
                }
            };

            var newDto = new ParentDto()
            {
                ParentKey  = 943982,
                ParentName = "Breaking",
                OneToOneReferenceChildDtoWithFk = new OneToOneReferenceChildDtoWithFk
                {
                    ParentKey = 943982,
                    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 ParentDto {
                ManyToManySpecialChildDto = new [] { new ManyToManySpecialChildDto() }
            };

            insert_inserts_in_parent_and_link(newDto, "ManyToManySpecialChildDto");
        }
        public void delete_with_no_reference_data_deletes_from_link_table_and_parent()
        {
            var oldDto = new ParentDto {
                ParentKey          = 1,
                ManyToManyChildDto = new [] { new ManyToManyChildDto() }
            };

            delete_deletes_from_link_table_and_parent(oldDto, typeof(ManyToManyChildDto));
        }
        public void insert_with_fk_on_parent_no_reference_data_inserts_rows_in_child_and_parent()
        {
            var newDto = new ParentDto
            {
                OneToOneChildDtoNoFk = new OneToOneChildDtoNoFk()
            };

            insert_maybe_inserts_in_child_and_always_in_parent(newDto, typeof(OneToOneChildDtoNoFk), true);
        }
        public void delete_with_fk_on_parent_and_reference_data_in_child_deletes_in_parent_only()
        {
            var oldDto = new ParentDto
            {
                OneToOneReferenceChildDtoNoFk = new OneToOneReferenceChildDtoNoFk()
            };

            delete_deletes_from_parent_and_maybe_child(oldDto, typeof(OneToOneReferenceChildDtoNoFk), false);
        }
        public void delete_with_no_reference_data_deletes_from_parent()
        {
            var oldDto = new ParentDto
            {
                ManyToOneChildDto = new ManyToOneChildDto()
            };

            delete_deletes_from_parent(oldDto);
        }
        public void insert_with_reference_data_in_child_inserts_in_parent()
        {
            var newDto = new ParentDto
            {
                ManyToOneReferenceChildDto = new ManyToOneReferenceChildDto()
            };

            insert_inserts_in_parent(newDto);
        }
        public void delete_with_special_data_in_child_deletes_from_parent()
        {
            var oldDto = new ParentDto
            {
                ManyToOneSpecialChildDto = new ManyToOneSpecialChildDto()
            };

            delete_deletes_from_parent(oldDto);
        }
        public void insert_with_special_data_in_child_inserts_in_parent()
        {
            var newDto = new ParentDto
            {
                ManyToOneSpecialChildDto = new ManyToOneSpecialChildDto()
            };

            insert_inserts_in_parent(newDto);
        }
        public void delete_with_special_data_in_child_deletes_from_link_table_and_parent()
        {
            var oldDto = new ParentDto {
                ParentKey = 1,
                ManyToManySpecialChildDto = new [] { new ManyToManySpecialChildDto() }
            };

            delete_deletes_from_link_table_and_parent(oldDto, typeof(ManyToManySpecialChildDto));
        }
        public void insert_with_fk_on_parent_and_reference_data_in_child_inserts_in_parent_only()
        {
            var newDto = new ParentDto
            {
                OneToOneReferenceChildDtoNoFk = new OneToOneReferenceChildDtoNoFk()
            };

            insert_maybe_inserts_in_child_and_always_in_parent(newDto, typeof(OneToOneReferenceChildDtoNoFk), false);
        }
        public void insert_with_no_reference_data_inserts_in_parent_and_link_table()
        {
            var newDto = new ParentDto
            {
                ManyToManyChildDto = new [] { new ManyToManyChildDto() }
            };

            insert_inserts_in_parent_and_link(newDto, "ManyToManyChildDto");
        }
        public void delete_with_fk_on_parent_no_reference_data_deletes_rows_in_child_and_parent()
        {
            var oldDto = new ParentDto
            {
                OneToOneChildDtoNoFk = new OneToOneChildDtoNoFk()
            };

            delete_deletes_from_parent_and_maybe_child(oldDto, typeof(OneToOneChildDtoNoFk), true);
        }
示例#26
0
        public void insert_with_reference_data_in_child_is_invalid()
        {
            var newDto = new ParentDto {
                OneToManyReferenceChildDto = new [] { new OneToManyReferenceChildDto() }
            };

            var cache = new DtoMetadataCache();

            GetCommands(cache, null, newDto, 2, 2, 1, 1, 0, 2, 1, 1, 0);
        }
示例#27
0
        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 MapOnlyPropertiesThatWereSetOnTheLeftHandSide_WithChildren()
        {
            var mapper = new MapperConfiguration(
                cfg =>
            {
                cfg.OnlyDefinedProperties();
                cfg.CreateMap <ChildModel, ChildDto>();
                cfg.CreateMap <ParentModel, ParentDto>();
            }
                ).CreateMapper();

            var destination = new ParentDto
            {
                Integer         = 1337,
                NullableInteger = 1337,
                Decimal         = 13.37M,
                NullableDecimal = 13.37M,
                String          = "123",
                Child           = new ChildDto
                {
                    Integer         = 1337,
                    NullableInteger = 1337,
                    Decimal         = 13.37M,
                    NullableDecimal = 13.37M,
                    String          = "123"
                }
            };

            mapper.Map(
                new ParentModel
            {
                Decimal         = 2.2M,
                NullableInteger = 123,
                Child           = new ChildModel
                {
                    NullableDecimal = 2.2M,
                    Integer         = 123
                }
            },
                destination
                );

            destination.Integer.Should().Be(1337);
            destination.NullableInteger.Should().Be(123);
            destination.Decimal.Should().Be(2.2M);
            destination.NullableDecimal.Should().Be(13.37M);
            destination.String.Should().Be("123");

            destination.Child.Integer.Should().Be(123);
            destination.Child.NullableInteger.Should().Be(1337);
            destination.Child.Decimal.Should().Be(13.37M);
            destination.Child.NullableDecimal.Should().Be(2.2M);
            destination.Child.String.Should().Be("123");
        }
        public ParentDto GetParent(Guid id)
        {
            Parent    parent      = db.ParentsRepository.GetByID(id.ToString());
            ParentDto user_parent = new ParentDto();

            if (parent != null)
            {
                user_parent = ParentToParentDto(parent);
                return(user_parent);
            }
            return(null);
        }
            protected override void Because_of()
            {
                var parent = new ParentModel {
                    ID = "PARENT_ONE"
                };

                parent.AddChild(new ChildModel {
                    ID = "CHILD_ONE"
                });

                _dto = Mapper.Map <ParentModel, ParentDto>(parent);
            }