public void PerformCleanup()
        {
            var reader = new EventInfoPropertyReader();

            var propFiles = Directory.GetFiles(StautConfiguration.Current.CollectorDirectory, "eventinfo.properties",
                                               SearchOption.AllDirectories);

            foreach (var propFile in propFiles)
            {
                var propDir = Path.GetDirectoryName(propFile);
                if (String.IsNullOrWhiteSpace(propDir))
                {
                    continue;
                }
                var info = reader.ReadProperties(propFile);
                if (info.Start.Date >= DateTime.Today) // Vi rører ikke events før de er over.
                {
                    continue;
                }
                var fileCount = Directory.GetFiles(propDir).Count();
                if (fileCount > 1) // Ligger det flere filer der holder vi avstand.
                {
                    continue;
                }
                var leafDir             = PathUtils.GetLeafDirectoryName(propFile);
                var storagePropFilename = Path.Combine(PathUtils.GetStoragePath(info.Start, leafDir), "eventinfo.properties");
                if (!File.Exists(storagePropFilename)) // Hvis ikke eventinfo-fila er kopiert over holder vi oss unna.
                {
                    continue;
                }
                // Kommer vi hit må vi vel endelig innse at dette directoriet kan slettes
                Directory.Delete(propDir, true);
            }
        }
        public void ReadProperties_WhenGivenNull_ThrowsArgumentException()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            Assert.Throws <ArgumentException>(() => sut.ReadProperties(null));

            // Assert
        }
        public void ReadProperties_WhenGivenEmptyString_ThrowsArgumentException()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            Assert.Throws <ArgumentException>(() => sut.ReadProperties(String.Empty));

            // Assert
        }
        public void ReadProperties_GivenGoodInputFile_ReturnsValidObject()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Should().NotBeNull("valid filename should result in valid object");
        }
        public void ReadProperties_WhenGivenNonExistingFile_ThrowsArgumentException()
        {
            // Arrange
            var          sut         = new EventInfoPropertyReader();
            const string badFilename = @"buh:\nah\d'oh\eventinfo.properties";

            // Act
            Assert.Throws <ArgumentException>(() => sut.ReadProperties(badFilename));

            // Assert
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectGeometryUrl()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.GeometryUrl.Should().Be("http://www.billettservice.no/seatmap/proxy/geometry/syst-25/geometry/TLD12_V07_geometry.xml", "that is the correct url");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectAvailabilityUrl()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.AvailibilityUrl.Should().Be("http://www.billettservice.no/seatmap/proxy/availability/NO/TLD0915-2015,NO-438525.xml", "that is the correct url");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectEventNumber()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.EventNumber.Should()
            .Be(438525, "that is what the eventid field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectDisplayName()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.DisplayName.Should()
            .Be("Rosenborg - Sarpsborg 08", "that is what the eventname field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectOpponent()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Opponent.Should()
            .Be("Sarpsborg", "that is what the opponent field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectTournament()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Tournament.Should()
            .Be("LEAGUE", "that is what the competition field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectLocation()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Location.Should()
            .Be("TLD", "that is what the location field of the file contains");
        }
        public void ReadProperties_GivenGoodInputFile_GetsCorrectStartTime()
        {
            // Arrange
            var sut = new EventInfoPropertyReader();

            // Act
            var res = sut.ReadProperties(@"..\..\TestData\eventinfo.properties");

            // Assert
            res.Start.Year.Should().Be(2015, "that is the correct year");
            res.Start.Month.Should().Be(8, "that is the correct month");
            res.Start.Day.Should().Be(2, "that is the correct day");
            res.Start.Hour.Should().Be(20, "that is the correct hour");
            res.Start.Minute.Should().Be(00, "that is the correct minute");
        }
        public IEnumerable <BillettServiceEvent> FetchEvents(string archivePath)
        {
            if (String.IsNullOrWhiteSpace(archivePath) || !Directory.Exists(archivePath))
            {
                throw new ArgumentException("Dårlig filområde");
            }

            // Loop gjennom archivePath sine subdirectories etter eventinfo.properties-filer
            var reader = new EventInfoPropertyReader();

            _events = Directory.GetFiles(archivePath, "eventinfo.properties", SearchOption.AllDirectories)
                      .ToDictionary(file => Path.GetDirectoryName(file), file => reader.ReadProperties(file));

            return(_events.Values);
        }