示例#1
0
            public void GivenSomeQuestionsAndAnExistingPartialTag_Search_ReturnsAListOfTaggedQuestions()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable> {
                    FakeQuestions.CreateFakeQuestions()
                };
                IndexesToExecute = new List <Type> {
                    typeof(RecentPopularTags)
                };

                const string tag            = "ravne"; // Hardcoded Typo.
                var          homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                var result = homeController.Search(tag) as JsonResult;

                // Assert.
                Assert.NotNull(result);

                dynamic model = result.Data;

                Assert.NotNull(model);
                Assert.Equal(1, model.Count);
                Assert.Equal("ravendb", model[0]);
            }
        public static void CreateSeedData(IDocumentStore documentStore)
        {
            Condition.Requires(documentStore).IsNotNull();

            using (IDocumentSession documentSession = documentStore.OpenSession())
            {
                // First, check to make sure we don't have any data.
                var user = documentSession.Load <User>(1);
                if (user != null)
                {
                    // ooOooo! we have a user, so it's assumed we actually have some seeded data.
                    return;
                }

                // We have no users, so it's assumed we therefore have no data at all.
                // So lets fake some up :)

                // Users.
                ICollection <User> users = FakeUsers.CreateFakeUsers(50);
                StoreFakeEntities(users, documentSession);

                // Questions.
                ICollection <Question> questions = FakeQuestions.CreateFakeQuestions(users.Select(x => x.Id).ToList());
                StoreFakeEntities(questions, documentSession);

                documentSession.SaveChanges();

                // Make sure all our indexes are not stale.
                documentStore.WaitForStaleIndexesToComplete();
            }
        }
示例#3
0
            public void GivenSomeQuestionsAndAnExistingTag_Tags_ReturnsAListOfTaggedQuestions()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable> {
                    FakeQuestions.CreateFakeQuestions()
                };

                const string tag            = "ravendb";
                var          homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                var result = homeController.Tag(tag) as JsonResult;

                // Assert.
                Assert.NotNull(result);

                dynamic model = result.Data;

                Assert.NotNull(model);

                // At least 5 questions are hardcoded to include the RavenDb tag.
                Assert.NotNull(model.Questions);
                Assert.True(model.Questions.Count >= 5);
                Assert.True(model.TotalResults >= 5);
            }
示例#4
0
            public void GivenSomeQuestions_Index_ReturnsTheMostRecentQuestions()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable> {
                    FakeQuestions.CreateFakeQuestions()
                };
                IndexesToExecute = new List <Type> {
                    typeof(Questions_Search), typeof(RecentPopularTags)
                };

                var homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                var result = homeController.Index(null, null) as ViewResult;

                // Assert.
                Assert.NotNull(result);

                var model = result.Model as IndexViewModel;

                Assert.NotNull(model);
                Assert.NotNull(model.QuestionListViewModel);
                Assert.NotNull(model.QuestionListViewModel.Questions);
                Assert.Equal(20, model.QuestionListViewModel.Questions.Count);

                // Make sure all the items are ordered correctly.
                DateTime?previousQuestion = null;

                foreach (QuestionWithDisplayName question in model.QuestionListViewModel.Questions)
                {
                    if (previousQuestion.HasValue)
                    {
                        Assert.True(previousQuestion.Value >= question.CreatedOn);
                    }

                    previousQuestion = question.CreatedOn;
                }

                // Now lets test that our fixed questions come back correctly.
                List <Question> fixedQuestions = FakeQuestions.CreateFakeQuestions(null, 5).ToList();

                for (int i = 0; i < 5; i++)
                {
                    // Can Assert anything except
                    // * Id (these new fakes haven't been Stored)
                    // * CreatedByUserId - this is randomized when fakes are created.
                    // * CreatedOn - these fakes were made AFTER the Stored data.
                    // ASSUMPTION: the first 5 fixed questions are the first 5 documents in the Document Store.
                    QuestionWithDisplayName question = model.QuestionListViewModel.Questions[i];
                    Assert.Equal(fixedQuestions[i].Subject, question.Subject);
                    Assert.Equal(fixedQuestions[i].Content, question.Content);
                    Assert.Equal(fixedQuestions[i].NumberOfViews, question.NumberOfViews);
                    Assert.Equal(fixedQuestions[i].Vote.DownVoteCount, question.Vote.DownVoteCount);
                    Assert.Equal(fixedQuestions[i].Vote.FavoriteCount, question.Vote.FavoriteCount);
                    Assert.Equal(fixedQuestions[i].Vote.UpVoteCount, question.Vote.UpVoteCount);
                }
            }
示例#5
0
        // ReSharper disable InconsistentNaming
        public void GivenSomeQuestions_Index_ReturnsTheMostRecentQuestions()
        // ReSharper restore InconsistentNaming
        {
            using (IDocumentSession documentSession = DocumentStore.OpenSession())
            {
                // Arrange.
                HomeController homeController = HomeController(documentSession);

                // Act.
                var result = homeController.Index(null, null) as ViewResult;

                // Assert.
                Assert.IsNotNull(result);

                var model = result.Model as IndexViewModel;
                Assert.IsNotNull(model);

                CollectionAssert.AllItemsAreNotNull(model.Questions);
                Assert.AreEqual(20, model.Questions.Count);

                // Make sure all the items are ordered correctly.
                DateTime?previousQuestion = null;
                foreach (Question question in model.Questions)
                {
                    if (previousQuestion.HasValue)
                    {
                        Assert.IsTrue(previousQuestion.Value >= question.CreatedOn);
                    }

                    previousQuestion = question.CreatedOn;
                }

                // Now lets test that our fixed questions come back correctly.
                List <Question> fixedQuestions = FakeQuestions.CreateFakeQuestions(null, 5).ToList();
                for (int i = 0; i < 5; i++)
                {
                    // Can Assert anything except
                    // * Id (these new fakes haven't been Stored)
                    // * CreatedByUserId - this is randomized when fakes are created.
                    // * CreatedOn - these fakes were made AFTER the Stored data.
                    // ASSUMPTION: the first 5 fixed questions are the first 5 documents in the Document Store.
                    Assert.AreEqual(fixedQuestions[i].Subject, model.Questions[i].Subject);
                    Assert.AreEqual(fixedQuestions[i].Content, model.Questions[i].Content);
                    Assert.AreEqual(fixedQuestions[i].NumberOfViews, model.Questions[i].NumberOfViews);
                    Assert.AreEqual(fixedQuestions[i].Vote.DownVoteCount, model.Questions[i].Vote.DownVoteCount);
                    Assert.AreEqual(fixedQuestions[i].Vote.FavoriteCount, model.Questions[i].Vote.FavoriteCount);
                    Assert.AreEqual(fixedQuestions[i].Vote.UpVoteCount, model.Questions[i].Vote.UpVoteCount);
                }
            }
        }
示例#6
0
            public void GivenSomeQuestionsAndNoDisplayNameAndNoTags_Index_ReturnsAJsonViewOfMostRecentQuestions()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable>
                {
                    FakeQuestions.CreateFakeQuestions(new[] { "users/1", "users/2", "users/3" }),
                    FakeUsers.CreateFakeUsers()
                };
                IndexesToExecute = new List <Type> {
                    typeof(Questions_Search)
                };

                var homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                // Note: this should return a list of the 20 most recent.
                JsonResult result = homeController.IndexJson(null, null);

                // Assert.
                Assert.NotNull(result);
                var questions = result.Data as IList <QuestionWithDisplayName>;

                Assert.NotNull(questions);
                Assert.Equal(20, questions.Count);

                // Now lets Make sure each one is ok.
                DateTime?previousDate = null;

                foreach (QuestionWithDisplayName question in questions)
                {
                    if (previousDate.HasValue)
                    {
                        Assert.True(previousDate.Value > question.CreatedOn);
                    }

                    previousDate = question.CreatedOn;
                    Assert.NotNull(question.DisplayName);
                    Assert.NotNull(question.Id);
                    Assert.NotNull(question.CreatedByUserId);
                    Assert.NotNull(question.Subject);
                    Assert.NotNull(question.Content);
                }
            }
示例#7
0
        private static void CreateSeedData(IDocumentStore documentStore)
        {
            Condition.Requires(documentStore).IsNotNull();

            // Users.
            ICollection <User> users = FakeUsers.CreateFakeUsers(50);

            // Questions.
            ICollection <Question> questions = FakeQuestions.CreateFakeQuestions(users.Select(x => x.Id).ToList());

            using (IDocumentSession documentSession = documentStore.OpenSession())
            {
                StoreFakeEntities(users, documentSession);
                StoreFakeEntities(questions, documentSession);

                documentSession.SaveChanges();
            }
        }
示例#8
0
        private static void SeedDocumentStore(IDocumentStore documentStore)
        {
            using (var session = documentStore.OpenSession())
            {
                // Don't add any seed data, if we already have some data in the system.
                var user = session.Query <User>().Take(1).ToList();
                if (user.Any())
                {
                    return;
                }

                var users = FakeUsers.CreateFakeUsers();

                StoreEntites(session, users);

                StoreEntites(session, FakeQuestions.CreateFakeQuestions(users.Select(x => x.Id).ToList()));

                session.SaveChanges();
            }
        }
示例#9
0
            public void GivenSomeQuestions_Index_ReturnsTheMostRecentPopularTagsInTheLast30Days()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable> {
                    FakeQuestions.CreateFakeQuestions()
                };
                IndexesToExecute = new List <Type> {
                    typeof(Questions_Search), typeof(RecentPopularTags)
                };

                var homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController);

                // Act.
                var result = homeController.Index(null, null) as ViewResult;

                // Assert.
                Assert.NotNull(result);

                var model = result.Model as IndexViewModel;

                Assert.NotNull(model);

                Assert.NotNull(model.RecentPopularTags);
                Assert.True(model.RecentPopularTags.Count > 0);

                // Make sure all the items are ordered correctly.
                int?previousCount = null;

                foreach (var keyValuePair in model.RecentPopularTags)
                {
                    if (previousCount.HasValue)
                    {
                        Assert.True(previousCount.Value >= keyValuePair.Value);
                    }

                    previousCount = keyValuePair.Value;
                }
            }
示例#10
0
            public void GivenAnAuthenticatedUserWithSomeFavouriteTags_Index_ReturnsAFavouriteTagsViewModelWithContent()
            {
                // Arrange.
                DataToBeSeeded = new List <IEnumerable>
                {
                    FakeQuestions.CreateFakeQuestions(),
                        FakeUsers.CreateFakeUsers()
                };

                IndexesToExecute = new List <Type> {
                    typeof(Questions_Search), typeof(RecentPopularTags)
                };

                // Note: we're faking that a user has authenticated.
                var homeController = new HomeController(DocumentSession, new CustomFormsAuthentication());

                ControllerUtilities.SetUpControllerContext(homeController, displayName: "Pure.Krome");


                // Act.
                var result = homeController.Index(null, null) as ViewResult;

                // Assert.
                Assert.NotNull(result);

                var model = result.Model as IndexViewModel;

                Assert.NotNull(model);

                UserTagListViewModel userFavoriteTagListViewModel = model.UserFavoriteTagListViewModel;

                Assert.NotNull(userFavoriteTagListViewModel);

                Assert.Equal("Favorite Tags", userFavoriteTagListViewModel.Header);
                Assert.Equal("interesting-tags", userFavoriteTagListViewModel.DivId1);
                Assert.Equal("interestingtags", userFavoriteTagListViewModel.DivId2);
                Assert.NotNull(userFavoriteTagListViewModel.Tags);
                Assert.Equal(3, userFavoriteTagListViewModel.Tags.Count);
            }