示例#1
0
        public void WhenAllInstancesOfATypeAreResolvedGenericallyItShouldReturnAllInstances()
        {
            // Arrange
            var expectedItemsList = new List <string> {
                "All", "Instances", "Are", "Retrieved"
            };
            var container = new ShifterContainer();

            container
            .AddInstance(typeof(int), 1)
            .AddInstance(typeof(string), "All")
            .AddInstance(typeof(int), 1)
            .AddInstance(typeof(string), "Instances")
            .AddInstance(typeof(int), 1)
            .AddInstance(typeof(string), "Are")
            .AddInstance(typeof(int), 1)
            .AddInstance(typeof(string), "Retrieved");

            // Act
            var resolveAll = container.ResolveAll <String>();

            // Assert
            resolveAll.Count().Should().Be(4, "because there are 4 instances registered.");
            resolveAll.Should().Contain(expectedItemsList);
        }
示例#2
0
        public void WhenResettingItShouldUnregisterAllInstancesOfThatType()
        {
            // Arrange
            var container = new ShifterContainer();

            container
            .AddInstance(typeof(int), 1234)
            .AddInstance(typeof(string), "Hello")
            .AddInstance(typeof(int), 2)
            .AddInstance(typeof(IShifterContainer), ShifterContainer.Default);

            // Act
            container.Reset();
            var resolvedInts      = container.ResolveAll <int>();
            var resolvedString    = container.ResolveAll <string>();
            var resolvedContainer = container.ResolveAll <IShifterContainer>();

            // Assert
            resolvedInts.Should().BeEmpty("because these ints are unregistered.");
            resolvedString.Should().BeEmpty("because these strings are unregistered.");
            resolvedContainer.Should().BeEmpty("because these containers are unregistered.");
        }
示例#3
0
        public void WhenUnregisteringATypeGenericallyItShouldUnregisterAllInstancesOfThatType()
        {
            // Arrange
            var container = new ShifterContainer();

            container
            .AddInstance(typeof(int), 1234)
            .AddInstance(typeof(string), "Hello")
            .AddInstance(typeof(int), 2)
            .AddInstance(typeof(IShifterContainer), ShifterContainer.Default);

            // Act
            container.Unregister <int>();
            var resolvedInts      = container.ResolveAll <int>();
            var resolvedString    = container.ResolveAll <string>();
            var resolvedContainer = container.ResolveAll <IShifterContainer>();

            // Assert
            resolvedInts.Should().BeEmpty("because these are unregistered.");
            resolvedString.Count().Should().Be(1, "because one string was left.");
            resolvedContainer.Count().Should().Be(1, "because one IShifterContainer was left.");
        }