public void ShouldGoToShowTopicOnCreateWithNoId()
 {
     var view = _repository.DynamicMock<ITopicFormView>();
     var provider = _repository.DynamicMock<ITopicProvider>();
     var loader = default(IEventRaiser);
     var creator = default(IEventRaiser);
     var input = new TopicInput
                     {
                         ForumId = 1423,
                         Title = "New Topic",
                         Body = "New topic body",
                         Sticky = false
                     };
     var data = new TopicMapper().FromInput(input);
     var newId = 321;
     With.Mocks(_repository).
         ExpectingInSameOrder(() =>
                                  {
                                      view.Load += null;
                                      loader = LastCall.IgnoreArguments().GetEventRaiser();
                                      view.Create += null;
                                      creator = LastCall.IgnoreArguments().GetEventRaiser();
                                      Expect.Call(view.IsPostBack).Return(true);
                                      Expect.Call(view.IsValid).Return(true);
                                      Expect.Call(view.Topic).Return(input);
                                      Expect.Call(provider.Create(data)).IgnoreArguments().Return(newId);
                                      Expect.Call(() => view.GoToShowTopic(newId));
                                  }).
         Verify(() =>
                    {
                        new TopicFormPresenter(view, provider);
                        loader.Raise(null, new EventArgs());
                        creator.Raise(null, new EventArgs());
                    });
 }
示例#2
0
        public TopicDetailModel GetById(Guid id)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var topic = teamCommunicationDbContext.Topics.Include(e => e.Team).Include(e => e.User).First(c => c.Id == id);

                return(TopicMapper.MapTopicEntityToDetailModel(topic));
            }
        }
示例#3
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            IEnumerable <UserTopicViewModel> topics = uow.TopicRepository
                                                      .Get(null, null, "Subscriptions,Posts,Posts.Author")
                                                      .ToList()
                                                      .Select(t => TopicMapper.Map(t, userId, t.Posts));

            return(View(topics.ToList()));
        }
示例#4
0
        public ActionResult Index()
        {
            var topics = uow.TopicRepository
                         .Get(includeProperties: "Posts,Posts.Author,Subscriptions")
                         .ToList();

            if (currentUser.IsLoggedIn())
            {
                return(RedirectToAction("Index", "NewsFeed"));
            }
            else
            {
                return(View(topics.Select(t => TopicMapper.Map(t)).ToList()));
            }
        }
示例#5
0
        public ActionResult Details(string name, string query)
        {
            if (query == null)
            {
                query = "";
            }

            query = query.ToLower();

            var topic = uow.TopicRepository
                        .Get(
                filter: t => t.Name.ToLower() == name,
                includeProperties: "Subscriptions,Posts.Author"
                )
                        .FirstOrDefault();


            if (topic == null)
            {
                throw new TopicNotFoundException(name);
            }

            Expression <Func <PostModel, bool> > postsFilter = p =>
                                                               p.TopicName.ToLower() == name.ToLower() &&
                                                               (p.Title.ToLower().Contains(query) ||
                                                                p.Content.ToLower().Contains(query) ||
                                                                p.Author.UserName.ToLower().Contains(query) ||
                                                                p.TopicName.ToLower().Contains(query));

            if (currentUser.IsLoggedIn())
            {
                var userId = User.Identity.GetUserId();
                var user   = uow.UserRepository.GetByID(userId);

                var posts = uow.PostRepository.Get(postsFilter, p => p.OrderByDescending(post => post.PostedAt), "Author");


                return(View(TopicMapper.Map(topic, userId, posts.ToList())));
            }


            return(View(TopicMapper.Map(new Entities.Topic.TopicModel
            {
                Posts = uow.PostRepository.Get(postsFilter).Where(p => p.TopicName == name).ToList(),
                Name = name,
                Subscriptions = topic.Subscriptions
            })));
        }
 public void ShouldMapTopicEntityToInput()
 {
     // Arrange
     var data = new Topic
                    {
                        Id = 4132,
                        Forum = new Core.Models.Forum {Id = 1422},
                        Sticky = false,
                        Title = "ToInput name",
                        Body = "ToInput body"
                    };
     // Act
     var input = new TopicMapper().ToInput(data);
     // Assert
     Assert.AreEqual(data.Id, input.Id);
     Assert.AreEqual(data.Forum.Id, input.ForumId);
     Assert.AreEqual(data.Sticky, input.Sticky);
     Assert.AreEqual(data.Title, input.Title);
     Assert.AreEqual(data.Body, input.Body);
 }
 public void ShouldMapTopicEntityFromInput()
 {
     // Arrange
     var input = new TopicInput
                     {
                         Id = 1423, 
                         ForumId = 1411, 
                         Sticky = true, 
                         Title = "FromInput name",
                         Body = "FromInput body"
                     };
     // Act
     var data = new TopicMapper().FromInput(input);
     // Assert
     Assert.AreEqual(input.Id, data.Id);
     Assert.AreEqual(input.ForumId, data.Forum.Id);
     Assert.AreEqual(input.Sticky, data.Sticky);
     Assert.AreEqual(input.Title, data.Title);
     Assert.AreEqual(input.Body, data.Body);
 }
 public void ShouldMapTopicEntityToDisplay()
 {
     // Arrange
     var data = new Topic
                    {
                        Id = 1423,
                        Forum = new Core.Models.Forum {Id = 1412},
                        Sticky = true,
                        Title = "ToDisplay name",
                        Body = "ToDisplay body"
                    };
     // Act
     var display = new TopicMapper().ToDisplay(data);
     // Assert
     Assert.AreEqual(data.Id, display.Id);
     Assert.AreEqual(data.Forum.Id, display.ForumId);
     Assert.AreEqual(data.Sticky, display.Sticky);
     Assert.AreEqual(data.Title, display.Title);
     Assert.AreEqual(data.Body, display.Body);
 }
示例#9
0
        public TopicDetailModel Add(TopicDetailModel detail)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var topic = TopicMapper.MapTopicDetailModelToEntity(detail);
                topic.Id = Guid.NewGuid();
                var idUser = detail.UserId;
                var idTeam = detail.TeamId;
                if (idUser != Guid.Empty)
                {
                    topic.User = teamCommunicationDbContext.Users.First(c => c.Id == idUser);
                }
                if (idTeam != Guid.Empty)
                {
                    topic.Team = teamCommunicationDbContext.Teams.First(c => c.Id == idTeam);
                }

                teamCommunicationDbContext.Topics.Add(topic);
                teamCommunicationDbContext.SaveChanges();

                return(TopicMapper.MapTopicEntityToDetailModel(topic));
            }
        }
 public void ShouldShowPopulatedTopicFormOnLoadWithId()
 {
     var view = _repository.DynamicMock<ITopicFormView>();
     var provider = _repository.DynamicMock<ITopicProvider>();
     var loader = default(IEventRaiser);
     var id = 4122;
     var data = new Topic
                    {
                        Id = id,
                        Title = "Populated topic title",
                        Body = "Populated topic body",
                        Sticky = true,
                        Forum = new Core.Models.Forum
                                    {
                                        Id = 4132,
                                        Name = "Parent forum name"
                                    }
                    };
     var input = new TopicMapper().ToInput(data);
     With.Mocks(_repository).
         ExpectingInSameOrder(() =>
                                  {
                                      view.Load += null;
                                      loader = LastCall.IgnoreArguments().GetEventRaiser();
                                      Expect.Call(view.IsPostBack).Return(false);
                                      Expect.Call(view.CurrentId).Return(id).Repeat.Any();
                                      Expect.Call(provider.Get(id)).Return(data);
                                      Expect.Call(view.Topic = input);
                                      LastCall.IgnoreArguments();
                                      SetupResult.For(view.Topic).Return(input);
                                  }).
         Verify(() =>
                    {
                        new TopicFormPresenter(view, provider);
                        loader.Raise(null, new EventArgs());
                        Assert.IsNotNull(view.Topic);
                        Assert.AreEqual(data.Id, view.CurrentId);
                        Assert.AreEqual(data.Title, view.Topic.Title);
                        Assert.AreEqual(data.Body, view.Topic.Body);
                        Assert.AreEqual(data.Sticky, view.Topic.Sticky);
                        Assert.AreEqual(data.Forum.Id, view.Topic.ForumId);
                    });
 }
 public void ShouldGoToShowTopicOnUpdateWithId()
 {
     var view = _repository.DynamicMock<ITopicFormView>();
     var provider = _repository.DynamicMock<ITopicProvider>();
     var loader = default(IEventRaiser);
     var updater = default(IEventRaiser);
     var id = 1423;
     var data = new Topic
                    {
                        Id = id,
                        Title = "Updated topic title",
                        Body = "updated topic body",
                        Forum = new Core.Models.Forum
                                    {
                                        Id = 4123,
                                        Name = "Parent forum name"
                                    }
                    };
     var input = new TopicMapper().ToInput(data);
     With.Mocks(_repository).
         ExpectingInSameOrder(() =>
                                  {
                                      view.Load += null;
                                      loader = LastCall.IgnoreArguments().GetEventRaiser();
                                      view.Update += null;
                                      updater = LastCall.IgnoreArguments().GetEventRaiser();
                                      Expect.Call(view.IsPostBack).Return(true);
                                      Expect.Call(view.IsValid).Return(true);
                                      Expect.Call(view.Topic).Return(input);
                                      Expect.Call(provider.Update(data)).IgnoreArguments().Return(true);
                                      Expect.Call(() => view.GoToShowTopic(id));
                                  }).
         Verify(() =>
                    {
                        new TopicFormPresenter(view, provider);
                        loader.Raise(null, new EventArgs());
                        updater.Raise(null, new IdEventArgs {Id = id});
                    });
 }