Exemplo n.º 1
0
        public void CreateGetKeysValuesCopyEnumerate()
        {
            var sRepo = new SourceRepository();

            Assert.True(sRepo.IsReadOnly == false);
            Assert.True(sRepo.Count == 0);

            var        mockLog = new Mock <ILog>();
            var        source1 = new CodeCoverageStringTextSource("abc", "", mockLog.Object);
            const uint fileId1 = 1;

            sRepo.Add(fileId1, source1);
            Assert.True(sRepo.Count == 1);
            Assert.True(sRepo.Keys.Count == 1);
            Assert.True(sRepo.Values.Count == 1);

            var        source2 = new CodeCoverageStringTextSource("def", "", mockLog.Object);
            const uint fileId2 = 2;

            sRepo.Add(fileId2, source2);
            Assert.True(sRepo.Count == 2);

            var array = new KeyValuePair <uint, CodeCoverageStringTextSource> [2];

            Assert.That(delegate { sRepo.CopyTo(array, 0); }, Throws.Nothing);

            // IDictionary is not ordered
            Assert.True(array[0].Key == fileId1 || array[1].Key == fileId2);
            Assert.True(array[0].Value == source1 || array[1].Value == source2);

            Assert.True(array[1].Key != default(uint));
            Assert.True(array[1].Value != default(CodeCoverageStringTextSource));

            // covers generic enumerator
            int count = 0;

            foreach (var item in sRepo)
            {
                Assert.True(item.Key != default(uint));
                Assert.True(item.Value != default(CodeCoverageStringTextSource));
                count += 1;
            }
            Assert.True(count == 2);

            // covers GetEnumerator
            count = 0;
            var e = ((IEnumerable)sRepo).GetEnumerator();

            while (e.MoveNext())
            {
                count += 1;
            }
            Assert.True(count == 2);
        }