Esempio n. 1
0
        public async Task WriteRequestsToFilesAsyncTest()
        {
            // Arrange
            DateTime dt = DateTime.Today;

            const string name1 = "TestReq";
            const string name2 = "Some";

            Request req1 = new Request
            {
                Name   = name1,
                Date   = dt,
                Visits = 3
            };

            Request req2 = new Request
            {
                Name = name2,
                Date = dt.AddDays(1)
            };

            RequestModel reqM1 = new RequestModel
            {
                Name   = name1,
                Date   = dt,
                Visits = 3
            };

            RequestModel reqM2 = new RequestModel
            {
                Name = name2,
                Date = dt.AddDays(1)
            };

            string req1Date = req1.Date.ToString(Formatter.ShortDateFormat);
            string req2Date = req2.Date.ToString(Formatter.ShortDateFormat);

            var    pathToSaveXmlFiles = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "xmlTests");
            string filePath1          = Path.Combine(pathToSaveXmlFiles, req1Date + FileExtension.Xml);
            string filePath2          = Path.Combine(pathToSaveXmlFiles, req2Date + FileExtension.Xml);

            List <Request> reqList = new List <Request> {
                req1, req2
            };

            _repository.GetAllAsync().Returns(reqList);
            _mapper.EntitiesToModels(reqList).Returns(new List <RequestModel> {
                reqM1, reqM2
            });

            // Act
            await _requestsService.WriteRequestsToFilesAsync(pathToSaveXmlFiles);

            // Assert
            CheckXmlFileFormatting(filePath1, reqM1, req1Date);
            CheckXmlFileFormatting(filePath2, reqM2, req2Date);
        }
        public void EntitiesAreCorrectlyMappedToModelsTest()
        {
            List <Request>      requests = RequestsGenerator.GetNRequests(6).OrderBy(x => x.Name).ToList();
            List <RequestModel> models   = _mapper.EntitiesToModels(requests).OrderBy(x => x.Name).ToList();

            for (int i = 0; i < 0; i++)
            {
                Assert.Equal(requests[i].Name, models[i].Name);
                Assert.Equal(requests[i].Date, models[i].Date);
                Assert.Equal(requests[i].Visits, models[i].Visits);
                Assert.Equal(requests[i].Index, models[i].Id);
            }
        }
Esempio n. 3
0
        public async Task WriteRequestsToFilesAsync(string directoryToSave)
        {
            IEnumerable <Request> requests = await _repo.GetAllAsync().ConfigureAwait(false);

            var groupedRequests = _mapper.EntitiesToModels(requests)
                                  .GroupBy(u => u.Date.Date)
                                  .Select(grp => grp.ToList())
                                  .ToList();

            // run creation of files in parallel - one thread for one date/file
            var tasks = new List <Task>();

            foreach (var list in groupedRequests)
            {
                tasks.Add(WriteToFile(list, directoryToSave));
            }
            await Task.WhenAll(tasks).ConfigureAwait(false);
        }