public void AssignTellerToBranch_Should_SetWorkAtIdPropertyToSuppliedBranchId_And_CreateTellerAtBranchHistory_And_ReturnOkObjectResult_When_ModelStateIsValid() { // Arrange var workerAtBranch = new WorkerAtBranchDto { WorkerId = 2, BranchId = 1 }; var currentUser = new ApplicationUser { Id = 1 }; var claims = new List <Claim> { new Claim(CustomClaimTypes.UserId, currentUser.Id.ToString()) }; var identity = new ClaimsIdentity(claims); var claimsPrincipal = new ClaimsPrincipal(identity); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = claimsPrincipal } }; _sut.ControllerContext = context; // Act var okResult = _sut.AssignTellerToBranch(workerAtBranch) as OkResult; // Assert Assert.IsNotNull(okResult); var tellerFromDb = _context.Tellers.SingleOrDefault(t => t.Id == workerAtBranch.WorkerId); Assert.IsNotNull(tellerFromDb); Assert.AreEqual(workerAtBranch.BranchId, tellerFromDb.WorkAtId); var tellerAtBranchFromDb = _context.TellerAtBranchHistory.Where(t => t.TellerId == workerAtBranch.WorkerId).ToList().LastOrDefault(); Assert.IsNotNull(tellerAtBranchFromDb); Assert.IsNotNull(tellerAtBranchFromDb.AssignDate); Assert.IsNull(tellerAtBranchFromDb.ExpelDate); Assert.IsNull(tellerAtBranchFromDb.ExpelledById); Assert.AreEqual(currentUser.Id, tellerAtBranchFromDb.AssignedById); Assert.AreEqual(workerAtBranch.BranchId, tellerAtBranchFromDb.BranchId); Assert.AreEqual(workerAtBranch.WorkerId, tellerAtBranchFromDb.TellerId); }