Пример #1
0
        public void ConfigureServices_GetLoggers()
        {
            IHostingEnvironment hostenv = new MockHostingEnvironment();

            Mock <NciStartupBase> mockStartup = new Mock <NciStartupBase>(hostenv)
            {
                CallBase = true
            };

            mockStartup.Protected().Setup("AddAdditionalConfigurationMappings", Moq.Protected.ItExpr.IsAny <IServiceCollection>());

            NciStartupBase startup = mockStartup.Object;

            IServiceCollection svcColl         = new ServiceCollection();
            IServiceProvider   serviceProvider = startup.ConfigureServices(svcColl);

            Object svc;

            svc = serviceProvider.GetService(typeof(ILogger <DefaultController>));
            Assert.NotNull(svc);
            Assert.IsAssignableFrom <Logger <DefaultController> >(svc);

            svc = serviceProvider.GetService(typeof(ILogger <ElasticClient>));
            Assert.NotNull(svc);
            Assert.IsAssignableFrom <Logger <ElasticClient> >(svc);
        }
Пример #2
0
        public void should_return_null_if_no_tags_is_supplied()
        {
            var mockEnv = new MockHostingEnvironment();

            var x = new AnimalService(mockEnv);

            var creatues = new List <Creature>
            {
                new Creature
                {
                    ImagePath    = "book.jpg",
                    CreatureTags = new List <CreatureTags>
                    {
                        new CreatureTags
                        {
                            Tag = new Tag
                            {
                                Name = "book"
                            }
                        }
                    }
                }
            };

            string matchingAnimal = x.GetAnimalUrlThatMatchesTags(new string[] { }, creatues);

            Assert.AreEqual(null, matchingAnimal);
        }
Пример #3
0
        public void should_return_creature_if_just_one_in_database_and_it_have_correct_tag()
        {
            var mockEnv = new MockHostingEnvironment();

            var x = new AnimalService(mockEnv);

            var creatues = new List <Creature>
            {
                new Creature
                {
                    ImagePath    = "book.jpg",
                    CreatureTags = new List <CreatureTags>
                    {
                        new CreatureTags
                        {
                            Tag = new Tag
                            {
                                Name = "book"
                            }
                        }
                    }
                }
            };

            string matchingAnimal = x.GetAnimalUrlThatMatchesTags(new [] { "book" }, creatues);

            Assert.AreEqual("book.jpg", matchingAnimal);
        }
    public void Constructor()
    {
      IHostingEnvironment hostenv = new MockHostingEnvironment();

      Mock<NciStartupBase> startup = new Mock<NciStartupBase>(hostenv){ CallBase = true };

      NciStartupBase mock = startup.Object;

      Assert.NotNull(mock.Configuration);
    }
Пример #5
0
        private KestrelServerOptions CreateServerOptions()
        {
            var serverOptions = new KestrelServerOptions();
            var env           = new MockHostingEnvironment {
                ApplicationName = "TestApplication", ContentRootPath = Directory.GetCurrentDirectory()
            };

            serverOptions.ApplicationServices = new ServiceCollection()
                                                .AddLogging()
                                                .AddSingleton <IHostEnvironment>(env)
                                                .BuildServiceProvider();
            return(serverOptions);
        }
        public async Task Create_POST_FailedResponse()
        {
            // arrange
            MockHostingEnvironment.Setup(x => x.WebRootPath).Returns("");
            MockLanguageService.Setup_CreateLanguage_Returns_LanguageCreateResponse_Failed();
            var model = GetLanguageOneCreateModel();

            // act
            var result = await SystemUnderTest.Create(model);

            // assert
            AssertErrorMessagesForInvalidOrFailedResponse <LanguageCreateModel>(result);
            MockLanguageService.Verify_CreateLanguage();
        }
        public async Task Create_POST()
        {
            // arrange
            MockHostingEnvironment.Setup(x => x.WebRootPath).Returns("");
            MockLanguageService.Setup_CreateLanguage_Returns_LanguageCreateResponse_Success();
            var model = GetLanguageOneCreateModel();

            // act
            var result = await SystemUnderTest.Create(model);

            // assert
            ((RedirectResult)result).Url.ShouldBe("/Language/List/");
            MockLanguageService.Verify_CreateLanguage();
        }
Пример #8
0
        public void ConfigureServices_ElasticsearchGoodConfiguration()
        {
            string appsettings = @"
{
    ""Elasticsearch"": {
        ""Servers"": ""http://localhost:9200"",
        ""Userid"": """",
        ""Password"": """",
        ""MaximumRetries"": 5
    }
  }
      ";

            // Create an appsettings.json in a location where only this test will see it.
            string        configLocation = Path.Join(Fixture.TestLocation, nameof(ConfigureServices_ElasticsearchGoodConfiguration));
            DirectoryInfo di             = Directory.CreateDirectory(configLocation);

            File.WriteAllText(Path.Join(configLocation, "appsettings.json"), appsettings);

            // Customize the hosting environment for this test.
            IHostingEnvironment hostenv = new MockHostingEnvironment();

            hostenv.ContentRootPath = configLocation;

            Mock <NciStartupBase> mockStartup = new Mock <NciStartupBase>(hostenv)
            {
                CallBase = true
            };

            NciStartupBase startup = mockStartup.Object;

            IServiceCollection svcColl         = new ServiceCollection();
            IServiceProvider   serviceProvider = startup.ConfigureServices(svcColl);

            Assert.NotNull(serviceProvider);

            Object svc = serviceProvider.GetService(typeof(IElasticClient));

            Assert.NotNull(svc);
            Assert.IsAssignableFrom <IElasticClient>(svc);
        }
Пример #9
0
        public void ConfigureServices_SubclassSetupServices()
        {
            IHostingEnvironment hostenv = new MockHostingEnvironment();

            Mock <NciStartupBase> mockStartup = new Mock <NciStartupBase>(hostenv)
            {
                CallBase = true
            };

            mockStartup.Protected().Setup("AddAdditionalConfigurationMappings", Moq.Protected.ItExpr.IsAny <IServiceCollection>());
            mockStartup.Protected().Setup("AddAppServices", Moq.Protected.ItExpr.IsAny <IServiceCollection>());

            NciStartupBase startup = mockStartup.Object;

            IServiceCollection svcColl         = new ServiceCollection();
            IServiceProvider   serviceProvider = startup.ConfigureServices(svcColl);

            // Verify the subclass had a chance to add services.
            mockStartup.Protected().Verify("AddAdditionalConfigurationMappings", Times.Once(), Moq.Protected.ItExpr.IsAny <IServiceCollection>());
            mockStartup.Protected().Verify("AddAppServices", Times.Once(), Moq.Protected.ItExpr.IsAny <IServiceCollection>());
        }
Пример #10
0
        public void ConfigureServices_ElasticsearchBadConfiguration()
        {
            IHostingEnvironment hostenv = new MockHostingEnvironment();

            Mock <NciStartupBase> mockStartup = new Mock <NciStartupBase>(hostenv)
            {
                CallBase = true
            };

            NciStartupBase startup = mockStartup.Object;

            IServiceCollection svcColl         = new ServiceCollection();
            IServiceProvider   serviceProvider = startup.ConfigureServices(svcColl);

            Assert.NotNull(serviceProvider);

            Exception ex = Assert.Throws <APIInternalException>(
                () => serviceProvider.GetService(typeof(IElasticClient))
                );

            Assert.Equal("No servers configured", ex.Message);
        }