public void ExpelManagerFromBranch_Should_SetWorkAtIdPropertyToNull_And_FillManagerAtBranchHistoryRecord_And_ReturnOkObjectResult_When_ModelStateIsValid() { // Arrange var workerAtBranch = new WorkerAtBranchDto { WorkerId = 5, BranchId = 2 }; var currentUser = new ApplicationUser { Id = 5 }; 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.ExpelManagerFromBranch(workerAtBranch) as OkResult; // Assert Assert.IsNotNull(okResult); var managerFromDb = _context.Managers.SingleOrDefault(m => m.Id == workerAtBranch.WorkerId); Assert.IsNotNull(managerFromDb); Assert.AreEqual(null, managerFromDb.WorkAtId); var managerAtBranchFromDb = _context.ManagerAtBranchHistory.Where(m => m.ManagerId == workerAtBranch.WorkerId).ToList().LastOrDefault(); Assert.IsNotNull(managerAtBranchFromDb); Assert.IsNotNull(managerAtBranchFromDb.ExpelDate); Assert.AreEqual(_managerAtBranchHistory.AssignDate, managerAtBranchFromDb.AssignDate); Assert.AreEqual(_managerAtBranchHistory.AssignedById, managerAtBranchFromDb.AssignedById); Assert.AreEqual(currentUser.Id, managerAtBranchFromDb.ExpelledById); Assert.AreEqual(workerAtBranch.BranchId, managerAtBranchFromDb.BranchId); Assert.AreEqual(workerAtBranch.WorkerId, managerAtBranchFromDb.ManagerId); }