示例#1
0
        public static void LoadFromDifferentLocations()
        {
            using (TempFile tf1 = TempFile.Create(TestData.s_SimpleAssemblyImage))
                using (TempFile tf2 = TempFile.Create(TestData.s_SimpleAssemblyImage))
                    // Note this is using SimpleAssemblyResolver in order to resolve LoadFromAssemblyName.
                    using (MetadataLoadContext lc = new MetadataLoadContext(new SimpleAssemblyResolver()))
                    {
                        Assembly a = lc.LoadFromByteArray(TestData.s_SimpleAssemblyImage);
                        Assert.NotNull(a);

                        Assembly a1 = lc.LoadFromByteArray(TestData.s_SimpleAssemblyImage);
                        Assert.Equal(a, a1);

                        Assembly a2 = lc.LoadFromAssemblyName(new AssemblyName(TestData.s_SimpleAssemblyFullName));
                        Assert.Equal(a, a2);

                        Assembly a3 = lc.LoadFromAssemblyPath(tf1.Path);
                        Assert.Equal(a, a3);

                        Assembly a4 = lc.LoadFromAssemblyPath(tf2.Path);
                        Assert.Equal(a, a4);
                    }
        }
示例#2
0
        public static void LoadFromDifferentLocations()
        {
            using (TempFile tf1 = TempFile.Create(TestData.s_SimpleAssemblyImage))
                using (TempFile tf2 = TempFile.Create(TestData.s_SimpleAssemblyImage))
                    using (MetadataLoadContext lc = new MetadataLoadContext(new EmptyCoreMetadataAssemblyResolver()))
                    {
                        // As long as the MVID matches, you can load the same assembly from multiple locations.
                        Assembly a = lc.LoadFromByteArray(TestData.s_SimpleAssemblyImage);
                        Assert.NotNull(a);

                        Assembly a1 = lc.LoadFromByteArray(TestData.s_SimpleAssemblyImage);
                        Assert.Equal(a, a1);

                        Assembly a2 = lc.LoadFromAssemblyName(new AssemblyName(TestData.s_SimpleAssemblyName));
                        Assert.Equal(a, a2);

                        Assembly a3 = lc.LoadFromAssemblyPath(tf1.Path);
                        Assert.Equal(a, a3);

                        Assembly a4 = lc.LoadFromAssemblyPath(tf2.Path);
                        Assert.Equal(a, a4);
                    }
        }
示例#3
0
        public void CanUploadMultipleFiles()
        {
            // Create multiple small text files
            var files = Enumerable.Range(1, 3)
                        .Select(i => TempFile.Create(_tempDirectory, "txt", $"Contents of file {i}."))
                        .ToList();

            // Upload each file
            var inputFile = Browser.FindElement(By.Id("input-file"));

            inputFile.SendKeys(string.Join("\n", files.Select(f => f.Path)));

            // VAlidate that each file was uploaded correctly
            Assert.All(files, file =>
            {
                var fileContainer      = Browser.FindElement(By.Id($"file-{file.Name}"));
                var fileSizeElement    = fileContainer.FindElement(By.Id("file-size"));
                var fileContentElement = fileContainer.FindElement(By.Id("file-content"));

                Browser.Equal(file.Contents.Length.ToString(), () => fileSizeElement.Text);
                Browser.Equal(file.Text, () => fileContentElement.Text);
            });
        }
示例#4
0
        public static void LoadFromDifferentLocations()
        {
            using (TempFile tf1 = TempFile.Create(TestData.s_SimpleAssemblyImage))
                using (TempFile tf2 = TempFile.Create(TestData.s_SimpleAssemblyImage))
                    using (TypeLoader tl = new TypeLoader())
                    {
                        // As long as the MVID matches, you can load the same assembly from multiple locations.
                        Assembly a = tl.LoadFromByteArray(TestData.s_SimpleAssemblyImage);
                        Assert.NotNull(a);

                        Assembly a1 = tl.LoadFromByteArray(TestData.s_SimpleAssemblyImage);
                        Assert.Equal(a, a1);

                        Assembly a2 = tl.LoadFromAssemblyName(new AssemblyName(TestData.s_SimpleAssemblyName));
                        Assert.Equal(a, a2);

                        Assembly a3 = tl.LoadFromAssemblyPath(tf1.Path);
                        Assert.Equal(a, a3);

                        Assembly a4 = tl.LoadFromAssemblyPath(tf2.Path);
                        Assert.Equal(a, a4);
                    }
        }
示例#5
0
        public void ModifiedFileIsNotReloadedIfOneFileIsMissing()
        {
            using (var file1 = TempFile.Create())
            {
                using (var file2 = TempFile.Create())
                {
                    factory.FilePaths(file1.Path, file2.Path)
                    .AutoUpdate(true);
                    file1.SetContentFromPath(TestUtils.TestFilePath("flag-only.json"));
                    file2.SetContent("{}");
                    using (var fp = MakeDataSource())
                    {
                        fp.Start();
                        var initData = _updateSink.Inits.ExpectValue();
                        AssertJsonEqual(DataSetAsJson(ExpectedDataSetForFlagOnlyFile(1)), DataSetAsJson(initData));

                        file2.Delete();
                        file1.SetContentFromPath(TestUtils.TestFilePath("segment-only.json"));

                        _updateSink.Inits.ExpectNoValue();
                    }
                }
            }
        }
示例#6
0
        [PlatformSpecific(~TestPlatforms.Browser)] // Not passing as internal System.Net.Mail.MailWriter stripped from build
        public void SentSpecialLengthMailAttachment_Base64Decode_Success()
        {
            // The special length follows pattern: (3N - 1) * 0x4400 + 1
            // This length will trigger WriteState.Padding = 2 & count = 1 (byte to write)
            // The smallest number to match the pattern is 34817.
            int specialLength = 34817;

            string stringLength34817 = new string('A', specialLength - 1) + 'Z';

            byte[] toBytes = Encoding.ASCII.GetBytes(stringLength34817);

            using (var tempFile = TempFile.Create(toBytes))
            {
                var message = new MailMessage("*****@*****.**", "*****@*****.**", "testSubject", "testBody");
                message.Attachments.Add(new Attachment(tempFile.Path));

                string attachment        = DecodeSentMailMessage(message).Attachment;
                string decodedAttachment = Encoding.UTF8.GetString(Convert.FromBase64String(attachment));

                // Make sure last byte is not encoded twice.
                Assert.Equal(specialLength, decodedAttachment.Length);
                Assert.Equal("AAAAAAAAAAAAAAAAZ", decodedAttachment.Substring(34800));
            }
        }
示例#7
0
        protected override void SetUp()
        {
            base.SetUp();

            // add 3 directories
            Directory.CreateDirectory(Path.Combine(TempDirName, "dir1"));
            Directory.CreateDirectory(Path.Combine(TempDirName, "dir2"));
            Directory.CreateDirectory(Path.Combine(TempDirName, "dir3"));

            // add file names
            _fileList.Add(Path.Combine(TempDirName, "file1.txt"));
            _fileList.Add(Path.Combine(TempDirName, "file2.txt"));
            _fileList.Add(Path.Combine(TempDirName, Path.Combine("dir1", "file3.tab")));
            _fileList.Add(Path.Combine(TempDirName, Path.Combine("dir1", "file4.txt")));
            _fileList.Add(Path.Combine(TempDirName, Path.Combine("dir2", "file5.tab")));
            _fileList.Add(Path.Combine(TempDirName, Path.Combine("dir2", "file6.txt")));


            // add some text to each file, just for fun ;)
            for (int i = 0; i < _fileList.Count; i++)
            {
                TempFile.Create(_fileList[i]);
            }
        }
示例#8
0
        public void Test_ReadLargeAmountFromStdout()
        {
            // create a text file with A LOT of data
            string        line     = "01234567890123456789012345678901234567890123456789012345678901234567890123456789" + Environment.NewLine;
            StringBuilder contents = new StringBuilder("You can delete this file" + Environment.NewLine);

            for (int i = 0; i < 250; i++)
            {
                contents.Append(line);
            }
            string tempFileName = Path.Combine(TempDirName, "bigfile.txt");

            TempFile.Create(tempFileName);

            if (PlatformHelper.IsWin32)
            {
                RunBuild(FormatBuildFile("program='cmd.exe' commandline='/c type &quot;" + tempFileName + "&quot;'", ""));
            }
            else
            {
                RunBuild(FormatBuildFile("program='cat' commandline=' &quot;" + tempFileName + "&quot;'", ""));
            }
            // if we get here then we passed, ie, no hang = bug fixed
        }
示例#9
0
 public CopyPasteFiles()
 {
     NodesFile = TempFile.Create();
     LinksFile = TempFile.Create();
 }
示例#10
0
 public override void TestInitialise()
 {
     base.TestInitialise();
     _utf16EncodedFile = TempFile.CreateWithContents(_fileContents, Encoding.Unicode).FullName;
     _emptyFile        = TempFile.Create().FullName;
 }
示例#11
0
 protected void SetUp()
 {
     _tempFileName = TempFile.Create();
 }
示例#12
0
 private static string GetCommandsTempFile(IEnumerable <string> commands)
 {
     return(TempFile.Create(string.Join("\n", commands), "txt"));
 }
示例#13
0
        public async Task SendFileGetsCanceledByDispose(bool owning)
        {
            // Aborting sync operations for non-owning handles is not supported on Unix.
            if (!owning && UsesSync && !PlatformDetection.IsWindows)
            {
                return;
            }

            // We try this a couple of times to deal with a timing race: if the Dispose happens
            // before the operation is started, the peer won't see a ConnectionReset SocketException and we won't
            // see a SocketException either.
            int msDelay = 100;
            await RetryHelper.ExecuteAsync(async() =>
            {
                (Socket socket1, Socket socket2) = SocketTestExtensions.CreateConnectedSocketPair();
                using SafeSocketHandle? owner    = ReplaceWithNonOwning(ref socket1, owning);

                using (socket2)
                {
                    Task socketOperation = Task.Run(async() =>
                    {
                        // Create a large file that will cause SendFile to block until the peer starts reading.
                        using var tempFile = TempFile.Create();
                        using (var fs = new FileStream(tempFile.Path, FileMode.CreateNew, FileAccess.Write))
                        {
                            fs.SetLength(20 * 1024 * 1024 /* 20MB */);
                        }

                        await SendFileAsync(socket1, tempFile.Path);
                    });

                    // Wait a little so the operation is started.
                    await Task.Delay(msDelay);
                    msDelay         *= 2;
                    Task disposeTask = Task.Run(() => socket1.Dispose());

                    await Task.WhenAny(disposeTask, socketOperation).WaitAsync(TimeSpan.FromSeconds(30));
                    await disposeTask;

                    SocketError?localSocketError = null;

                    try
                    {
                        await socketOperation;
                    }
                    catch (SocketException se)
                    {
                        localSocketError = se.SocketErrorCode;
                    }

                    if (UsesSync)
                    {
                        Assert.Equal(SocketError.ConnectionAborted, localSocketError);
                    }
                    else
                    {
                        Assert.Equal(SocketError.OperationAborted, localSocketError);
                    }

                    owner?.Dispose();

                    // On OSX, we're unable to unblock the on-going socket operations and
                    // perform an abortive close.
                    if (!(UsesSync && PlatformDetection.IsOSXLike))
                    {
                        SocketError?peerSocketError = null;
                        var receiveBuffer           = new byte[4096];
                        while (true)
                        {
                            try
                            {
                                int received = socket2.Receive(receiveBuffer);
                                if (received == 0)
                                {
                                    break;
                                }
                            }
                            catch (SocketException se)
                            {
                                peerSocketError = se.SocketErrorCode;
                                break;
                            }
                        }
                        Assert.Equal(SocketError.ConnectionReset, peerSocketError);
                    }
                }
            }, maxAttempts : 10, retryWhen : e => e is XunitException);
        }
        public void CanOpenFileStreamDirectlyForReading()
        {
            string filePath = TempFile.Create().FullName;

            using (new FileStream(filePath, FileMode.Open, FileAccess.Read)) {}
        }
 public override void TestInitialise()
 {
     base.TestInitialise();
     _emptyFile = TempFile.Create().FullName;
 }