コード例 #1
0
        public async Task TestGetDS2019FileStream_ArchiveDoesNotHaveFile()
        {
            using (ShimsContext.Create())
            {
                var sevisId     = "N000012345";
                var now         = DateTime.UtcNow;
                var zipFileName = String.Format("_{0}_{1}.pdf", sevisId, now);

                var entries         = new List <ZipArchiveEntry>();
                var readonlyEntries = new ReadOnlyCollection <ZipArchiveEntry>(entries);

                var zipArchive = new System.IO.Compression.Fakes.ShimZipArchive
                {
                    EntriesGet = () => readonlyEntries
                };

                var archiveHandler = new SevisBatchZipArchiveHandler(zipArchive);

                Action <Stream> tester = (testStream) =>
                {
                    Assert.IsNull(testStream);
                };
                var requestId   = new RequestId(1, RequestIdType.Participant, RequestActionType.Create);
                var stream      = archiveHandler.GetDS2019FileStream(requestId, sevisId);
                var streamAsync = await archiveHandler.GetDS2019FileStreamAsync(requestId, sevisId);

                tester(stream);
                tester(streamAsync);
            }
        }
コード例 #2
0
        public async Task TestGetDS2019FileStream_ArchiveHasFile()
        {
            using (ShimsContext.Create())
            {
                var memoryStream = new MemoryStream();
                var sevisId      = "N000012345";
                var now          = DateTime.UtcNow;
                var zipFileName  = String.Format("_{0}_{1}.pdf", sevisId, now);
                var entry        = new System.IO.Compression.Fakes.ShimZipArchiveEntry
                {
                    NameGet = () => zipFileName,
                    Open    = () => memoryStream
                };

                var entries = new List <ZipArchiveEntry>();
                entries.Add(entry);
                var readonlyEntries = new ReadOnlyCollection <ZipArchiveEntry>(entries);

                var zipArchive = new System.IO.Compression.Fakes.ShimZipArchive
                {
                    EntriesGet = () => readonlyEntries
                };

                var archiveHandler = new SevisBatchZipArchiveHandler(zipArchive);

                Action <Stream> tester = (testStream) =>
                {
                    Assert.IsTrue(Object.ReferenceEquals(memoryStream, testStream));
                };
                var requestId   = new RequestId(1, RequestIdType.Participant, RequestActionType.Create);
                var stream      = archiveHandler.GetDS2019FileStream(requestId, sevisId);
                var streamAsync = await archiveHandler.GetDS2019FileStreamAsync(requestId, sevisId);

                tester(stream);
                tester(streamAsync);

                memoryStream.Dispose();
            }
        }