Ejemplo n.º 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);
        }
Ejemplo n.º 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.");
        }
Ejemplo n.º 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.");
        }