public void SetUp()
 {
     _directoryPathValidator = A.Fake <IDirectoryHelper>();
     _notifier                             = A.Fake <INotifier>();
     _pathHelper                           = A.Fake <IPathHelper>();
     _directoryMonitor                     = A.Fake <IDirectoryMonitor>();
     _peopleCache                          = A.Fake <IPeopleCache>();
     _peopleAverageAgeEvaluator            = A.Fake <IPeopleAverageAgeEvaluator>();
     _averagePeopleAgePerCountrySerializer = A.Fake <ISerializer <AveragePeopleAgePerCountry> >();
     _fileHelper                           = A.Fake <IFileHelper>();
     _objectUnderTest                      = new AgeAggregatorService(_directoryPathValidator, _notifier, _pathHelper, _directoryMonitor, _peopleCache, _peopleAverageAgeEvaluator, _averagePeopleAgePerCountrySerializer, _fileHelper);
 }
        public void Should_DeleteRemovedFileFromCache_When_FileIsRemovedFromDirectory()
        {
            string deletedFileName = "deletedFileName";
            string existingDirectoryPath = "existingFilePath", fullExistingDirectoryPath = "fullExistingDirectoryPath";

            A.CallTo(() => _directoryPathValidator.ValidateDirectoryPath(existingDirectoryPath)).Returns(true);
            A.CallTo(() => _pathHelper.CanWrite(A <string> .Ignored)).Returns(true);
            A.CallTo(() => _pathHelper.GetFullPath(existingDirectoryPath)).Returns(fullExistingDirectoryPath);
            var testMonitor = new DirectoryMonitorWhichAllowsToFireEventsFromOutside();

            _objectUnderTest = new AgeAggregatorService(_directoryPathValidator, _notifier, _pathHelper, testMonitor, _peopleCache, _peopleAverageAgeEvaluator, _averagePeopleAgePerCountrySerializer, _fileHelper);

            _objectUnderTest.RunAsync(existingDirectoryPath, null);
            Thread.Sleep(1000);
            testMonitor.ForceFileRemoved(deletedFileName);

            A.CallTo(() => _peopleCache.ExcludeFiles(Path.Combine(fullExistingDirectoryPath, deletedFileName))).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void Should_NotifyUser_When_FileIsAddedToDirectory()
        {
            string newFileName = "newFileName";
            string existingDirectoryPath = "existingFilePath", fullExistingDirectoryPath = "fullExistingDirectoryPath";

            A.CallTo(() => _directoryPathValidator.ValidateDirectoryPath(existingDirectoryPath)).Returns(true);
            A.CallTo(() => _pathHelper.CanWrite(A <string> .Ignored)).Returns(true);
            A.CallTo(() => _pathHelper.GetFullPath(existingDirectoryPath)).Returns(fullExistingDirectoryPath);
            var testMonitor = new DirectoryMonitorWhichAllowsToFireEventsFromOutside();

            _objectUnderTest = new AgeAggregatorService(_directoryPathValidator, _notifier, _pathHelper, testMonitor, _peopleCache, _peopleAverageAgeEvaluator, _averagePeopleAgePerCountrySerializer, _fileHelper);

            _objectUnderTest.RunAsync(existingDirectoryPath, null);
            Thread.Sleep(1000);
            testMonitor.ForceFileAdded(newFileName);

            A.CallTo(() => _notifier.NotifyUser("File newFileName has been added to the directory. Recalculating results...")).MustHaveHappened(Repeated.Exactly.Once);
        }