public void Should_AddItemsToCache_When_InitializedWithDirectoryPathWhereSomeItemsExist()
        {
            var deserializedPeople = new List <Person>()
            {
                new Person
                {
                    FirstName = "PersonName1",
                    LastName  = "PersonLastName1",
                    Country   = "Country1",
                    Age       = 30
                },
                new Person
                {
                    FirstName = "PersonName2",
                    LastName  = "PersonLastName2",
                    Country   = "Country2",
                    Age       = 60
                }
            };
            var    peopleDeserializer = A.Fake <IDeserializer <Person> >();
            string directoryPath      = "directoryPath";

            string[] allowedExtensions = new[] { ".xml", "json", ".csv" };
            string[] files             = new[] { "file1" };
            A.CallTo(() => _directoryHelper.GetDirectoryFiles(directoryPath, A <string[]> .That.IsSameSequenceAs(allowedExtensions))).Returns(files);
            A.CallTo(() => _pathHelper.GetExtension("file1")).Returns(".extension");
            A.CallTo(() => _personDeserializerFactory.CreateFor(".extension")).Returns(peopleDeserializer);
            A.CallTo(() => _fileHelper.ReadFile("file1")).Returns("file1Content");
            A.CallTo(() => peopleDeserializer.DeserializeArray("file1Content")).Returns(deserializedPeople);

            _objectUnderTest.Initialize(directoryPath);
            var takenFromCache = _objectUnderTest.GetPeople();

            CollectionAssert.AreEquivalent(deserializedPeople, takenFromCache);
        }
예제 #2
0
 public void IncludeFiles(params string[] fileNames)
 {
     Parallel.ForEach(fileNames, name =>
     {
         var deserialized = _personDeserializerFactory.CreateFor(_pathHelper.GetExtension(name)).DeserializeArray(_fileHelper.ReadFile(name));
         if (deserialized != null)
         {
             _fileNameBasedPeopleDictionary.TryAdd(name, deserialized);
         }
     });
 }