private async Task <int> findUser(string _userName) { Services.UsersService usersService = new Services.UsersService(new Repository.UsersRepository()); var users = await usersService.GetUsersAsync() as List <Users.User>; List <Users.User> user = users.Where(u => u.login == _userName).ToList(); if (user.Count == 1) { return(user[0].userId); } else { if (user.Count > 1) { return(-1); } } return(0); }
public async Task PostEmployeeLogin_LoginWhileAlreadyOnline_ReturnsUnauthorized() { using (var context = GetInitializedUsersContext()) { var usersService = new Services.UsersService(context, new QueueApiServiceMock()); UsersController controller = new UsersController(usersService); EmployeeLogin login = new EmployeeLogin { Username = "******", Password = "******", ServiceType = ServiceType.Pharmacist, StationNumber = 1 }; ActionResult <EmployeeInfo> firstLoginResult = await controller.PostEmployeeLogin(login); ActionResult <EmployeeInfo> result = await controller.PostEmployeeLogin(login); Assert.IsInstanceOf <ActionResult <EmployeeInfo> >(result); Assert.IsInstanceOf <UnauthorizedObjectResult>(result.Result); } }
public async Task SaveCustomerTreatment_SaveOneTreatment_TreatmentInDb() { using (UsersContext context = GetUsersContext()) { int employeeId = 11; int customerId = 1; DateTime today = DateTime.Today; Customer customer = new Customer { CustomerId = customerId, CardNumber = 100 }; Employee employee = new Employee { EmployeeId = employeeId }; context.Customers.Add(customer); context.Employees.Add(employee); context.SaveChanges(); CustomerTreatment customerTreatment = new CustomerTreatment { CustomerId = customerId, DateOfTreatment = today, TreatingEmployeeId = employeeId }; Treatment expectedTreatment = new Treatment { EmployeeId = employeeId, CustomerId = customerId, TreatmentDate = today, Customer = customer, Employee = employee }; Services.UsersService usersService = new Services.UsersService(context, GetQueueApiServiceMock()); await usersService.SaveCustomerTreatment(customerTreatment); Treatment actualTreatment = context.Treatments.Find(today, customerId, employeeId); Assert.AreEqual(expectedTreatment.TreatmentDate, actualTreatment.TreatmentDate); Assert.AreEqual(expectedTreatment.EmployeeId, actualTreatment.EmployeeId); Assert.AreEqual(expectedTreatment.CustomerId, actualTreatment.CustomerId); } }
public async Task GetDailyEmployeeReports_RequestReport_ReturnsReports() { using (UsersContext context = GetUsersContext()) { DateTime today = DateTime.Today; int employeeId = 10; string employeeFirstName = "First"; string employeeLastName = "Last"; context.Customers.AddRange( new Customer { CustomerId = 1, CardNumber = 2 }, new Customer { CustomerId = 2, CardNumber = 3 }); context.Employees.Add(new Employee { EmployeeId = employeeId, Firstname = employeeFirstName, Lastname = employeeLastName }); context.Treatments.AddRange( new Treatment { EmployeeId = employeeId, CustomerId = 1, TreatmentDate = today }, new Treatment { EmployeeId = employeeId, CustomerId = 2, TreatmentDate = today }); context.SaveChanges(); List <DailyEmployeeReport> expectedReports = new List <DailyEmployeeReport> { new DailyEmployeeReport { Date = today, FirstName = employeeFirstName, LastName = employeeLastName, NumberOfPatientsTreated = 2 } }; Services.UsersService usersService = new Services.UsersService(context, GetQueueApiServiceMock()); List <DailyEmployeeReport> actualReports = await usersService.GetDailyEmployeeReports(today); Assert.AreEqual(expectedReports, actualReports); } }
public async Task PostEmployeeLogin_FirstValidLogin_LoginSuccessful() { using (var context = GetInitializedUsersContext()) { var usersService = new Services.UsersService(context, new QueueApiServiceMock()); UsersController controller = new UsersController(usersService); EmployeeLogin login = new EmployeeLogin { Username = "******", Password = "******", ServiceType = ServiceType.Pharmacist, StationNumber = 1 }; ActionResult <EmployeeInfo> result = await controller.PostEmployeeLogin(login); Assert.IsInstanceOf <ActionResult <EmployeeInfo> >(result); Assert.IsInstanceOf <EmployeeInfo>(result.Value); bool isOnline = context.Employees.Where(e => e.Username == login.Username).Single().Online; Assert.IsTrue(isOnline); } }
public async Task GetDailyReports_RequestDailyReports_ReturnsCorrectReports() { using (var context = GetInitializedUsersContext()) { var usersService = new Services.UsersService(context, new QueueApiServiceMock()); UsersController controller = new UsersController(usersService); DateTime yesterday = DateTime.Today.AddDays(-1); DailyEmployeeReport firstEmployee = new DailyEmployeeReport { Date = yesterday, FirstName = "Shay", LastName = "Musachanov", NumberOfPatientsTreated = 4 }; DailyEmployeeReport secondEmployee = new DailyEmployeeReport { Date = yesterday, FirstName = "Daniel", LastName = "Szuster", NumberOfPatientsTreated = 3 }; DailyEmployeeReport thirdEmployee = new DailyEmployeeReport { Date = yesterday, FirstName = "David", LastName = "Fineboym", NumberOfPatientsTreated = 2 }; ActionResult <List <DailyEmployeeReport> > result = await controller.GetDailyReports(yesterday); Assert.IsInstanceOf <ActionResult <List <DailyEmployeeReport> > >(result); Assert.IsInstanceOf <List <DailyEmployeeReport> >(result.Value); List <DailyEmployeeReport> reports = result.Value; Assert.AreEqual(firstEmployee, reports.Find(e => e.FirstName == firstEmployee.FirstName)); Assert.AreEqual(secondEmployee, reports.Find(e => e.FirstName == secondEmployee.FirstName)); Assert.AreEqual(thirdEmployee, reports.Find(e => e.FirstName == thirdEmployee.FirstName)); } }
public async Task PostCustomerTreatment_PostValidTreatment_TreatmentSavedAndDateTruncated() { using (var context = GetInitializedUsersContext()) { var usersService = new Services.UsersService(context, new QueueApiServiceMock()); UsersController controller = new UsersController(usersService); CustomerTreatment treatment = new CustomerTreatment { CustomerId = 10, DateOfTreatment = DateTime.Now, TreatingEmployeeId = 3 }; IActionResult result = await controller.PostCustomerTreatment(treatment); Assert.IsInstanceOf <IActionResult>(result); Assert.IsInstanceOf <CreatedAtActionResult>(result); Assert.DoesNotThrow(() => context.Treatments. Where(t => t.CustomerId == treatment.CustomerId && t.TreatmentDate == DateTime.Today && t.EmployeeId == treatment.TreatingEmployeeId). Single()); } }
public async Task PostEmployeeLogin_LoginWithWrongPassword_ReturnsUnauthorizedAndEmployeeIsOffline() { using (var context = GetInitializedUsersContext()) { var usersService = new Services.UsersService(context, new QueueApiServiceMock()); UsersController controller = new UsersController(usersService); EmployeeLogin login = new EmployeeLogin { Username = "******", Password = "******", ServiceType = ServiceType.Pharmacist, StationNumber = 1 }; ActionResult <EmployeeInfo> result = await controller.PostEmployeeLogin(login); Assert.IsInstanceOf <ActionResult <EmployeeInfo> >(result); Assert.IsInstanceOf <UnauthorizedObjectResult>(result.Result); bool isOnline = context.Employees.Where(e => e.Username == login.Username).Single().Online; Assert.IsFalse(isOnline); } }
public async Task PostEmployeeLogout_OnlineEmployeeLogsOut_EmployeeIsOfflineAndStationIdIsNull() { using (var context = GetInitializedUsersContext()) { var usersService = new Services.UsersService(context, new QueueApiServiceMock()); UsersController controller = new UsersController(usersService); EmployeeLogin login = new EmployeeLogin { Username = "******", Password = "******", ServiceType = ServiceType.Pharmacist, StationNumber = 1 }; ActionResult <EmployeeInfo> loginResult = await controller.PostEmployeeLogin(login); IActionResult result = await controller.PostEmployeeLogout(login.Username); Assert.IsInstanceOf <IActionResult>(result); Assert.IsInstanceOf <OkResult>(result); Employee employee = context.Employees.Where(e => e.Username == login.Username).Single(); Assert.IsFalse(employee.Online); Assert.IsNull(employee.StationId); } }