C#Fluent Assertion with InMemoryDatabase UnitTesting

 // assert each employee has morning and afternoon shifts
 var employees = context.Employees;
 foreach (var emp in employees)
 {
     var empShifts = context.EmployeeShifts.Where(x => x.EmployeeId == emp.Id).ToList();
     empShifts.Count().Should().Be(10);
     empShifts.Where(x => x.ShiftSchedule == ENUMERATIONS.ShiftSchedule.firstHalf).Count().Should().Be(5);
     empShifts.Where(x => x.ShiftSchedule == ENUMERATIONS.ShiftSchedule.secondHalf).Count().Should().Be(5);
  }

  // assert if no consecutive days shift of each employee
  foreach (var emp in employees)
  {
      var empShifts = context.EmployeeShifts.Where(x => x.EmployeeId == emp.Id).ToList();
                 
       foreach (var shift in empShifts)
       {
            var shiftDate = shift.Date;

            var nextDate = shift.Date.AddDays(1);
            var prevDate = shift.Date.AddDays(-1);

            var nextShift = empShifts.Where(x => x.Date == nextDate).FirstOrDefault();
            var prevShift = empShifts.Where(x => x.Date == prevDate).FirstOrDefault();
                       
            nextShift.Should().BeNull();
            prevShift.Should().BeNull();
                       
       }


  }
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *