Exemplo n.º 1
0
        public async Task GetAppointments_WhenCalled_ReturnsAllItemsForReceptionist()
        {
            // Arrange
            var dbName = Guid.NewGuid().ToString();

            FakeDatabaseSeed(dbName);

            using (var context = new ApplicationDbContext(CreateOptions(dbName)))
            {
                // Arrange
                var controller = new AppointmentsController(context);

                var httpContextMock = new Mock <HttpContext>();
                httpContextMock.Setup(h => h.User.IsInRole("Receptionist"))
                .Returns(true);

                var controllerContextMock = new Mock <ControllerContext>();
                controllerContextMock.Object.HttpContext = httpContextMock.Object;

                controller.ControllerContext = controllerContextMock.Object;

                // Act
                var result = await controller.GetAppointments();

                // Assert
                var appointments = Assert.IsType <List <Appointment> >(result.Value);
                Assert.Equal(2, appointments.Count);
            }
        }
        public void GetAppointmets_NotOwnAppointmentNotListed()
        {
            //given
            var testData = new List <Appointment> {
                new Appointment {
                    Mechanic = testMechanic2,
                    Partner  = testPartner,
                    Time     = DateTime.Now.AddHours(1),
                    WorkType = "maintenance",
                    Note     = ""
                }
            };

            _context.Appointments.AddRange(testData);
            _context.SaveChanges();

            AppointmentsController underTest = new AppointmentsController(_context);

            SetupUser(underTest, "mechanic123");

            //when
            var result = underTest.GetAppointments();

            //then
            Assert.IsNotNull(result);
            var okResult = result as OkObjectResult;

            Assert.IsInstanceOf <OkObjectResult>(okResult, result.GetType().ToString());
            var collectionResult = okResult.Value as IEnumerable <AppointmentDTO>;

            Assert.IsInstanceOf <IEnumerable <AppointmentDTO> >(collectionResult, result.GetType().ToString());
            Assert.AreEqual(0, collectionResult.Count());
        }
Exemplo n.º 3
0
        public void TestGetAppointmentsFail()
        {
            MockBusinessAppointmentFail();
            AppointmentsController controller = new AppointmentsController(businessAppointment);
            List <Appointment>     result     = controller.GetAppointments();

            Assert.IsNull(result);
        }
Exemplo n.º 4
0
        public async Task GetAppointments_WhenCalled_ReturnsUnauthorizedWhenUserNotAuthorized()
        {
            using (var context = new ApplicationDbContext(CreateOptions(Guid.NewGuid().ToString())))
            {
                // Arrange
                var controller = new AppointmentsController(context);

                var httpContextMock = new Mock <HttpContext>();
                httpContextMock.Setup(h => h.User.IsInRole(It.IsAny <string>()))
                .Returns(false);

                var controllerContextMock = new Mock <ControllerContext>();
                controllerContextMock.Object.HttpContext = httpContextMock.Object;

                controller.ControllerContext = controllerContextMock.Object;

                // Act
                var result = await controller.GetAppointments();

                // Assert
                Assert.IsType <UnauthorizedResult>(result.Result);
            }
        }