public void Source_Then_SourceShouldBeSetAndItemsLoaded()
        {
            var testee = new ResourceDictionary();

            testee.Source = GetTesteeUri();

            testee.Source.Should().Be(GetTesteeUri());
            testee.MergedDictionaries.Should().NotBeEmpty().And.Subject.First().Should().NotBeEmpty();
            testee.IsFirstSourceReference.Should().BeTrue();
        }
        public void Indexer_Then_ResultShouldNotBeNull()
        {
            var testee = new ResourceDictionary {
                Source = GetTesteeUri()
            };

            var result = testee["Brush"];

            result.Should().NotBeNull();
        }
        public void Source_When_UriAlreadyLoaded_Then_MergedDictionariesShouldContainExpectedResourceDictionary()
        {
            var expectedResourceDictionary = new ResourceDictionary {
                Source = GetTesteeUri()
            };
            var testee = new ResourceDictionary();

            testee.Source = GetTesteeUri();

            testee.MergedDictionaries.Should().Contain(expectedResourceDictionary.MergedDictionaries.FirstOrDefault());
            expectedResourceDictionary.IsFirstSourceReference.Should().BeTrue();
            testee.IsFirstSourceReference.Should().BeFalse();
            ResourceDictionary.CachedDictionaries.Count.Should().Be(1);
        }
        public void Source_When_AlreadySet_Then_MergedDictionariesShouldNotContainOldDictionary()
        {
            var testee = new ResourceDictionary {
                Source = GetTesteeUri()
            };
            var oldMergedDictionary = testee.MergedDictionaries.FirstOrDefault();

            testee.Source = GetSecondUri();

            testee.MergedDictionaries.Should().NotContain(oldMergedDictionary);
            testee.MergedDictionaries.Should().NotBeEmpty();
            testee.IsFirstSourceReference.Should().BeTrue();
            ResourceDictionary.CachedDictionaries.Count.Should().Be(1);
        }
        public void TryRemoveFromCache_Then_CachedResourceDictionaryShouldNotLongerExistInCache()
        {
            var testee = new ResourceDictionary {
                Source = GetTesteeUri()
            };

            testee = null;
            GC.Collect(2, GCCollectionMode.Forced);
            GC.WaitForFullGCComplete();
            GC.WaitForPendingFinalizers();

            ResourceDictionary.TryRemoveFromCache(GetTesteeUri());

            ResourceDictionary.CachedDictionaries.Count.Should().Be(0);
        }
        public void Source_When_AlreadySetAndIsFirstReference_Then_MergedDictionariesShouldBeChangedToNewSource()
        {
            var testee = new ResourceDictionary {
                Source = GetTesteeUri()
            };
            var expectedResourceDictionary = new ResourceDictionary {
                Source = GetTesteeUri()
            };
            var oldExpectedIsFirstSourceReference = expectedResourceDictionary.IsFirstSourceReference;
            var firstMergedDictionary             = testee.MergedDictionaries.FirstOrDefault();

            testee.Source = GetSecondUri();

            firstMergedDictionary.Should().NotBeNull();
            testee.MergedDictionaries.Should().NotContain(firstMergedDictionary);
            testee.MergedDictionaries.Should().NotContain(expectedResourceDictionary.MergedDictionaries.FirstOrDefault());
            testee.MergedDictionaries.Should().NotBeEmpty().And.Subject.Should().NotBeEmpty();
            testee.IsFirstSourceReference.Should().BeTrue();
            oldExpectedIsFirstSourceReference.Should().BeFalse();
            expectedResourceDictionary.IsFirstSourceReference.Should().BeTrue();
            ResourceDictionary.CachedDictionaries.Count.Should().Be(2);
        }