public async Task Should_Create_New_Item() { var sessionToCreate = new TestSessionDTO { Id = 1, Title = "My session", TestIds = { 2 }, MemberIds = { "3" } }; var repositoryMock = new Mock <IRepository <TestSession> >(); var unitOfWorkMock = new Mock <IUnitOfWork>(); unitOfWorkMock.Setup(u => u.TestSessions).Returns(() => repositoryMock.Object); var service = new TestSessionService(unitOfWorkMock.Object, mapper); await service.CreateAsync(sessionToCreate); repositoryMock.Verify(m => m.Create(It.Is <TestSession>(t => t.Title == sessionToCreate.Title && t.Tests.Single().TestId == sessionToCreate.TestIds.Single() && t.Members.Single().UserId == sessionToCreate.MemberIds.Single()))); unitOfWorkMock.Verify(m => m.SaveAsync()); }
public async Task <IActionResult> Create([FromForm] TestSessionDTO testSession) { await testSessionService.CreateAsync(testSession); return(RedirectToAction(nameof(List))); }