Exemplo n.º 1
0
        public void AddItemTypesRegistersItemRegistry()
        {
            InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, this.itemRegistry);

            this.BuildServiceProvider();

            this.serviceProvider.GetRequiredService <IItemRegistry>().Should().Be(this.itemRegistry);
        }
Exemplo n.º 2
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);
        }
Exemplo 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"));
        }
Exemplo 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"));
        }
Exemplo n.º 5
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>();
        }
Exemplo n.º 6
0
        public void AddingNullRegistryToServiceCollectionWillThrowException()
        {
            Action act = () => InventoryDependencyExtensions.AddItemTypes(this.serviceCollection, null);

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

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