public IEnumerator <DuplicateGroup> GetEnumerator()
        {
            XDocument xdoc = _fileOps.LoadXml(_config.DuplicateFilePath);

            // Get all the duplicate groups
            IEnumerable <XElement> xmlGroups = xdoc.Descendants("G");

            // Convert each group to a model
            foreach (XElement xmlGroup in xmlGroups)
            {
                DuplicateGroup   duplicateGroup = new DuplicateGroup();
                List <GroupFile> groupFiles     = new List <GroupFile>();

                IEnumerable <XElement> xmlImages = xmlGroup.Descendants("Image");
                foreach (XElement xmlImage in xmlImages)
                {
                    GroupFile groupFile = new GroupFile()
                    {
                        Checked  = xmlImage.Attribute("Checked").Value != "0",
                        FullName = xmlImage.Attribute("FileName").Value
                    };

                    groupFiles.Add(groupFile);
                }

                duplicateGroup.Files = groupFiles;
                yield return(duplicateGroup);
            }
        }
Ejemplo n.º 2
0
        public void GetEnumeratorGetsCorrectNumberOfGroups()
        {
            // Arrange
            XDocument xdoc = new XDocument(
                new XElement("root",
                             this.ArrangeGroup(),
                             this.ArrangeGroup(),
                             this.ArrangeGroup()));

            IFileOperationsAbstraction fileOps = Substitute.For <IFileOperationsAbstraction>();

            fileOps.LoadXml(Arg.Any <string>()).Returns(xdoc);

            XmlDuplicateReader uut = this.XmlDuplicateReaderWithDefaultMocks(
                fileOps: fileOps);

            // Act & Assert
            Assert.Equal(3, uut.Count());
        }
Ejemplo n.º 3
0
        public void GetEnumeratorGetsCorrectFilesInGroup()
        {
            // Arrange
            XDocument xdoc = new XDocument(
                new XElement("root",
                             this.ArrangeGroup(
                                 this.ArrangeFile(true, "file1"),
                                 this.ArrangeFile(false, "file2"))));

            IFileOperationsAbstraction fileOps = Substitute.For <IFileOperationsAbstraction>();

            fileOps.LoadXml(Arg.Any <string>()).Returns(xdoc);

            XmlDuplicateReader uut = this.XmlDuplicateReaderWithDefaultMocks(
                fileOps: fileOps);

            // Act & Assert
            DuplicateGroup group = Assert.Single(uut);

            Assert.Equal(2, group.Files.Count());
            GroupFile file1 = Assert.Single(group.Files, f => f.FullName == "file1" && f.Checked == true);
            GroupFile file2 = Assert.Single(group.Files, f => f.FullName == "file2" && f.Checked == false);
        }
Ejemplo n.º 4
0
        public void CallingFilesPropertyAlwaysReturnsSameInstance()
        {
            // Arrange
            XDocument xdoc = new XDocument(
                new XElement("root",
                             this.ArrangeGroup(
                                 this.ArrangeFile(false, "file1"))));

            IFileOperationsAbstraction fileOps = Substitute.For <IFileOperationsAbstraction>();

            fileOps.LoadXml(Arg.Any <string>()).Returns(xdoc);

            XmlDuplicateReader uut = this.XmlDuplicateReaderWithDefaultMocks(
                fileOps: fileOps);

            // Act
            DuplicateGroup          group        = uut.Single();
            IEnumerable <GroupFile> intersection = group.Files.Intersect(group.Files);
            IEnumerable <GroupFile> except       = group.Files.Except(group.Files);

            // Assert
            Assert.Single(intersection);
            Assert.Empty(except);
        }