Ejemplo n.º 1
0
        public void GetItemMetaWillBeCalledOnce()
        {
            this.itemRegistryMock.Setup(x => x.GetItemMeta()).Returns(new ItemMeta[0]);

            InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, this.itemRegistryMock.Object);

            this.itemRegistryMock.Verify(x => x.GetItemMeta(), Times.Once);
        }
Ejemplo n.º 2
0
        public void AddItemTypesRegistersItemRegistry()
        {
            InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, this.itemRegistry);

            this.BuildServiceProvider();

            this.serviceProvider.GetRequiredService <IItemRegistry>().Should().Be(this.itemRegistry);
        }
Ejemplo n.º 3
0
        public void ReturningNullOnGetItemMetaWillThrowInvalidItemRegistryException()
        {
            this.itemRegistryMock
            .Setup(x => x.GetItemMeta())
            .Returns <IEnumerable <ItemMeta> >(null);

            Action act = () => InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, this.itemRegistryMock.Object);

            act.Should().Throw <InvalidItemRegistryException>()
            .Where(x => x.Message.Contains("returns") && x.Message.Contains("null"));
        }
Ejemplo n.º 4
0
        public void ReturningNullAsValueInItemRegistryShouldThrowException()
        {
            this.itemRegistryMock.Setup(x => x.GetItemMeta()).Returns(new ItemMeta[] { null });

            Action act = () => InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, this.itemRegistryMock.Object);

            act.Should().Throw <InvalidItemRegistryException>()
            .Where(x =>
                   x.Message.Contains(nameof(IItemRegistry.GetItemMeta)) &&
                   x.Message.Contains("contains") &&
                   x.Message.Contains("null") &&
                   x.Message.Contains("value"));
        }
Ejemplo n.º 5
0
        public void AddServicesExtensionRegistersNeededServices()
        {
            InventoryDependencyExtensions.AddDefaultInventoryServices(this.serviceCollection);

            this.AddItemRegistryMock();
            this.BuildServiceProvider();

            this.serviceProvider.GetRequiredService <IInventoryFactory>()
            .Should().BeOfType <InventoryFactory>();

            this.serviceProvider.GetRequiredService <IItemFactory>()
            .Should().BeOfType <ItemFactory>();
        }
Ejemplo n.º 6
0
        public void RegisteredItemsInItemRegistryWillBeResolvable()
        {
            var meta = this.itemRegistry.CreateItemMetaForward <FakeItem>("item", "Fake Item");

            this.SetupRegistryWithItems(meta);

            InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, this.itemRegistry);

            this.BuildServiceProvider();

            var factory = this.serviceProvider.GetRequiredService(typeof(FakeItem));

            factory.Should()
            .NotBeNull()
            .And.BeOfType <ObjectFactory>();

            var resolvedItem = ((ObjectFactory)factory)(this.serviceProvider, new [] { meta });

            resolvedItem.Should()
            .NotBeNull()
            .And.BeOfType <FakeItem>();
        }
Ejemplo n.º 7
0
        public void RunningAddServiceExtensionsOnNullThrowsArgumentNullException()
        {
            Action act = () => InventoryDependencyExtensions.AddDefaultInventoryServices(null);

            act.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 8
0
        public void RunningAddDefaultItemFactoryOnNullThrowsException()
        {
            Action act = () => InventoryDependencyExtensions.AddDefaultItemFactory(null);

            act.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 9
0
        public void AddingNullRegistryToServiceCollectionWillThrowException()
        {
            Action act = () => InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, null);

            act.Should().Throw <ArgumentNullException>();
        }
Ejemplo n.º 10
0
        public void AddingItemRegistryOnNullServiceCollectionWillThrowException()
        {
            Action act = () => InventoryDependencyExtensions.AddItemTypes(null, this.itemRegistryMock.Object);

            act.Should().Throw <ArgumentNullException>();
        }