public async void ScheduleDeleteList() { var schedules = new List <Timetable>(); //Arrange schedules.Add(new Timetable() { Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); schedules.Add(new Timetable() { Id = 2, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); schedules.Add(new Timetable() { Id = 3, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); // Act var result = await TimetableDAO.Create(roomContext, schedules); // Assert Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); schedules.RemoveAt(2); result = await TimetableDAO.DeleteTimeTable(roomContext, schedules); Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); var resultSchedule = TimetableDAO.GetById(roomContext, 1); Assert.Null(resultSchedule); resultSchedule = TimetableDAO.GetById(roomContext, 3); Assert.NotNull(resultSchedule); }
public async void GetByRoomAndDate() { var schedules = new List <Timetable>(); //Arrange schedules.Add(new Timetable() { Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); schedules.Add(new Timetable() { Id = 2, RoomId = 1, Date = DateTime.Now.AddDays(1).Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); schedules.Add(new Timetable() { Id = 3, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }); // Act var result = await TimetableDAO.Create(roomContext, schedules); // Assert Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); var resultList = TimetableDAO.GetByRoomAndDate(roomContext, 1, DateTime.Now.Date); Assert.Equal(2, resultList.Count); }
public async void UpdateSchedule() { //Arrange var schedule = new Timetable() { Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }; // Act var result = await TimetableDAO.Create(roomContext, schedule); // Assert Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); schedule.Date = DateTime.Now.AddDays(1).Date; schedule.StartTime = TimeSpan.Parse("9:00"); schedule.EndTime = TimeSpan.Parse("12:00"); result = TimetableDAO.Update(roomContext, schedule); Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); var resultSchedule = TimetableDAO.GetById(roomContext, 1); Assert.Equal(1, resultSchedule.RoomId); Assert.Equal(DateTime.Now.AddDays(1).Date, resultSchedule.Date); Assert.Equal(TimeSpan.Parse("9:00"), resultSchedule.StartTime); Assert.Equal(TimeSpan.Parse("12:00"), resultSchedule.EndTime); }
public async void ScheduleCreateSuccessfully() { //Arrange var schedule = new Timetable() { Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }; // Act var result = await TimetableDAO.Create(roomContext, schedule); // Assert Assert.Equal((int)HttpStatusCode.OK, ((ObjectResult)result).StatusCode); }
public SemesterServiceTest() { factory = new ConnectionFactory(); userContext = factory.CreateUserDbContextForInMemory(); userContext.Database.EnsureDeleted(); userContext.Database.EnsureCreated(); userContext.SaveChanges(); roomContext = factory.CreateRoomDbContextForInMemory(); roomContext.Database.EnsureDeleted(); roomContext.Database.EnsureCreated(); roomContext.SaveChanges(); attendanceDAO = new Mock <AttendanceDAO>(userContext); logDAO = new Mock <LogDAO>(userContext); var iAttendanceDao = attendanceDAO.As <IAttendanceDAO>(); var iLogDAO = logDAO.As <ILogDAO>(); //mocking user manager var users = new List <AppUser> { new AppUser { UserName = "******", Email = "*****@*****.**" }, new AppUser { UserName = "******", Email = "*****@*****.**" }, new AppUser { UserName = "******", Email = "*****@*****.**" }, new AppUser { UserName = "******", Email = "*****@*****.**" }, new AppUser { UserName = "******", Email = "*****@*****.**" }, }.AsQueryable(); var fakeUserManager = new Mock <FakeUserManager>(); fakeUserManager.Setup(x => x.Users).Returns(users.AsQueryable()); fakeUserManager.Setup(x => x.DeleteAsync(It.IsAny <AppUser>())) .ReturnsAsync(IdentityResult.Success); fakeUserManager.Setup(x => x.CreateAsync(It.IsAny <AppUser>(), It.IsAny <string>())) .ReturnsAsync(IdentityResult.Success); fakeUserManager.Setup(x => x.UpdateAsync(It.IsAny <AppUser>())) .ReturnsAsync(IdentityResult.Success); var mockEnvironment = new Mock <IWebHostEnvironment>(); //...Setup the mock as needed mockEnvironment .Setup(m => m.EnvironmentName) .Returns("Hosting:UnitTestEnvironment"); mockEnvironment.Setup(m => m.ContentRootPath).Returns(""); _SemetserService = new Mock <SemesterService>(fakeUserManager.Object, userContext, roomContext, mockEnvironment.Object, iAttendanceDao.Object, iLogDAO.Object); var semester = new Semester() { Id = 1, Name = "testSemester", File = "TestFile.xsl", LastUpdated = DateTime.Now }; SemesterDAO.Create(roomContext, semester); var room = new Room() { RoomId = 1, Subject = "testSubject", ClassName = "testName", CreatorId = "testUser", SemesterId = 1 }; RoomDAO.Create(roomContext, room); var links = new List <RoomUserLink>(); links.Add(new RoomUserLink() { RoomId = 1, RoomUserId = 1, UserId = "testUser" }); links.Add(new RoomUserLink() { RoomId = 1, RoomUserId = 2, UserId = "testUser2" }); links.Add(new RoomUserLink() { RoomId = 1, RoomUserId = 3, UserId = "testUser1" }); // Act RoomUserLinkDAO.Create(roomContext, links); var schedule = new Timetable() { Id = 1, RoomId = 1, Date = DateTime.Now.Date, StartTime = TimeSpan.Parse("8:00"), EndTime = TimeSpan.Parse("10:00"), }; // Act TimetableDAO.Create(roomContext, schedule); }