Esempio n. 1
0
 public TagViewModel BuildViewModel(Tag tag)
 {
     return new TagViewModel() {
         Id = tag.Id,
         Name = tag.Name
     };
 }
        public ActionResult Complain(CreateComplaintViewModel model)
        {
            if (ModelState.IsValid)
            {
                var me = FacebookService.GetMe();

                var complaint = new Complaint()
                {
                    ComplaintText = model.ComplaintText,
                    FacebookUserId = me.FacebookUserId,
                    FacebookUserName = me.Name,
                };

                if (model.SelectedComplaintSeverityId.HasValue)
                {
                    var severity = _complaintSeverityService.Get(model.SelectedComplaintSeverityId.Value);
                    complaint.Severity = severity;
                }

                if (model.TagList.Any())
                {
                    foreach (var tagName in model.TagList)
                    {
                        var tag = _tagService.FindByName(tagName);

                        if (tag == null)
                        {
                            tag = new Tag() {
                                Name = tagName
                            };
                        }

                        complaint.Tags.Add(tag);
                    }
                }

                var errors = _complaintService.Create(complaint);

                if (!errors.Any())
                {
                    if (model.PublishToWall)
                    {
                        FacebookService.Post("feed", new
                        {
                            message = model.ComplaintText,
                            picture = String.Format("{0}/Content/Images/angry smiley.png", Constants.RootUrl),
                            link = String.Format("{0}/Complaint/View/{1}", Constants.RootUrl, complaint.Id),
                            caption = "I just complained",
                            description = "I just posted a complaint on Complainatron",
                            source = String.Format("{0}/Complaint/View/{1}", Constants.RootUrl, complaint.Id),
                        });
                    }

                    var viewModel = _complaintBuilder.BuildViewModel(complaint);
                    return PartialView("_Complaint", viewModel);
                }
                else
                {
                    SetModelStateErrors(errors);
                }
            }

            PopulateCreateComplaintModel(model);
            return PartialView("_Complain", model);
        }
        public void It_should_ask_the_complaint_service_for_a_paged_list_of_complaints_as_a_part_of_the_tag_action()
        {
            //Arrange
            StubContext();

            var tagId = Guid.NewGuid();
            var pagingInfo = TestUtilities.GetPagingInformation();
            IPagedList<Complaint> complaints = TestUtilities.GetPagedTestComplaints(pagingInfo);
            var tag = new Tag() { Name = "tag" };

            A.CallTo(() => _tagService.Get(tagId)).Returns(tag);
            A.CallTo(() => _complaintService.GetComplaintsByTag(pagingInfo, tagId)).Returns(complaints);

            //Act
            _controller.Tag(tagId, pagingInfo);

            //Assert
            A.CallTo(() => _complaintService.GetComplaintsByTag(pagingInfo, tagId)).MustHaveHappened(Repeated.Exactly.Once);
        }
        public void It_should_return_a_view_as_a_part_of_the_tag_action()
        {
            //Arrange
            StubContext();

            var tagId = Guid.NewGuid();
            var pagingInfo = TestUtilities.GetPagingInformation();
            IPagedList<Complaint> complaints = TestUtilities.GetPagedTestComplaints(pagingInfo);
            var tag = new Tag() { Name = "tag" };

            A.CallTo(() => _tagService.Get(tagId)).Returns(tag);
            A.CallTo(() => _complaintService.GetComplaintsByTag(pagingInfo, tagId)).Returns(complaints);

            //Act
            var result = _controller.Tag(tagId, pagingInfo);

            //Assert
            result.Should().BeOfType<ViewResult>();
        }