Пример #1
0
 public bool Update(Topic entity)
 {
     try
     {
         var topic = _topics.First(e => e.Id == entity.Id);
         topic.Title = entity.Title;
         topic.Body = entity.Body;
         topic.Sticky = entity.Sticky;
         topic.Forum = entity.Forum;
         topic.Posts = entity.Posts;
         _dataContext.SubmitChanges();
         return true;
     }
     catch (Exception)
     {
         return false;
     }
 }
 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 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);
 }
Пример #4
0
 public int Create(Topic entity)
 {
     _topics.InsertOnSubmit(entity);
     _dataContext.SubmitChanges();
     return entity.Id;
 }
 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});
                    });
 }