public void ClockInEmployeeTest_WhenUserNameAndReportDateIsCorrect_ReturnsSuccessMessage() { var container = ContainerConfig.Configure(); DateTime now = DateTime.Now; ClockInQueryModel clockIn = new ClockInQueryModel { UserId = 10001, UserName = "******", ActivityId = 1, ClockInDateTime = now }; Mock <IDailyTimeInDataAccess> mock = new Mock <IDailyTimeInDataAccess>(); mock.Setup(x => x.InsertTimeIn(clockIn)).Returns(true); mock.Setup(x => x.GetEmployeeRecentTimeIn(clockIn.UserName)).Returns(new DailyTimeIn { TimeInDttm = now.AddDays(-1) }); ITimeInEmployeeAttendance app = new TimeInEmployeeAttendance(mock.Object); string output = app.ClockInEmployee(clockIn); Assert.AreEqual("Employee successfully clocked in.", output); }
/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="activityId"></param> /// <param name="employeeName"></param> /// <returns></returns> public bool InsertTimeIn(ClockInQueryModel clockIn) { DailyTimeIn newRecord = new DailyTimeIn(); try { using (TimeInEntities context = new TimeInEntities()) { newRecord.EmployeeId = clockIn.UserId; newRecord.ActivityCd = clockIn.ActivityId; newRecord.TimeInDttm = clockIn.ClockInDateTime; newRecord.IsActive = true; newRecord.CreateDttm = DateTime.Now; newRecord.CreateUserId = clockIn.UserName; newRecord.UpdateDttm = DateTime.Now; newRecord.UpdateUserId = clockIn.UserName; context.DailyTimeIns.Add(newRecord); context.SaveChanges(); } } catch (Exception ex) { return(false); } return(true); }
public IHttpActionResult ClockInEmployee([FromBody] ClockInModel clockIn) { var container = ContainerConfig.Configure(); User userQuery = new User(); Activity activityQuery = new Activity(); if (clockIn == null) { return(Json(new { Result = "Internal server error.", StatusCode = HttpStatusCode.InternalServerError })); } using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <IUserDataAccess>(); userQuery = app.GetUser(clockIn.UserName); if (userQuery == null) { return(Json(new { Result = "Employee record not found." })); } } using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <IActivityDataAccess>(); activityQuery = app.GetActivitySingle(clockIn.ActivityId); if (activityQuery == null) { return(Json(new { Result = "Activity selected is unknown." })); } } using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <ITimeInEmployeeAttendance>(); ClockInQueryModel clockQuery = new ClockInQueryModel { UserId = userQuery.UserKey, UserName = clockIn.UserName, ActivityId = activityQuery.ActivityId, ClockInDateTime = DateTime.Parse(clockIn.ClockInDateTime) }; string clockInResult = app.ClockInEmployee(clockQuery); return(Json(new { Result = clockInResult })); } }
public void ClockInEmployeeTest_WhenReportMonthIsOutOfMaximumBounds_ReturnsReportMonthIsOutOfBoundsError() { var container = ContainerConfig.Configure(); using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <ITimeInEmployeeAttendance>(); ClockInQueryModel clockIn = new ClockInQueryModel { UserId = 10001, UserName = "******", ActivityId = 1, ClockInDateTime = DateTime.Now.AddMonths(1) }; string output = app.ClockInEmployee(clockIn); Assert.AreEqual("Date is out of bounds.", output); } }
public void ClockInEmployeeTest_WhenEmployeeUserIdIsZero_ReturnsUserNotFoundError() { var container = ContainerConfig.Configure(); using (var scope = container.BeginLifetimeScope()) { var app = scope.Resolve <ITimeInEmployeeAttendance>(); ClockInQueryModel clockIn = new ClockInQueryModel { UserId = 0, UserName = "******", ActivityId = 1, ClockInDateTime = DateTime.Now }; string output = app.ClockInEmployee(clockIn); Assert.AreEqual("User not found.", output); } }
public string ClockInEmployee(ClockInQueryModel clockIn) { if (clockIn == null) { return("No data is being processed."); } if (string.IsNullOrEmpty(clockIn.UserName) || clockIn.UserId < 10000) { return("User not found."); } if (clockIn.ClockInDateTime < DateTime.Parse("1900-01-01") || clockIn.ClockInDateTime > DateTime.Now) { return("Date is out of bounds."); } if (clockIn.ActivityId == 0) { return("Activity ID not found."); } var recentTimeIn = _dataAccess.GetEmployeeRecentTimeIn(clockIn.UserName); if (recentTimeIn.TimeInDttm.Date == clockIn.ClockInDateTime.Date) { return("Already clocked in for the day."); } bool isSuccess = _dataAccess.InsertTimeIn(clockIn); if (isSuccess) { return("Employee successfully clocked in."); } return(string.Empty); }