Ejemplo n.º 1
0
        public async Task RetrieveDataSourceByName_GoodFlow()
        {
            // Arrange

            // Act
            Action             act = () => service.RetrieveDataSourceByName(It.IsAny <string>());
            IDataSourceAdaptee retrievedAdaptee = await service.RetrieveDataSourceByName(It.IsAny <string>());

            // Assert
            act.Should().NotThrow();
            retrievedAdaptee.Should().NotBeNull();
            retrievedAdaptee.Should().BeAssignableTo(typeof(IDataSourceAdaptee));
        }
Ejemplo n.º 2
0
        public async Task RetrieveDataSourceByName_NoDataSourceFound()
        {
            // Arrange
            loaderMock.Setup(_ => _.GetDataSourceByName(It.IsAny <string>()))
            .ReturnsAsync((IDataSourceAdaptee)null);

            // Act
            Action             act = () => service.RetrieveDataSourceByName(It.IsAny <string>());
            IDataSourceAdaptee retrievedAdaptee = await service.RetrieveDataSourceByName(It.IsAny <string>());

            // Assert
            act.Should().NotThrow();
            retrievedAdaptee.Should().BeNull();
        }
Ejemplo n.º 3
0
        public async Task GetDataSourceByName_NoDataSourceFound()
        {
            // Arrange
            assemblyHelperMock.Setup(_ => _.RetrieveTypesFromExecutingAssemblyFolderFolderByInterface(It.IsAny <Type>()))
            .Returns(new Type[0]);

            Mock <IServiceScope> scopeMock = new Mock <IServiceScope>();

            scopeMock
            .Setup(_ => _.ServiceProvider.GetService(It.IsAny <Type>()))
            .Returns((IDataSourceAdaptee)null);

            factoryMock.Setup(_ => _.CreateScope())
            .Returns(scopeMock.Object);

            // Act
            Action             act = () => loader.GetDataSourceByName(It.IsAny <string>());
            IDataSourceAdaptee retrievedDataSource = await loader.GetDataSourceByName(It.IsAny <string>());

            // Assert
            act.Should().NotThrow();
            retrievedDataSource.Should().BeNull();
            scopeMock.Verify(_ => _.ServiceProvider.GetService(It.IsAny <Type>()), Times.Exactly(0));
        }
Ejemplo n.º 4
0
        public async Task GetDataSourceByName_GoodFlow()
        {
            // Arrange
            returnedTypesFromAssembly = new Type[]
            {
                typeof(GithubDataSourceAdaptee)
            };

            assemblyHelperMock.Setup(_ => _.RetrieveTypesFromExecutingAssemblyFolderFolderByInterface(It.IsAny <Type>()))
            .Returns(returnedTypesFromAssembly);

            string name = "TestSource";

            returnedTypeFromLoader = new Mock <IDataSourceAdaptee>().As <IDataSourceAdaptee>();
            returnedTypeFromLoader.Setup(_ => _.Title)
            .Returns(name);

            Mock <IServiceScope> scopeMock = new Mock <IServiceScope>();

            scopeMock
            .Setup(_ => _.ServiceProvider.GetService(It.IsAny <Type>()))
            .Returns(returnedTypeFromLoader.Object);

            factoryMock.Setup(_ => _.CreateScope())
            .Returns(scopeMock.Object);

            // Act
            Action             act = () => loader.GetDataSourceByName(name);
            IDataSourceAdaptee retrievedDataSource = await loader.GetDataSourceByName(name);

            // Assert
            act.Should().NotThrow();
            retrievedDataSource.Should().NotBeNull();
            retrievedDataSource.Title.Should().Be(name);
            scopeMock.Verify(_ => _.ServiceProvider.GetService(It.IsAny <Type>()), Times.Exactly(2));
        }