示例#1
0
        public void If_adding_single_item_Then_expected_count_and_values_match()
        {
            _sut.Add(1, 1000);

            Assert.That(_sut.Count, Is.EqualTo(1));
            Assert.That(_sut.ContainsKey(1), Is.True);
            Assert.That(_sut.GetValues(1), Is.EquivalentTo(new[] { 1000 }));
            Assert.That(_sut.GetValuesAsHashSet(1), Is.EquivalentTo(new[] { 1000 }));
            Assert.That(_sut.Keys, Is.EquivalentTo(new[] { 1 }));
            Assert.That(_sut.Values, Is.EquivalentTo(new[] { 1000 }));
        }
示例#2
0
        public void If_addMany_with_key_and_no_values_Then_count_and_values_match()
        {
            _sut.AddMany(1, new int[0]);

            Assert.That(_sut.Count, Is.EqualTo(0));
            Assert.That(_sut.ContainsKey(0), Is.False);
            Assert.That(_sut.GetValues(1), Is.Empty);
            Assert.That(_sut.GetValuesAsHashSet(1), Is.Empty);
            Assert.That(_sut.Keys, Is.Empty);
            Assert.That(_sut.Values, Is.Empty);
        }
示例#3
0
        public void RegisterAllUniqueInterfaceImplementations(bool overwriteExistingRegistrations = false, params Assembly[] assemblies)
        {
            if (assemblies == null || !assemblies.Any())
            {
                assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(x => !x.IsDynamic).ToArray();
            }

            var classTypes = assemblies.SelectMany(x => x.GetTypes()).Where(x => !x.IsInterface && !x.IsAbstract).ToList();
            var interfaces = new HashSet <Type>(assemblies.SelectMany(x => x.GetTypes()).Where(x => x.IsInterface));

            var interfaceMap = new HashSetDictionary <Type, Type>();

            foreach (var classType in classTypes)
            {
                foreach (var interfaceType in classType.GetInterfaces().Where(x => interfaces.Contains(x)))
                {
                    interfaceMap.Add(interfaceType, classType);
                }
            }

            foreach (var interfaceType in interfaceMap.Keys)
            {
                var values = interfaceMap.GetValuesAsHashSet(interfaceType);
                if (values.Count != 1)
                {
                    continue;
                }

                if (overwriteExistingRegistrations || !_actions.ContainsKey(interfaceType))
                {
                    Register(interfaceType, values.First());
                }
            }
        }
        public void Then_count_and_values_match()
        {
            Assert.That(_sut.IsReadOnly, Is.False);

            Assert.That(_sut.Count, Is.EqualTo(0));
            Assert.That(_sut.ContainsKey(1), Is.False);

            Assert.That(_sut.GetValues(1), Is.Empty);
            Assert.That(_sut.GetValuesAsHashSet(1), Is.Empty);

            Assert.That(_sut.Keys, Is.Empty);
            Assert.That(_sut.Keys.IsReadOnly, Is.True);

            Assert.That(_sut.Values, Is.Empty);
            Assert.That(_sut.Values.IsReadOnly, Is.True);
        }