public ActionResult Edit([Bind(Include = "ID,Name,Peopel,Coustomer,StartTime,EndTime,Tips,Person")] HistoryModels roomModels) { if (ModelState.IsValid) { db.Entry(roomModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(roomModels)); }
public ActionResult Create([Bind(Include = "Room_ID,Room_No,Room_Level,Room_Type,Room_Rate,Room_Status")] Room room) { if (ModelState.IsValid) { db.Rooms.Add(room); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(room)); }
public ActionResult Create(Room room) { if (ModelState.IsValid) { db.Rooms.Add(room); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(room)); }
public ActionResult Create([Bind(Include = "ID,Name,Peopel,Coustomer,StartTime,EndTime,Tips,Status,Page,Person")] RoomModels roomModels) { if (ModelState.IsValid) { db.RoomModels.Add(roomModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(roomModels)); }
public ActionResult Create([Bind(Include = "Id,RoomCode,RoomName,Description,Charges")] Room room) { if (ModelState.IsValid) { db.Patients.Add(room); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(room)); }
public RoomServiceTest() { //setting up context factory = new ConnectionFactory(); _context = factory.CreateRoomDbContextForInMemory(); _context.Database.EnsureDeleted(); _context.Database.EnsureCreated(); _context.SaveChanges(); var room = new Room() { RoomId = 1, Subject = "testSubject", ClassName = "testName", CreatorId = "testUser", SemesterId = 1 }; RoomDAO.Create(_context, room); var chats = new List <RoomChat>(); chats.Add(new RoomChat() { Id = 1, RoomId = 1, UserId = "testUser", Date = DateTime.Now, Content = "testChat", Type = 1, }); chats.Add(new RoomChat() { Id = 2, RoomId = 1, UserId = "testUser", Date = DateTime.Now, Content = "testChat", Type = 1, }); chats.Add(new RoomChat() { Id = 3, RoomId = 1, UserId = "testUser", Date = DateTime.Now, Content = "testChat", Type = 1, }); foreach (var chat in chats) { RoomChatDAO.Create(_context, chat); } var links = new List <RoomUserLink>(); links.Add(new RoomUserLink() { RoomId = 1, RoomUserId = 1, UserId = "testUser" }); links.Add(new RoomUserLink() { RoomId = 1, RoomUserId = 2, UserId = "testUser1" }); links.Add(new RoomUserLink() { RoomId = 1, RoomUserId = 3, UserId = "testUser2" }); RoomUserLinkDAO.Create(_context, links); _env = new Mock <IWebHostEnvironment>(); _env.Setup(f => f.ContentRootPath).Returns(""); }
public RoomDAOTest() { factory = new ConnectionFactory(); roomContext = factory.CreateRoomDbContextForInMemory(); roomContext.Database.EnsureDeleted(); roomContext.Database.EnsureCreated(); roomContext.SaveChanges(); }
public static async Task <IActionResult> Create(RoomDBContext context, RoomChat roomChat) { try { context.RoomChat.Add(roomChat); context.SaveChanges(); return(new ObjectResult(new { message = "Add success!" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static IActionResult UpdateRoom(RoomDBContext context, Room room) { try { context.Room.Update(room); context.SaveChanges(); return(new ObjectResult(new { message = "Successful" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static async Task <IActionResult> Update(RoomDBContext context, Semester semester) { try { context.Semester.Update(semester); context.SaveChanges(); return(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static IActionResult Update(RoomDBContext context, Timetable timetable) { try { context.TimeTable.UpdateRange(timetable); context.SaveChanges(); return(new ObjectResult(new { message = "Add success!" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static async Task <IActionResult> DeleteRoomChat(RoomDBContext context, List <RoomChat> roomChats) { try { context.RoomChat.RemoveRange(roomChats); context.SaveChanges(); return(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public RoomChatDAOTest() { factory = new ConnectionFactory(); roomContext = factory.CreateRoomDbContextForInMemory(); roomContext.Database.EnsureDeleted(); roomContext.Database.EnsureCreated(); roomContext.SaveChanges(); var room = new Room() { RoomId = 1, Subject = "testSubject", ClassName = "testName", CreatorId = "testUser", SemesterId = 1 }; RoomDAO.Create(roomContext, room); }
public static async Task <IActionResult> Delete(RoomDBContext context, RoomUserLink roomUserLink) { try { context.RoomUserLink.Remove(roomUserLink); context.SaveChanges(); return(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static async Task <IActionResult> DeleteTimeTable(RoomDBContext context, List <Timetable> timetables) { try { context.TimeTable.RemoveRange(timetables); context.SaveChanges(); return(new ObjectResult(new { message = "delete success!" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static async Task <IActionResult> Create(RoomDBContext context, RoomUserLink roomUserLink) { try { await context.RoomUserLink.AddAsync(roomUserLink); context.SaveChanges(); return(new ObjectResult("success") { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(e.Message) { StatusCode = 500, }); } }
public static async Task <IActionResult> Create(RoomDBContext context, List <RoomUserLink> roomUserLinks) { try { await context.RoomUserLink.AddRangeAsync(roomUserLinks); context.SaveChanges(); return(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public static async Task <IActionResult> Create(RoomDBContext context, Timetable timetable) { try { await context.TimeTable.AddAsync(timetable); context.SaveChanges(); return(new ObjectResult(new { message = "Add success!" }) { StatusCode = 200, }); } catch (Exception e) { return(new ObjectResult(new { message = e.Message }) { StatusCode = 500, }); } }
public async void DeleteTeacher_Returns_Fail_LinkedToRoom(string id) { //Arrange var user = new AppUser { Id = id, UserName = "******", Email = "Test1@gmail", Avatar = "default.png", RealName = "Test 1", DOB = new DateTime(2020, 09, 29) }; var user2 = new AppUser { Id = "4", UserName = "******", Email = "Test4@gmail", Avatar = "default.png", RealName = "Test 4", DOB = new DateTime(2020, 09, 29) }; var roomUserLink = new RoomUserLink { RoomUserId = 1, RoomId = 1, UserId = "4" }; _roomContext.RoomUserLink.Add(roomUserLink); _roomContext.SaveChanges(); List <string> list = new List <string>() { user.Id, "4" }; List <string> listcheckSuccess = new List <string>() { user.Id }; fakeUserManager.Setup(x => x.FindByIdAsync(user.Id)).ReturnsAsync(user); fakeUserManager.Setup(x => x.FindByIdAsync(user2.Id)).ReturnsAsync(user2); fakeUserManager.Setup(x => x.IsInRoleAsync(It.IsAny <AppUser>(), "teacher")).ReturnsAsync(true); //Act var result = await _teacherService.Object.DeleteTeacher(list); var okObjectResult = result as OkObjectResult; var model = okObjectResult.Value as Dictionary <String, object>; var keys = model.Keys.ToArray(); var values = model.Values.ToArray(); var emptyList = new List <string>() { "Teacher " + user2.UserName + " is still linked to a classroom" }; var listSuccess = (List <string>)values[0]; var listFailed = (List <Error>)values[1]; //Assert Assert.Equal(200, okObjectResult.StatusCode); Assert.IsType <OkObjectResult>(okObjectResult); Assert.Equal(2, model.Count); Assert.Equal("success", keys[0].ToString()); Assert.Equal("failed", keys[1].ToString()); Assert.Equal(listcheckSuccess, values[0]); //check value in dictionary Assert.Equal(user.Id, listSuccess[0]); Assert.Equal(emptyList[0], listFailed[0].Message); }
public TeacherServiceTest() { //setting up context 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(); //mocking user manager fakeUserManager = new Mock <FakeUserManager>(); 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); //MockLogDAO var logDAO = new Mock <ILogDAO>(); logDAO.Setup(x => x.CreateLog(It.IsAny <UsersLog>())).ReturnsAsync("success"); logDAO.Setup(x => x.DeleteLogs(It.IsAny <List <UsersLog> >())).ReturnsAsync("success"); logDAO.Setup(x => x.GetLogsByRoomId(It.IsAny <string>())).ReturnsAsync(new List <UsersLog>()); //MockLogDAO var attendanceDAO = new Mock <IAttendanceDAO>(); attendanceDAO.Setup(x => x.UpdateAttendance(It.IsAny <List <AttendanceReports> >())).ReturnsAsync(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); attendanceDAO.Setup(x => x.CreateAttendance(It.IsAny <List <AttendanceReports> >())).ReturnsAsync(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); attendanceDAO.Setup(x => x.DeleteAttendance(It.IsAny <List <AttendanceReports> >())).ReturnsAsync(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); //mocking IEmailService var emailConfig = new EmailConfiguration { From = "*****@*****.**", SmtpServer = "smtp.gmail.com", Port = 465, UserName = "******" }; var appSettings = new AppSettings { Secret = "THIS IS USED TO SIGN AND VERIFY JWT TOKENS, REPLACE IT WITH YOUR OWN SECRET, IT CAN BE ANY STRING" }; IOptions <AppSettings> options = Options.Create(appSettings); //mocking HttpContextAccessor mockHttpContextAccessor = new Mock <IHttpContextAccessor>(); var HttpContext = new DefaultHttpContext(); mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(HttpContext); //Mocking EmailSender mockEmailSender = new Mock <IEmailSender>(); //Mocking UserAccessor mockUserAccessor = new Mock <UserAccessor>(mockHttpContextAccessor.Object); //Mocking UrlHelper mockUrlHelperFactory = new Mock <IUrlHelperFactory>(); //Mockikng ActionContextAccessor actionContextAccessor = new Mock <IActionContextAccessor>(); //MockPMAO var privateDAO = new Mock <IPrivateMessageDAO>(); privateDAO.Setup(x => x.DeletePrivateMessages(It.IsAny <List <PrivateMessage> >())).ReturnsAsync(new OkObjectResult("")); _teacherService = new Mock <TeacherService>( _userContext, fakeUserManager.Object, _roomContext, logDAO.Object, attendanceDAO.Object, privateDAO.Object, mockEmailSender.Object, mockUrlHelperFactory.Object, actionContextAccessor.Object); }
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); }
public UserServiceTest(TestFixture <Startup> fixture) { //setting up context factory = new ConnectionFactory(); context = factory.CreateUserDbContextForInMemory(); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.SaveChanges(); //setting up room context factory = new ConnectionFactory(); roomContext = factory.CreateRoomDbContextForInMemory(); roomContext.Database.EnsureDeleted(); roomContext.Database.EnsureCreated(); roomContext.SaveChanges(); //mocking user manager users = new List <AppUser> { new AppUser { Id = "TestUserId01", UserName = "******", Email = "*****@*****.**", RealName = "TestRealName01", Avatar = "default.png", DOB = new DateTime(2020, 02, 02) }, new AppUser { Id = "TestUserId02", UserName = "******", Email = "*****@*****.**", RealName = "TestRealName02", Avatar = "default.png", DOB = new DateTime(2020, 02, 02) }, new AppUser { Id = "TestUserId03", UserName = "******", Email = "*****@*****.**", RealName = "TestRealName03", Avatar = "default.png", DOB = new DateTime(2020, 02, 02) }, new AppUser { Id = "TestUserId04", UserName = "******", Email = "*****@*****.**", RealName = "TestRealName04", Avatar = "default.png", DOB = new DateTime(2020, 02, 02) }, new AppUser { Id = "TestUserId05", UserName = "******", Email = "*****@*****.**", RealName = "TestRealName05", Avatar = "default.png", DOB = new DateTime(2020, 02, 02) }, }.AsQueryable(); 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); fakeUserManager.Setup(x => x.GetRolesAsync(It.IsAny <AppUser>())).ReturnsAsync(new List <string>() { "student" }); //mocking mapper var mapper = (IMapper)fixture.Server.Host.Services.GetService(typeof(IMapper)); //var mockMapper = new MapperConfiguration(cfg => //{ // cfg.AddProfile(new UserProfile()); //your automapperprofile //}); //var mapper = mockMapper.CreateMapper(); //mocking IEmailService var emailConfig = new EmailConfiguration { From = "*****@*****.**", SmtpServer = "smtp.gmail.com", Port = 465, UserName = "******" }; var appSettings = new AppSettings { Secret = "THIS IS USED TO SIGN AND VERIFY JWT TOKENS, REPLACE IT WITH YOUR OWN SECRET, IT CAN BE ANY STRING" }; IOptions <AppSettings> options = Options.Create(appSettings); //mocking HttpContextAccessor mockHttpContextAccessor = new Mock <IHttpContextAccessor>(); var HttpContext = new DefaultHttpContext(); mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(HttpContext); //mocking signinmanager fakeSignInManager = new Mock <FakeSignInManager>(); fakeSignInManager.Setup( x => x.PasswordSignInAsync(It.IsAny <AppUser>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync(SignInResult.Success); _jwtGenerator = new Mock <JwtGenerator>(options, mapper, context); //mocking attendanceDAO attendanceDAO = new Mock <IAttendanceDAO>(); attendanceDAO.Setup(x => x.UpdateAttendance(It.IsAny <List <AttendanceReports> >())).ReturnsAsync(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); attendanceDAO.Setup(x => x.CreateAttendance(It.IsAny <List <AttendanceReports> >())).ReturnsAsync(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); attendanceDAO.Setup(x => x.DeleteAttendance(It.IsAny <List <AttendanceReports> >())).ReturnsAsync(new ObjectResult(new { message = "success" }) { StatusCode = 200, }); //MockLogDAO logDAO = new Mock <ILogDAO>(); logDAO.Setup(x => x.CreateLog(It.IsAny <UsersLog>())).ReturnsAsync("success"); logDAO.Setup(x => x.DeleteLogs(It.IsAny <List <UsersLog> >())).ReturnsAsync("success"); logDAO.Setup(x => x.GetLogsByRoomId(It.IsAny <string>())).ReturnsAsync(new List <UsersLog>()); //mocking UserStore mockUserStore = new Mock <IUserStore>(); mockUserStore.Setup(x => x.GenerateTokenAndSave(It.IsAny <String>())).Returns(""); mockUserStore.Setup(x => x.IsTokenValid(It.IsAny <String>())).Returns(true); var _env = new Mock <IWebHostEnvironment>(); _env.Setup(x => x.ContentRootPath).Returns(Directory.GetCurrentDirectory); //Mocking UrlHelper mockUrlHelperFactory = new Mock <IUrlHelperFactory>(); //Mockikng ActionContextAccessor actionContextAccessor = new Mock <IActionContextAccessor>(); //Mocking EmailSender mockEmailSender = new Mock <IEmailSender>(); //Mocking UserAccessor mockUserAccessor = new Mock <UserAccessor>(mockHttpContextAccessor.Object); _userService = new Mock <UserService>( context, mapper, fakeSignInManager.Object, fakeUserManager.Object, mockUrlHelperFactory.Object, actionContextAccessor.Object, mockEmailSender.Object, _jwtGenerator.Object, mockUserAccessor.Object, mockUserStore.Object, _env.Object, logDAO.Object, roomContext, attendanceDAO.Object ); }