Esempio n. 1
0
        public async Task PostCommentViewModelCurrentUserIsAuthenticated_ReturnsJsonResulACommentViewModel() {
            var repository = new FakeCommentRepository();

            var contextService = new Mock<IContextService>();
            var account = new Account {Id = 12345, DisplayName = "TestDisplayName", Email = "*****@*****.**"};
            contextService
                .Setup(x => x.GetCurrentAccountAsync())
                .Returns(Task.FromResult(account));

            var commentController = new CommentController(repository, new Mock<IVoteService>().Object, contextService.Object);
            var commentViewModel = new CommentViewModel {
                CountdownId = 123,
                Text = "Comment content..."
            };

            dynamic result = (await commentController.Create(commentViewModel)).Data;

            var model = result as CommentViewModel;
            Assert.IsNotNull(model);
            Assert.AreEqual(account.DisplayName, model.CreatedByName);
            Assert.AreEqual(account.Email, model.CreatedByEmail);

            DateTime localTime = DateTime.UtcNow.ToLocalTime();
            Assert.AreEqual(localTime.Date, model.CreatedOn.Date);
            Assert.AreEqual(localTime.Hour, model.CreatedOn.Hour);
            Assert.AreEqual(localTime.Minute, model.CreatedOn.Minute);
            Assert.AreEqual(localTime.Second, model.CreatedOn.Second);

            Assert.AreEqual(commentViewModel.Text, model.Text);
            Assert.AreEqual(commentViewModel.CountdownId, model.CountdownId);
        }
Esempio n. 2
0
        public async Task<JsonResult> Create(CommentViewModel commentViewModel) {
            Account currentAccount = await _contextService.GetCurrentAccountAsync();
            Comment comment = commentViewModel.ToComment(currentAccount);

            await _commentRepository.CreateAsync(comment);

            return Json(comment.ToCommentViewModel());
        }
Esempio n. 3
0
        public async Task PostCommentViewModelCurrentUserIsAuthenticated_CreatesTheCommentWithTheCorrectValues() {
            var repository = new FakeCommentRepository();

            var contextService = new Mock<IContextService>();
            var account = new Account {Id = 123};
            contextService
                .Setup(x => x.GetCurrentAccountAsync())
                .Returns(Task.FromResult(account));

            var commentController = new CommentController(repository, new Mock<IVoteService>().Object, contextService.Object);
            var commentViewModel = new CommentViewModel {
                CountdownId = 123,
                Text = "Comment content..."
            };

            await commentController.Create(commentViewModel);

            Assert.AreEqual(1, repository.InMemoryComments.Count);
            Comment comment = repository.InMemoryComments[0];
            Assert.AreEqual(commentViewModel.Text, comment.Text);
            Assert.AreEqual(commentViewModel.CountdownId, comment.CountdownId);
            Assert.AreEqual(account, comment.Account);
            Assert.AreEqual(DateTime.UtcNow.Date, comment.CreatedOn.Date);
        }