示例#1
0
		public PostViewModel Map(Post post)
		{
			return new PostViewModel {
				Title = post.Title,
				PublicationDate = post.PubDate.LocalDateTime.ToString("g"),
				Description = post.Description,
				Link = post.Link,
			};
		}
		public void GivenPost_WhenPubDateIsInDifferentOffset_InitialPostingDateIsInLocalTime ()
		{
			var post = new Post { Title = "t", Description = "d", Link = "l", PubDate = new DateTimeOffset(new DateTime(2016, 1, 13, 11, 20, 08), DateTimeOffset.Now.Offset.Add(TimeSpan.FromHours(-1))) };

			var model = _mapper.Map (post);

			var expected = new PostViewModel {
				Title = post.Title,
				Description = post.Description,
				Link = post.Link,
				PublicationDate = new DateTime(2016, 1, 13, 12, 20, 08, DateTimeKind.Local).ToString ("g")
			};

			model.ShouldBeEquivalentTo(expected);
		}
		public void GivenPost_WhenMapIsCalled_APostViewModelIsReturned ()
		{
			var post = new Post { Title = "t", Description = "d", Link = "l", PubDate = new DateTimeOffset(new DateTime(2016, 1, 13, 11, 20, 08), DateTimeOffset.Now.Offset) };

			var model = _mapper.Map (post);

			var expected = new PostViewModel {
				Title = post.Title,
				Description = post.Description,
				Link = post.Link,
				PublicationDate = new DateTime(2016, 1, 13, 11, 20, 08, DateTimeKind.Local).ToString ("g")
			};

			model.ShouldBeEquivalentTo(expected);
		}