Beispiel #1
0
        public void KeyComparerCollisions()
        {
            // First check where collisions have matching values.
            var builder = ImmutableSortedDictionary.Create <string, string>()
                          .Add("a", "1").Add("A", "1").ToBuilder();

            builder.KeyComparer = StringComparer.OrdinalIgnoreCase;
            Assert.Equal(1, builder.Count);
            Assert.True(builder.ContainsKey("a"));

            var set = builder.ToImmutable();

            Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer);
            Assert.Equal(1, set.Count);
            Assert.True(set.ContainsKey("a"));

            // Now check where collisions have conflicting values.
            builder = ImmutableSortedDictionary.Create <string, string>()
                      .Add("a", "1").Add("A", "2").Add("b", "3").ToBuilder();
            Assert.Throws <ArgumentException>(() => builder.KeyComparer = StringComparer.OrdinalIgnoreCase);

            // Force all values to be considered equal.
            builder.ValueComparer = EverythingEqual <string> .Default;
            Assert.Same(EverythingEqual <string> .Default, builder.ValueComparer);
            builder.KeyComparer = StringComparer.OrdinalIgnoreCase; // should not throw because values will be seen as equal.
            Assert.Equal(2, builder.Count);
            Assert.True(builder.ContainsKey("a"));
            Assert.True(builder.ContainsKey("b"));
        }
Beispiel #2
0
        public void WithComparersCollisions()
        {
            // First check where collisions have matching values.
            var map = ImmutableSortedDictionary.Create <string, string>()
                      .Add("a", "1").Add("A", "1");

            map = map.WithComparers(StringComparer.OrdinalIgnoreCase);
            Assert.Same(StringComparer.OrdinalIgnoreCase, map.KeyComparer);
            Assert.Equal(1, map.Count);
            Assert.True(map.ContainsKey("a"));
            Assert.Equal("1", map["a"]);

            // Now check where collisions have conflicting values.
            map = ImmutableSortedDictionary.Create <string, string>()
                  .Add("a", "1").Add("A", "2").Add("b", "3");
            Assert.Throws <ArgumentException>(() => map.WithComparers(StringComparer.OrdinalIgnoreCase));

            // Force all values to be considered equal.
            map = map.WithComparers(StringComparer.OrdinalIgnoreCase, EverythingEqual <string> .Default);
            Assert.Same(StringComparer.OrdinalIgnoreCase, map.KeyComparer);
            Assert.Same(EverythingEqual <string> .Default, map.ValueComparer);
            Assert.Equal(2, map.Count);
            Assert.True(map.ContainsKey("a"));
            Assert.True(map.ContainsKey("b"));
        }
Beispiel #3
0
 public ProjectState RemoveAllDocuments()
 {
     return(this.With(
                projectInfo: this.ProjectInfo.WithVersion(this.Version.GetNewerVersion()).WithDocuments(SpecializedCollections.EmptyEnumerable <DocumentInfo>()),
                documentIds: ImmutableList <DocumentId> .Empty,
                documentStates: ImmutableSortedDictionary.Create <DocumentId, DocumentState>(DocumentIdComparer.Instance)));
 }
Beispiel #4
0
        public void WithComparers()
        {
            var map = ImmutableSortedDictionary.Create <string, string>().Add("a", "1").Add("B", "1");

            Assert.Same(Comparer <string> .Default, map.KeyComparer);
            Assert.True(map.ContainsKey("a"));
            Assert.False(map.ContainsKey("A"));

            map = map.WithComparers(StringComparer.OrdinalIgnoreCase);
            Assert.Same(StringComparer.OrdinalIgnoreCase, map.KeyComparer);
            Assert.Equal(2, map.Count);
            Assert.True(map.ContainsKey("a"));
            Assert.True(map.ContainsKey("A"));
            Assert.True(map.ContainsKey("b"));

            var cultureComparer = StringComparer.CurrentCulture;

            map = map.WithComparers(StringComparer.OrdinalIgnoreCase, cultureComparer);
            Assert.Same(StringComparer.OrdinalIgnoreCase, map.KeyComparer);
            Assert.Same(cultureComparer, map.ValueComparer);
            Assert.Equal(2, map.Count);
            Assert.True(map.ContainsKey("a"));
            Assert.True(map.ContainsKey("A"));
            Assert.True(map.ContainsKey("b"));
        }
Beispiel #5
0
        public void EnumeratorRecyclingMisuse()
        {
            var collection     = ImmutableSortedDictionary.Create <int, int>().Add(3, 5);
            var enumerator     = collection.GetEnumerator();
            var enumeratorCopy = enumerator;

            Assert.True(enumerator.MoveNext());
            Assert.False(enumerator.MoveNext());
            enumerator.Dispose();
            Assert.Throws <ObjectDisposedException>(() => enumerator.MoveNext());
            Assert.Throws <ObjectDisposedException>(() => enumerator.Reset());
            Assert.Throws <ObjectDisposedException>(() => enumerator.Current);
            Assert.Throws <ObjectDisposedException>(() => enumeratorCopy.MoveNext());
            Assert.Throws <ObjectDisposedException>(() => enumeratorCopy.Reset());
            Assert.Throws <ObjectDisposedException>(() => enumeratorCopy.Current);

            enumerator.Dispose(); // double-disposal should not throw
            enumeratorCopy.Dispose();

            // We expect that acquiring a new enumerator will use the same underlying Stack<T> object,
            // but that it will not throw exceptions for the new enumerator.
            enumerator = collection.GetEnumerator();
            Assert.True(enumerator.MoveNext());
            Assert.False(enumerator.MoveNext());
            Assert.Throws <InvalidOperationException>(() => enumerator.Current);
            enumerator.Dispose();
        }
        public static void TestDebuggerAttributes_Null()
        {
            Type proxyType = DebuggerAttributes.GetProxyType(ImmutableSortedDictionary.Create <int, int>());
            TargetInvocationException tie = Assert.Throws <TargetInvocationException>(() => Activator.CreateInstance(proxyType, (object)null));

            Assert.IsType <ArgumentNullException>(tie.InnerException);
        }
Beispiel #7
0
        public void WithComparersEmptyCollection()
        {
            var map = ImmutableSortedDictionary.Create <string, string>();

            Assert.Same(Comparer <string> .Default, map.KeyComparer);
            map = map.WithComparers(StringComparer.OrdinalIgnoreCase);
            Assert.Same(StringComparer.OrdinalIgnoreCase, map.KeyComparer);
        }
Beispiel #8
0
 public Builder()
 {
     Pizzas       = ImmutableSortedDictionary.Create <int, Pizza>();
     Sizes        = ImmutableSortedDictionary.Create <int, Size>();
     Toppings     = ImmutableSortedDictionary.Create <int, Topping>();
     Orders       = ImmutableSortedDictionary.Create <int, Order>();
     OrderDetails = ImmutableSortedDictionary.Create <int, OrderDetail>();
 }
Beispiel #9
0
        public void ContainsValue()
        {
            var map     = ImmutableSortedDictionary.Create <string, int>().Add("five", 5);
            var builder = map.ToBuilder();

            Assert.True(builder.ContainsValue(5));
            Assert.False(builder.ContainsValue(4));
        }
Beispiel #10
0
        public void CollisionExceptionMessageContainsKey()
        {
            var map = ImmutableSortedDictionary.Create <string, string>()
                      .Add("firstKey", "1").Add("secondKey", "2");
            var exception = Assert.Throws <ArgumentException>(null, () => map.Add("firstKey", "3"));

            Assert.Contains("firstKey", exception.Message);
        }
Beispiel #11
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="DbContextOptions" /> class. You normally override
        ///     <see cref="DbContext.OnConfiguring(DbContextOptionsBuilder)" /> or use a <see cref="DbContextOptionsBuilder" />
        ///     to create instances of this class and it is not designed to be directly constructed in your application code.
        /// </summary>
        /// <param name="extensions"> The extensions that store the configured options. </param>
        protected DbContextOptions(
            IReadOnlyDictionary <Type, IDbContextOptionsExtension> extensions)
        {
            Check.NotNull(extensions, nameof(extensions));

            _extensionsMap = extensions as ImmutableSortedDictionary <Type, IDbContextOptionsExtension>
                             ?? ImmutableSortedDictionary.Create <Type, IDbContextOptionsExtension>(TypeFullNameComparer.Instance)
                             .AddRange(extensions);
        }
Beispiel #12
0
        public void DebuggerAttributesValid()
        {
            DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableSortedDictionary.Create <string, int>());
            DebuggerAttributes.ValidateDebuggerTypeProxyProperties(ImmutableSortedDictionary.Create <int, int>());

            object rootNode = DebuggerAttributes.GetFieldValue(ImmutableSortedDictionary.Create <string, string>(), "_root");

            DebuggerAttributes.ValidateDebuggerDisplayReferences(rootNode);
        }
Beispiel #13
0
        public void Clear()
        {
            var builder = ImmutableSortedDictionary.Create <string, int>().ToBuilder();

            builder.Add("five", 5);
            Assert.Equal(1, builder.Count);
            builder.Clear();
            Assert.Equal(0, builder.Count);
        }
Beispiel #14
0
        public void GetValueOrDefaultOfConcreteType()
        {
            var empty     = ImmutableSortedDictionary.Create <string, int>().ToBuilder();
            var populated = ImmutableSortedDictionary.Create <string, int>().Add("a", 5).ToBuilder();

            Assert.Equal(0, empty.GetValueOrDefault("a"));
            Assert.Equal(1, empty.GetValueOrDefault("a", 1));
            Assert.Equal(5, populated.GetValueOrDefault("a"));
            Assert.Equal(5, populated.GetValueOrDefault("a", 1));
        }
Beispiel #15
0
        public void CollisionExceptionMessageContainsKey()
        {
            var map = ImmutableSortedDictionary.Create <string, string>()
                      .Add("firstKey", "1").Add("secondKey", "2");
            var exception = AssertExtensions.Throws <ArgumentException>(null, () => map.Add("firstKey", "3"));

            if (!PlatformDetection.IsNetNative) //.Net Native toolchain removes exception messages.
            {
                Assert.Contains("firstKey", exception.Message);
            }
        }
Beispiel #16
0
        public void AddRange()
        {
            var builder = ImmutableSortedDictionary.Create <string, int>().ToBuilder();

            builder.AddRange(new Dictionary <string, int> {
                { "a", 1 }, { "b", 2 }
            });
            Assert.Equal(2, builder.Count);
            Assert.Equal(1, builder["a"]);
            Assert.Equal(2, builder["b"]);
        }
        public static ImmutableSortedDictionary <T, T> SysColImmutableSortedDictionarySetup <T>(Dictionary <T, T> values)
        {
            var immutableMap = ImmutableSortedDictionary.Create <T, T>();

            foreach (var kvp in values)
            {
                immutableMap = immutableMap.Add(kvp.Key, kvp.Value);
            }

            return(immutableMap);
        }
Beispiel #18
0
        public ImmutableSortedDictionary <T, T> SysColImmutableSortedDictionary()
        {
            var map = ImmutableSortedDictionary.Create <T, T>();

            foreach (var kvp in values)
            {
                map = map.Add(kvp.Key, kvp.Value);
            }

            return(map);
        }
Beispiel #19
0
        public void KeyComparerEmptyCollection()
        {
            var builder = ImmutableSortedDictionary.Create <string, string>()
                          .Add("a", "1").Add("B", "1").ToBuilder();

            Assert.Same(Comparer <string> .Default, builder.KeyComparer);
            builder.KeyComparer = StringComparer.OrdinalIgnoreCase;
            Assert.Same(StringComparer.OrdinalIgnoreCase, builder.KeyComparer);
            var set = builder.ToImmutable();

            Assert.Same(StringComparer.OrdinalIgnoreCase, set.KeyComparer);
        }
Beispiel #20
0
        public void RemoveRange()
        {
            var builder =
                ImmutableSortedDictionary.Create <string, int>()
                .AddRange(new Dictionary <string, int> {
                { "a", 1 }, { "b", 2 }, { "c", 3 }
            })
                .ToBuilder();

            Assert.Equal(3, builder.Count);
            builder.RemoveRange(new[] { "a", "b" });
            Assert.Equal(1, builder.Count);
            Assert.Equal(3, builder["c"]);
        }
Beispiel #21
0
        public void DebuggerAttributesValid()
        {
            DebuggerAttributes.ValidateDebuggerDisplayReferences(ImmutableSortedDictionary.Create <string, int>());
            ImmutableSortedDictionary <int, int> dict = ImmutableSortedDictionary.Create <int, int>().Add(1, 2).Add(2, 3).Add(3, 4);
            var info = DebuggerAttributes.ValidateDebuggerTypeProxyProperties(dict);

            object rootNode = DebuggerAttributes.GetFieldValue(ImmutableSortedDictionary.Create <string, string>(), "_root");

            DebuggerAttributes.ValidateDebuggerDisplayReferences(rootNode);
            PropertyInfo itemProperty = info.Properties.Single(pr => pr.GetCustomAttribute <DebuggerBrowsableAttribute>().State == DebuggerBrowsableState.RootHidden);

            KeyValuePair <int, int>[] items = itemProperty.GetValue(info.Instance) as KeyValuePair <int, int>[];
            Assert.Equal(dict, items);
        }
        static void Main(string[] args)
        {
            ImmutableSortedDictionary <int, int> isd = ImmutableSortedDictionary.Create <int, int>();

            isd = isd.Add(1, 1);
            isd = isd.Add(2, 2);
            isd = isd.Remove(2);
            ImmutableSortedDictionary <int, int> .Builder isdBuilder = isd.ToBuilder();
            isdBuilder.Add(10, 10); //adds to original SortedDictionary. returns void.

            ImmutableSortedDictionary <int, int> .Builder builder = ImmutableSortedDictionary.CreateBuilder <int, int>();
            builder.Add(3, 3);
            isd = builder.ToImmutable();
        }
        public void ImmutableSortedDictionaryTest_0_Success()
        {
            var collection = ImmutableSortedDictionary.Create <int, int>();
            var target     = this.CreateTarget <ImmutableSortedDictionary <int, int> >();

            using (var buffer = new MemoryStream())
            {
                target.Pack(buffer, collection);
                buffer.Position = 0;
                var unpacked = target.Unpack(buffer);
                buffer.Position = 0;
                Assert.That(unpacked.ToArray(), Is.EqualTo(collection.ToArray()));
            }
        }
Beispiel #24
0
        private ImmutableSortedDictionary <Payload, Payload> creatASListWithNelement(int numberOfElements)
        {
            var     treeBuilder  = ImmutableSortedDictionary.Create <Payload, Payload>();
            Payload firstElement = new Payload("Load 0");

            treeBuilder = treeBuilder.Add(firstElement, firstElement);



            for (int i = 1; i < numberOfElements; i++)
            {
                Payload objecttoAdd = new Payload("Load " + i);
                treeBuilder = treeBuilder.Add(objecttoAdd, objecttoAdd);
            }

            return(treeBuilder.ToImmutableSortedDictionary <Payload, Payload>());
        }
        public void SerializeSortedDictionary()
        {
            ImmutableSortedDictionary <int, string> l = ImmutableSortedDictionary.Create(new SortedDictionary <int, string>
            {
                { 1, "One" },
                { 2, "II" },
                { 3, "3" }
            });

            string json = JsonConvert.SerializeObject(l, Formatting.Indented);

            Assert.AreEqual(@"{
  ""1"": ""One"",
  ""2"": ""II"",
  ""3"": ""3""
}", json);
        }
Beispiel #26
0
        public ProjectState(ProjectInfo projectInfo, HostLanguageServices languageServices, SolutionServices solutionServices)
        {
            Contract.ThrowIfNull(projectInfo);
            Contract.ThrowIfNull(languageServices);
            Contract.ThrowIfNull(solutionServices);

            _languageServices = languageServices;
            _solutionServices = solutionServices;

            var projectInfoFixed = FixProjectInfo(projectInfo);

            // We need to compute our AnalyerConfigDocumentStates first, since we use those to produce our DocumentStates
            _analyzerConfigDocumentStates = ImmutableSortedDictionary.Create <DocumentId, AnalyzerConfigDocumentState>(DocumentIdComparer.Instance);
            _lazyAnalyzerConfigSet        = ComputeAnalyzerConfigSetValueSource(_analyzerConfigDocumentStates.Values);

            _documentIds           = projectInfoFixed.Documents.Select(d => d.Id).ToImmutableList();
            _additionalDocumentIds = projectInfoFixed.AdditionalDocuments.Select(d => d.Id).ToImmutableList();

            var parseOptions = projectInfoFixed.ParseOptions;
            var docStates    = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                     projectInfoFixed.Documents.Select(d =>
                                                                                                       new KeyValuePair <DocumentId, DocumentState>(d.Id,
                                                                                                                                                    CreateDocument(d, parseOptions))));

            _documentStates = docStates;

            var additionalDocStates = ImmutableSortedDictionary.CreateRange(DocumentIdComparer.Instance,
                                                                            projectInfoFixed.AdditionalDocuments.Select(d =>
                                                                                                                        new KeyValuePair <DocumentId, TextDocumentState>(d.Id, new TextDocumentState(d, solutionServices))));

            _additionalDocumentStates  = additionalDocStates;
            _lazyLatestDocumentVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentVersionAsync(docStates, additionalDocStates, c), cacheResult: true);
            _lazyLatestDocumentTopLevelChangeVersion = new AsyncLazy <VersionStamp>(c => ComputeLatestDocumentTopLevelChangeVersionAsync(docStates, additionalDocStates, c), cacheResult: true);

            // ownership of information on document has moved to project state. clear out documentInfo the state is
            // holding on. otherwise, these information will be held onto unnecesarily by projectInfo even after
            // the info has changed by DocumentState.
            // we hold onto the info so that we don't need to duplicate all information info already has in the state
            _projectInfo = ClearAllDocumentsFromProjectInfo(projectInfoFixed);

            _lazyChecksums = new AsyncLazy <ProjectStateChecksums>(ComputeChecksumsAsync, cacheResult: true);
        }
        public void Always_ShouldCorrectlyUpdatePairSettings()
        {
            //arrange
            var env = _testSuit.Build();

            env.Setup(b => b.RegisterType <ExtPriceSettingsController>().AsSelf());
            env.Setup(b => b.RegisterType <AssetPairsController>().AsSelf());
            var container                  = env.CreateContainer();
            var assetPairsController       = container.Resolve <AssetPairsController>();
            var extPriceSettingsController = container.Resolve <ExtPriceSettingsController>();

            var model = new AssetPairExtPriceSettingsModel
            {
                AssetPairId = "pair",
                Markups     = new AssetPairMarkupsParamsModel {
                    Bid = 1, Ask = 2
                },
                MinOrderbooksSendingPeriod = TimeSpan.FromMinutes(3),
                OutlierThreshold           = 4,
                PresetDefaultExchange      = "ex",
                RepeatedOutliers           = new RepeatedOutliersParamsModel
                {
                    MaxAvg            = 5,
                    MaxAvgAge         = TimeSpan.FromMinutes(6),
                    MaxSequenceLength = 7,
                    MaxSequenceAge    = TimeSpan.FromMinutes(8),
                },
                Steps = ImmutableSortedDictionary.Create <OrderbookGeneratorStepEnum, bool>()
                        .Add(OrderbookGeneratorStepEnum.FindOutliers, false),
            };

            //act
            assetPairsController.Add("pair", AssetPairQuotesSourceTypeDomainEnum.Disabled);
            env.Sleep(new TimeSpan(1));
            extPriceSettingsController.Update(model);
            var extractedModel = extPriceSettingsController.Get("pair");

            //assert
            model.Steps = GetDefaultSteps().SetItems(model.Steps);
            extractedModel.Should().BeEquivalentTo(model);
        }
Beispiel #28
0
        private static void TestSortedDictionaryImpl <T>(TypeModel model, string caption)
            where T : class, IImmutableCollectionWrapper, new()
        {
            var dict = new Dictionary <int, string> {
                { 1, "a" },
                { 3, "c" },
                { 2, "b" }
            };
            var obj = new T {
                SortedDictionary = ImmutableSortedDictionary.Create <int, string>().AddRange(dict)
            };

            using var ms = new MemoryStream();
            try
            {
                model.Serialize(ms, obj);
            }
            catch (Exception ex)
            {
                throw new ProtoException(caption + ":serialize", ex);
            }
            ms.Position = 0;
            T clone;

            try
            {
#pragma warning disable CS0618
                clone = (T)model.Deserialize(ms, null, typeof(T));
#pragma warning restore CS0618
            }
            catch (Exception ex)
            {
                throw new ProtoException(caption + ":deserialize", ex);
            }
            Assert.Equal(3, clone.SortedDictionary.Count); //, caption);
            Assert.Equal("a", clone.SortedDictionary[1]);  //, caption);
            Assert.Equal("b", clone.SortedDictionary[2]);  //, caption);
            Assert.Equal("c", clone.SortedDictionary[3]);  //, caption);
            AssertSequence(new[] { 1, 2, 3 }, clone.SortedDictionary.Keys, caption);
        }
Beispiel #29
0
        private static void TestSortedDictionaryImpl <T>(TypeModel model, string caption)
            where T : class, IImmutableCollectionWrapper, new()
        {
            var dict = new Dictionary <int, string>
            {
                { 1, "a" },
                { 3, "c" },
                { 2, "b" }
            };
            var obj = new T {
                SortedDictionary = ImmutableSortedDictionary.Create <int, string>().AddRange(dict)
            };

            model.ForceSerializationDuringClone = true;
            var clone = model.DeepClone(obj);

            Assert.AreEqual(3, clone.SortedDictionary.Count, caption);
            Assert.AreEqual("a", clone.SortedDictionary[1], caption);
            Assert.AreEqual("b", clone.SortedDictionary[2], caption);
            Assert.AreEqual("c", clone.SortedDictionary[3], caption);
            AssertSequence(new[] { 1, 2, 3 }, clone.SortedDictionary.Keys, caption);
        }
Beispiel #30
0
        public void Create()
        {
            IEnumerable <KeyValuePair <string, string> > pairs = new Dictionary <string, string> {
                { "a", "b" }
            };
            var keyComparer   = StringComparer.OrdinalIgnoreCase;
            var valueComparer = StringComparer.CurrentCulture;

            var dictionary = ImmutableSortedDictionary.Create <string, string>();

            Assert.Equal(0, dictionary.Count);
            Assert.Same(Comparer <string> .Default, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.Create <string, string>(keyComparer);
            Assert.Equal(0, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.Create(keyComparer, valueComparer);
            Assert.Equal(0, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(valueComparer, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.CreateRange(pairs);
            Assert.Equal(1, dictionary.Count);
            Assert.Same(Comparer <string> .Default, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.CreateRange(keyComparer, pairs);
            Assert.Equal(1, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(EqualityComparer <string> .Default, dictionary.ValueComparer);

            dictionary = ImmutableSortedDictionary.CreateRange(keyComparer, valueComparer, pairs);
            Assert.Equal(1, dictionary.Count);
            Assert.Same(keyComparer, dictionary.KeyComparer);
            Assert.Same(valueComparer, dictionary.ValueComparer);
        }