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();
            }
        }
Example #2
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);
                }
            }
Example #3
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();
            }
        }
Example #4
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();
            }
        }
Example #5
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);
            }