public void AddedSources_Are_Deterministic()
        {
            // a few manual simple ones
            AdditionalSourcesCollection asc = new AdditionalSourcesCollection(".cs");

            asc.Add("file3.cs", SourceText.From("", Encoding.UTF8));
            asc.Add("file1.cs", SourceText.From("", Encoding.UTF8));
            asc.Add("file2.cs", SourceText.From("", Encoding.UTF8));
            asc.Add("file5.cs", SourceText.From("", Encoding.UTF8));
            asc.Add("file4.cs", SourceText.From("", Encoding.UTF8));

            var sources   = asc.ToImmutableAndFree();
            var hintNames = sources.Select(s => s.HintName).ToArray();

            Assert.Equal(
                new[] { "file3.cs", "file1.cs", "file2.cs", "file5.cs", "file4.cs" },
                hintNames
                );

            // generate a long random list, remembering the order we added them
            Random r = new Random();

            string[] names = new string[1000];
            asc = new AdditionalSourcesCollection(".cs");
            for (int i = 0; i < 1000; i++)
            {
                names[i] = CSharpTestBase.GetUniqueName() + ".cs";
                asc.Add(names[i], SourceText.From("", Encoding.UTF8));
            }

            sources   = asc.ToImmutableAndFree();
            hintNames = sources.Select(s => s.HintName).ToArray();
            Assert.Equal(names, hintNames);
        }
Exemplo n.º 2
0
        public void Remove(string addHintName, string removeHintName)
        {
            AdditionalSourcesCollection asc = new AdditionalSourcesCollection(".cs");

            asc.Add(addHintName, SourceText.From("", Encoding.UTF8));
            asc.RemoveSource(removeHintName);
            var sources = asc.ToImmutableAndFree();

            Assert.Empty(sources);
        }
        public void HintName_ValidValues(string hintName)
        {
            AdditionalSourcesCollection asc = new AdditionalSourcesCollection();

            asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8));
            Assert.True(asc.Contains(hintName));

            var sources = asc.ToImmutableAndFree();

            Assert.True(sources[0].HintName.EndsWith(".cs"));
        }