Ejemplo n.º 1
0
        public ShareHandlerFixture()
        {
            _httpContext = MvcTestHelper.GetHttpContext();

            _redirector      = new Mock <ISocialServiceRedirector>();
            _storyRepository = new Mock <IStoryRepository>();

            resolver.Expect(r => r.Resolve <ISocialServiceRedirector>(It.IsAny <string>())).Returns(_redirector.Object);

            _handler = new ShareHandler {
                StoryRepository = _storyRepository.Object
            };
        }
        public BaseControllerFixture()
        {
            _formsAuthentication = new Mock <IFormsAuthentication>();
            _userRepository      = new Mock <IUserRepository>();

            _controller = new BaseControllerTestDouble
            {
                Settings            = settings.Object,
                FormsAuthentication = _formsAuthentication.Object,
                UserRepository      = _userRepository.Object
            };

            _httpContext = _controller.MockHttpContext();
        }
        public SupportControllerFixture()
        {
            _emailSender     = new Mock <IEmailSender>();
            _storyRepository = new Mock <IStoryRepository>();
            _userRepository  = new Mock <IUserRepository>();

            _controller = new SupportController(_storyRepository.Object, _emailSender.Object)
            {
                Settings       = settings.Object,
                UserRepository = _userRepository.Object
            };

            _httpContext = _controller.MockHttpContext("/Kigg", null, null);
            _httpContext.HttpRequest.ExpectGet(r => r.UserHostAddress).Returns("192.168.0.1");
        }
Ejemplo n.º 4
0
        public TagControllerFixture()
        {
            _user = new Mock <IUser>();

            _userRepository = new Mock <IUserRepository>();
            _userRepository.Setup(r => r.FindByUserName(It.IsAny <string>())).Returns(_user.Object);

            _tagRepository = new Mock <ITagRepository>();
            _controller    = new TagController(_tagRepository.Object)
            {
                Settings       = settings.Object,
                UserRepository = _userRepository.Object
            };

            _httpContext = _controller.MockHttpContext();
        }
        public BaseControllerFixture()
        {
            _formsAuthentication = new Mock <IFormsAuthentication>();
            _userRepository      = new Mock <IUserRepository>();
            _storyRepository     = new Mock <IStoryRepository>();

            _storyRepository.Setup(r => r.CountByUpcoming()).Returns(0);
            _controller = new BaseControllerTestDouble
            {
                Settings            = settings.Object,
                FormsAuthentication = _formsAuthentication.Object,
                UserRepository      = _userRepository.Object,
                StoryRepository     = _storyRepository.Object
            };

            _httpContext = _controller.MockHttpContext();
        }
Ejemplo n.º 6
0
        public IPBlockFixture()
        {
            const string BlockedIP = "192.168.0.1";

            file.Expect(f => f.ReadAllText(It.IsAny <string>())).Returns(string.Empty);

            var collection = new Mock <IBlockedIPCollection>();

            collection.Expect(c => c.Contains(BlockedIP)).Returns(true);
            resolver.Expect(r => r.Resolve <IBlockedIPCollection>()).Returns(collection.Object);

            _httpContext = MvcTestHelper.GetHttpContext();

            _httpContext.HttpRequest.ExpectGet(r => r.UserHostAddress).Returns(BlockedIP);
            _httpContext.HttpRequest.ExpectGet(r => r.Url).Returns(new Uri("http://dotnetshoutout.com/Upcoming"));

            _module = new IPBlock();
        }
Ejemplo n.º 7
0
        public void OnResultExecuted_Should_Compress_Response_When_Exception_Occurred_But_Exception_Is_Handled()
        {
            HttpContextMock       httpContext       = MvcTestHelper.GetHttpContext();
            ControllerContext     controllerContext = new ControllerContext(httpContext.Object, new RouteData(), new Mock <ControllerBase>().Object);
            ResultExecutedContext executedContext   = new ResultExecutedContext(controllerContext, new EmptyResult(), false, new Exception())
            {
                ExceptionHandled = true
            };

            httpContext.HttpRequest.Object.Headers.Add("Accept-Encoding", "gzip");
            httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            httpContext.HttpResponse.SetupGet(r => r.Filter).Returns(new MemoryStream());
            httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
            httpContext.HttpResponse.SetupSet(r => r.Filter = It.IsAny <Stream>());

            _attribute.OnResultExecuted(executedContext);

            httpContext.Verify();
        }
Ejemplo n.º 8
0
        public SupportControllerFixture()
        {
            _emailSender              = new Mock <IEmailSender>();
            _storyRepository          = new Mock <IStoryRepository>();
            _userRepository           = new Mock <IUserRepository>();
            _upcommingEventRepository = new Mock <ICommingEventRepository>();

            _controller = new SupportController(_storyRepository.Object, _emailSender.Object, _upcommingEventRepository.Object)
            {
                Settings        = settings.Object,
                UserRepository  = _userRepository.Object,
                StoryRepository = _storyRepository.Object
            };

            _storyRepository.Setup(x => x.CountByUpcoming()).Returns(0);

            _httpContext = _controller.MockHttpContext("/Kigg", null, null);
            _httpContext.HttpRequest.SetupGet(r => r.UserHostAddress).Returns("192.168.0.1");
        }
Ejemplo n.º 9
0
        public CommentControllerFixture()
        {
            RouteTable.Routes.Clear();
            new RegisterRoutes(settings.Object).Execute();

            _userRepository = new Mock <IUserRepository>();

            _reCAPTCHA = new Mock <reCAPTCHAValidator>("http://api-verify.recaptcha.net/verify", "http://api.recaptcha.net", "https://api-secure.recaptcha.net", "bar", "bar", "hello", "world", new Mock <IHttpForm>().Object);

            _storyRepository = new Mock <IStoryRepository>();
            _storyService    = new Mock <IStoryService>();

            _controller = new CommentController(_storyRepository.Object, _storyService.Object)
            {
                Settings            = settings.Object,
                FormsAuthentication = new Mock <IFormsAuthentication>().Object,
                UserRepository      = _userRepository.Object,
                CaptchaValidator    = _reCAPTCHA.Object
            };

            _httpContext = _controller.MockHttpContext();
        }
Ejemplo n.º 10
0
        public void OnResultExecuted_Should_Compress_Response(string encoding)
        {
            HttpContextMock       httpContext       = MvcTestHelper.GetHttpContext();
            ControllerContext     controllerContext = new ControllerContext(httpContext.Object, new RouteData(), new Mock <ControllerBase>().Object);
            ResultExecutedContext executedContext   = new ResultExecutedContext(controllerContext, new EmptyResult(), false, null);

            httpContext.HttpRequest.Object.Headers.Add("Accept-Encoding", encoding);

            if (!string.IsNullOrEmpty(encoding))
            {
                httpContext.HttpResponse.SetupGet(r => r.Filter).Returns(new MemoryStream());
                httpContext.HttpResponse.Setup(r => r.AppendHeader(It.IsAny <string>(), It.IsAny <string>())).Verifiable();
                httpContext.HttpResponse.SetupSet(r => r.Filter = It.IsAny <Stream>());
            }

            _attribute.OnResultExecuted(executedContext);

            if (!string.IsNullOrEmpty(encoding))
            {
                httpContext.Verify();
            }
        }
Ejemplo n.º 11
0
 public ErrorHandlerFixture()
 {
     _httpContext = MvcTestHelper.GetHttpContext();
     _handler     = new ErrorHandler();
 }
 public HtmlHelperExtensionFixture()
 {
     _httpContext = MvcTestHelper.GetHttpContext(AppPath, null, null);
 }
Ejemplo n.º 13
0
        public SiteMapHandlerFixture()
        {
            RouteTable.Routes.Clear();
            new RegisterRoutes(settings.Object).Execute();

            var userRepository     = new Mock <IUserRepository>();
            var storyRepository    = new Mock <IStoryRepository>();
            var categoryRepository = new Mock <ICategoryRepository>();
            var tagRepository      = new Mock <ITagRepository>();

            List <IUser> topMovers = new List <IUser>();

            for (int i = 1; i <= settings.Object.TopUsers; i++)
            {
                var user = new Mock <IUser>();

                user.ExpectGet(u => u.Id).Returns(Guid.NewGuid());
                user.ExpectGet(u => u.UserName).Returns("Top Mover {0}".FormatWith(i));

                topMovers.Add(user.Object);
            }

            userRepository.Expect(r => r.FindTop(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>())).Returns(new PagedResult <IUser>(topMovers, settings.Object.TopUsers));

            Func <string, Mock <IStory> > createStory = name =>
            {
                var category = new Mock <ICategory>();
                category.ExpectGet(c => c.Name).Returns("Dummy");

                var tag = new Mock <ITag>();
                tag.ExpectGet(t => t.Name).Returns("Dummy");

                var story = new Mock <IStory>();
                story.ExpectGet(s => s.BelongsTo).Returns(category.Object);
                story.ExpectGet(s => s.UniqueName).Returns(name);
                story.ExpectGet(s => s.Tags).Returns(new List <ITag> {
                    tag.Object
                });
                story.ExpectGet(s => s.TagCount).Returns(1);

                return(story);
            };

            List <IStory> publishedStories = new List <IStory>();

            for (int i = 1; i <= 50; i++)
            {
                var story = createStory("Published Story {0}".FormatWith(i));

                story.ExpectGet(s => s.PublishedAt).Returns(Constants.ProductionDate);

                publishedStories.Add(story.Object);
            }

            List <IStory> upcomingStories = new List <IStory>();

            for (int i = 1; i <= 50; i++)
            {
                var story = createStory("Upcoming Story {0}".FormatWith(i));

                upcomingStories.Add(story.Object);
            }

            storyRepository.Expect(r => r.FindPublished(It.IsAny <int>(), It.IsAny <int>())).Returns(new PagedResult <IStory>(publishedStories, 1000));
            storyRepository.Expect(r => r.FindUpcoming(It.IsAny <int>(), It.IsAny <int>())).Returns(new PagedResult <IStory>(upcomingStories, 1000));

            storyRepository.Expect(r => r.CountByPublished()).Returns(300);
            storyRepository.Expect(r => r.CountByUpcoming()).Returns(100);

            List <ICategory> categories = new List <ICategory>();

            for (int i = 1; i <= 10; i++)
            {
                var category = new Mock <ICategory>();

                category.ExpectGet(c => c.UniqueName).Returns("Category {0}".FormatWith(i));

                categories.Add(category.Object);
            }

            categoryRepository.Expect(r => r.FindAll()).Returns(new ReadOnlyCollection <ICategory>(categories));
            storyRepository.Expect(r => r.CountByCategory(It.IsAny <Guid>())).Returns(5);

            List <ITag> tags = new List <ITag>();

            for (int i = 1; i <= settings.Object.TopTags; i++)
            {
                var tag = new Mock <ITag>();

                tag.ExpectGet(t => t.UniqueName).Returns("Tag {0}".FormatWith(i));

                tags.Add(tag.Object);
            }

            tagRepository.Expect(r => r.FindByUsage(It.IsAny <int>())).Returns(new ReadOnlyCollection <ITag>(tags));
            storyRepository.Expect(r => r.CountByTag(It.IsAny <Guid>())).Returns(5);

            _httpContext = MvcTestHelper.GetHttpContext("/Kigg", null, null);

            _handler = new SiteMapHandler
            {
                Settings               = settings.Object,
                UserRepository         = userRepository.Object,
                CategoryRepository     = categoryRepository.Object,
                TagRepository          = tagRepository.Object,
                StoryRepository        = storyRepository.Object,
                PublishedStoryMaxCount = 5,
                UpcomingStoryMaxCount  = 5,
                CacheDurationInMinutes = 45,
                Compress               = true,
                GenerateETag           = true
            };
        }
Ejemplo n.º 14
0
 public BaseHttpModuleFixture()
 {
     _httpContext = MvcTestHelper.GetHttpContext();
     _module      = new BaseHttpModuleTestDouble();
 }