Beispiel #1
0
        public void Setup()
        {
            _anagramsService    = Substitute.For <IAnagramsService>();
            _anagramsController = new AnagramsController(_anagramsService);

            _anagramsController.ControllerContext             = new ControllerContext();
            _anagramsController.ControllerContext.HttpContext = new DefaultHttpContext();
            _anagramsController.ControllerContext.HttpContext.Connection.RemoteIpAddress =
                new IPAddress(new byte[] { 127, 0, 0, 1 });
        }
        public void Setup()
        {
            _cookiesHandlerServiceMock = Substitute.For <ICookiesHandlerService>();
            _userLogServiceMock        = Substitute.For <IUserLogService>();
            _wordServiceMock           = Substitute.For <IWordService>();
            _contextMock = Substitute.For <AnagramSolverCodeFirstContext>();

            _controller = new AnagramsController(
                _cookiesHandlerServiceMock, _wordServiceMock, _userLogServiceMock, _contextMock);

            _anagram = new Anagram()
            {
                Word = "word1", ID = 1, Category = "cat"
            };
            _anagramsList = new List <Anagram>()
            {
                _anagram
            };
        }
        public void UnitTestBaseSetUp()
        {
            Mock <IConfigurationSection> configurationSectionStub = new Mock <IConfigurationSection>();

            configurationSectionStub.Setup(x => x["DefaultConnection"]).Returns("TestConnectionString");
            Mock <IConfiguration> configurationStub = new Mock <IConfiguration>();

            configurationStub.Setup(x => x.GetSection("ConnectionStrings")).Returns(configurationSectionStub.Object);

            IServiceCollection services = new ServiceCollection();
            var target = new Startup(configurationStub.Object);

            target.ConfigureServices(services);
            services.AddTransient <CombinationsService>();

            var wwwrootPath            = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug\\netcoreapp2.1", string.Empty), "wwwroot");
            var mockHostingEnvironment = new Mock <IHostingEnvironment>();

            mockHostingEnvironment.SetupGet(x => x.WebRootPath).Returns(wwwrootPath);

            var serviceProvider = services.BuildServiceProvider();

            _controller = new AnagramsController(mockHostingEnvironment.Object, serviceProvider.GetService <CombinationsService>());
        }