public void ExpelTellerFromBranch_Should_SetWorkAtIdPropertyToNull_And_FillTellerAtBranchHistoryRecord_And_ReturnOkObjectResult_When_ModelStateIsValid() { // Arrange var workerAtBranch = new WorkerAtBranchDto { WorkerId = 3, BranchId = 2 }; var currentUser = new ApplicationUser { Id = 3 }; 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.ExpelTellerFromBranch(workerAtBranch) as OkResult; // Assert Assert.IsNotNull(okResult); var tellerFromDb = _context.Tellers.SingleOrDefault(t => t.Id == workerAtBranch.WorkerId); Assert.IsNotNull(tellerFromDb); Assert.AreEqual(null, tellerFromDb.WorkAtId); var tellerAtBranchFromDb = _context.TellerAtBranchHistory.Where(t => t.TellerId == workerAtBranch.WorkerId).ToList().LastOrDefault(); Assert.IsNotNull(tellerAtBranchFromDb); Assert.IsNotNull(tellerAtBranchFromDb.ExpelDate); Assert.AreEqual(_tellerAtBranchHistory.AssignDate, tellerAtBranchFromDb.AssignDate); Assert.AreEqual(_tellerAtBranchHistory.AssignedById, tellerAtBranchFromDb.AssignedById); Assert.AreEqual(currentUser.Id, tellerAtBranchFromDb.ExpelledById); Assert.AreEqual(workerAtBranch.BranchId, tellerAtBranchFromDb.BranchId); Assert.AreEqual(workerAtBranch.WorkerId, tellerAtBranchFromDb.TellerId); }