public async Task CreateMessageTestAsync() { var expected = new Message() { Id = "Id1", ReceivedAt = DateTime.UtcNow, Text = "Text1", Title = "Title1" }; var mock = new Mock <IRepository>(); mock.Setup(m => m.SaveMessageAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>())) .Returns <string, string, DateTime>((title, text, date) => { return(Task.FromResult(new Message() { Id = expected.Id, ReceivedAt = date, Text = text, Title = title })); }); var mockLog = new Mock <ILogger <MessagesController> >(); var controller = new MessagesController(mock.Object, mockLog.Object); var result = await controller.CreateMessageAsync(new Web.Models.Message() { Title = expected.Title, Text = expected.Text }); Assert.IsType <Web.Models.Message>(result); Assert.Equal(expected.Id, result.Id); Assert.Equal(expected.Title, result.Title); Assert.Equal(expected.Text, result.Text); Assert.NotNull(result.ReceivedAt); Assert.Equal(expected.ReceivedAt, result.ReceivedAt.Value, TimeSpan.FromSeconds(2)); }