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());
        }
Пример #2
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);
            }
        }
Пример #3
0
        public async void CancelAppointment_WhenCalledWithInvalidAppointment_ReturnsBadRequest()
        {
            // Arrange
            var apptItem = new AppointmentEntity()
            {
                PatientID           = 200,
                AppointmentDateTime = DateTime.Now.AddDays(20) //invalid appointment max today + 14 days
            };
            var apptDtoItem = FakeBookings.GetFakeAppointmentDto();
            var mapper      = TestHelpers.Helpers.GetAppointmentMapperForTest();

            _repo.CancelBookingAsync(apptItem).ReturnsForAnyArgs(false);

            var mycontroller       = new AppointmentsController(_repo, _notify, mapper, _logger);
            var expectedCodeResult = new StatusCodeResult(400);

            // Act
            var sut = await mycontroller.CancelAppointment(apptDtoItem);

            var result = sut as BadRequestResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedCodeResult.StatusCode, result.StatusCode);
        }
Пример #4
0
        public async void CreateAppointment_WhenCalledWithInvalidAppointment_ReturnsBadRequest()
        {
            // Arrange
            var apptItem = new AppointmentEntity()
            {
                PatientID           = 200,
                AppointmentDateTime = DateTime.Now.AddDays(20) /* Invalid data: Rule is appointment can be booked upto two weeks ahead only */
            };
            var apptDtoItem = FakeBookings.GetFakeAppointmentDto();
            var mapper      = TestHelpers.Helpers.GetAppointmentMapperForTest();

            _repo.CreateBookingAsync(apptItem).ReturnsForAnyArgs(false);

            var mycontroller       = new AppointmentsController(_repo, _notify, mapper, _logger);
            var expectedCodeResult = new StatusCodeResult(400);


            // Act
            var sut = await mycontroller.Create(apptDtoItem);

            var result = sut as BadRequestObjectResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedCodeResult.StatusCode, result.StatusCode);
        }
Пример #5
0
        public async void CreateAppointment_WhenCalledWithValidAppointment_ReturnsCreated()
        {
            // Arrange
            var apptItem = new AppointmentEntity()
            {
                PatientID           = 200,
                AppointmentDateTime = DateTime.Now.AddDays(1)
            };
            var apptDtoItem = FakeBookings.GetFakeAppointmentDto();
            var mapper      = TestHelpers.Helpers.GetAppointmentMapperForTest();

            _repo.CreateBookingAsync(apptItem).ReturnsForAnyArgs(true);

            var mycontroller       = new AppointmentsController(_repo, _notify, mapper, _logger);
            var expectedCodeResult = new StatusCodeResult(201);


            // Act
            var sut = await mycontroller.Create(apptDtoItem);

            var result = sut as StatusCodeResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedCodeResult.StatusCode, result.StatusCode);
        }
Пример #6
0
        public async void UpdateAppointment_WhenCalledWithValidAppointment_ReturnsBadRequest()
        {
            // Arrange
            var apptItem = new ChangedAppointmentDto()
            {
                PatientID              = 12,
                AppointmentDateTime    = new DateTime(2020, 08, 12, 13, 30, 00),
                NewAppointmentDateTime = new DateTime(2020, 08, 12, 14, 30, 00)
            };
            var apptItemEntity = new ChangedAppointmentEntity()
            {
                PatientID              = 12,
                AppointmentDateTime    = new DateTime(2020, 08, 12, 13, 30, 00),
                NewAppointmentDateTime = new DateTime(2020, 08, 12, 14, 30, 00)
            };

            var mapper = TestHelpers.Helpers.GetChangedAppointmentMapperForTest();

            _repo.UpdateBookingAsync(apptItemEntity).ReturnsForAnyArgs(false);

            var mycontroller       = new AppointmentsController(_repo, _notify, mapper, _logger);
            var expectedCodeResult = new StatusCodeResult(400);

            // Act
            var sut = await mycontroller.UpdateAppointment(apptItem);

            var result = sut as BadRequestObjectResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(expectedCodeResult.StatusCode, result.StatusCode);
        }
        public async Task Index_Returns_ViewResult()
        {
            IFixture fixture = new Fixture();

            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            var model = fixture.Create <EditAppointmentViewModel>();

            _appService.Setup(c => c.EditAppointment(It.IsAny <int>(), It.IsAny <string>(), CancellationToken.None))
            .ReturnsAsync(model);

            var appointmentsController = new AppointmentsController(_appService.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext
                    {
                        User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, "user") },
                                                                      "test"))
                    }
                }
            };

            var action = await appointmentsController.Index(1);

            Assert.IsInstanceOf <ViewResult>(action);
        }
        public async void AddAppointment_Returns_addAppointment()
        {
            //Arrange
            var    book     = new List <Appointment>();
            string DateTime = "19-09-2021";

            book.Add(new Appointment()
            {
                Id                    = Guid.NewGuid(),
                AnyPetHair            = false,
                Date                  = DateTime,
                PowerOutletAvailable  = true,
                Vehicles              = null,
                WaterHoseAvailability = true,
                WaterSupplyConnection = true,
            });
            var repo = new Mock <IGenericRepository <Appointment> >();

            repo.Setup(x => x.GetAll()).Returns(Task.FromResult <IEnumerable <Appointment> >(book));
            //repo.Verify();
            var config = new Mock <IConfiguration>();
            var logger = new Mock <ILogger <AppointmentsController> >();
            AppointmentsController controller = new AppointmentsController(logger.Object, repo.Object, config.Object);
            int    expectedCount = 1;
            String expectedDate  = "19-09-2021";
            //Act
            ViewResult result         = (ViewResult)controller.Book();
            int        actualCount    = book.Count;
            String     actualBookDate = DateTime;


            //Assert
            Assert.Equal(expectedCount, actualCount);
            // Assert.Equal(expectedDealTitle, actualBookID);
        }
        public async Task ShouldModifyAppointment()
        {
            var appointment = 1;
            var body        = new ReAssingmentAppointment()
            {
                reassigmentDate = DateTime.Now.AddDays(1).ToShortDateString(),
                doctorId        = 3
            };

            var appointmentController = new AppointmentsController(new Services.AppointmentServices())
            {
                Request = new HttpRequestMessage
                {
                    Method     = HttpMethod.Put,
                    Content    = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json"),
                    RequestUri = new Uri($"{url}/{appointment}")
                }
            };

            appointmentController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var response = appointmentController.modifyAppointment(appointment, body);
            var result   = await response.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(result.StatusCode, HttpStatusCode.OK);
        }
Пример #10
0
        public void CreateAppointment()
        {
            var repo = new Mock <IRepository <Appointment> >();
            // Arrange
            AppointmentRepository  rep        = new AppointmentRepository();
            PeopleRepository       peopleRep  = new PeopleRepository();
            AppointmentsController controller = new AppointmentsController(rep.Repo, peopleRep.Repo);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();
            var testAppointment = new AppointmentDTO()
            {
                Client       = new PersonDTO(peopleRep.Repo.All().FirstOrDefault(o => o.ApplicationUser.UserName == "*****@*****.**")),
                Collaborater = new PersonDTO(peopleRep.Repo.All().FirstOrDefault(o => o.ApplicationUser.UserName == "*****@*****.**")),
                StartDate    = DateTime.UtcNow,
                EndDate      = DateTime.UtcNow.AddHours(2),
                Status       = AppointmentStatus.Pending,
                Note         = "plata o plomo"
            };

            // Act
            IHttpActionResult result = controller.Post("*****@*****.**", testAppointment);
            var contentResult        = result as OkNegotiatedContentResult <AppointmentDTO>;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(testAppointment.StartDate, contentResult.Content.StartDate);
        }
Пример #11
0
 public AppoinmentsControllerTests()
 {
     _repo      = NSubstitute.Substitute.For <IAppointmentRepository>();
     _logger    = NSubstitute.Substitute.For <ILogger <AppointmentsController> >();
     _notify    = NSubstitute.Substitute.For <INotifier>();
     _mapper    = NSubstitute.Substitute.For <IMapper>();
     controller = new AppointmentsController(_repo, _notify, _mapper, _logger);
 }
Пример #12
0
        public void TestGetAppointmentsFail()
        {
            MockBusinessAppointmentFail();
            AppointmentsController controller = new AppointmentsController(businessAppointment);
            List <Appointment>     result     = controller.GetAppointments();

            Assert.IsNull(result);
        }
Пример #13
0
        public void ErrorPageWhenInvalidID()
        {
            int id = -1;
            AppointmentsController a = SetMockAndGetAppointmentController();
            var result = a.Details(id);

            //result moet een not found zijn
            Assert.IsType <NotFoundResult>(result);
        }
Пример #14
0
 public AppointmentsControllerTests()
 {
     _fixture = new Fixture().Customize(new AutoMoqCustomization());
     _fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
     _fixture.Behaviors.Add(new OmitOnRecursionBehavior());
     _appointmentService     = _fixture.Freeze <Mock <IAppointmentService> >();
     _autoMapper             = _fixture.Freeze <Mock <IMapper> >();
     _appointmentsController = _fixture.Build <AppointmentsController>().OmitAutoProperties().Create();
 }
        public void Delete(int?id)
        {
            // Arrange
            AppointmentsController controller = new AppointmentsController();

            // Act
            ViewResult result = controller.Delete(id) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        internal AppointmentsControllerFactory()
        {
            // Context
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            Context = new ApplicationDbContext(options);
            Context.Database.EnsureDeleted(); // Ensures we have a new database with no data in it.
            Context.Database.EnsureCreated();
            Service = new AppointmentsController(Context);
        }
Пример #17
0
        public async System.Threading.Tasks.Task TestCreateAppointmentsRightAsync()
        {
            MockBusinessAppointmentRight();
            Appointment appointment = new Appointment {
                Id = 1, Date = new DateTime(2019, 05, 05, 12, 00, 23), PatientId = 1, Status = 1, Type = "Odontología"
            };
            AppointmentsController controller = new AppointmentsController(businessAppointment);
            IHttpActionResult      result     = await controller.PostAppointment(appointment);

            Assert.IsNotNull(result);
        }
        public void Create()
        {
            // Arrange
            AppointmentsController controller = new AppointmentsController();

            // Act
            ViewResult result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
        private static AppointmentsController GetAppointmentsController(IAppointmentRepository repository)
        {
            var controller = new AppointmentsController(repository);

            controller.ControllerContext = new ControllerContext
            {
                Controller     = controller,
                RequestContext = new RequestContext(new MockHttpContext(), new RouteData())
            };

            return(controller);
        }
Пример #20
0
        public void TestGetappointment()
        {
            //Arrange
            var appintmentID = 1;
            AppointmentsController appointmentController = new AppointmentsController();

            //Act
            IHttpActionResult actionResult = appointmentController.Getappointmentt(appintmentID);

            //Assert
            Assert.IsNotNull(actionResult);
        }
Пример #21
0
        public void GetAppointment()
        {
            var controller = new AppointmentsController();

            var request = new GetAppointmentsRequest
            {
                Start = DateTime.UtcNow.ToString(),
                End   = DateTime.UtcNow.AddDays(30).ToString()
            };
            var result = controller.GetDetails(request) as  OkNegotiatedContentResult <GetAppointmentsResponse>;

            Assert.IsNotNull(result.Content.Appointments);
        }
Пример #22
0
        public void CreateAppointmentTest()
        {
            string fakeDress = "fake";
            string fakecolor = "fake";

            AppointmentsController controller = SetMockAndGetAppointmentController();
            var mockAppContext = new Mock <ApplicationDbContext>();


            var Appointment = FakeAppointmentList.First();
            var result      = controller.Create(Appointment, fakeDress, fakecolor);

            Assert.IsType <RedirectToActionResult>(result);
        }
Пример #23
0
        public void CancelAppointment_InvalidData_BadRequest_Test()
        {
            //Arrage
            IDbContext  dbContext           = new MedicalAppointmentContext();
            IRepository repository          = new AppointmentRepository(dbContext);
            var         sut                 = new AppointmentsController(repository);
            var         appointmentToCancel = new Appointment();

            //Act
            var result = sut.Cancel(appointmentToCancel);

            //Assert
            Assert.IsTrue(result is BadRequestErrorMessageResult);
        }
Пример #24
0
        public void GetAppointmentByPatientId_NotNullResponse_Test()
        {
            //Arrage
            IDbContext  dbContext  = new MedicalAppointmentContext();
            IRepository repository = new AppointmentRepository(dbContext);
            var         sut        = new AppointmentsController(repository);

            //Act
            var result = sut.GetByPatientId(1) as OkNegotiatedContentResult <IEnumerable <IAppointment> >;
            var appointmentListResult = result.Content as List <Appointment>;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(appointmentListResult);
        }
Пример #25
0
        public void GetAppointmentsByPatientId_Count_AppointmentsResponse_Test()
        {
            //Arrage
            IDbContext  dbContext      = new MedicalAppointmentContext();
            IRepository repository     = new AppointmentRepository(dbContext);
            var         sut            = new AppointmentsController(repository);
            var         expectedResult = 1;

            //Act
            var result = sut.GetByPatientId(1) as OkNegotiatedContentResult <IEnumerable <IAppointment> >;
            var appointmentListResult = result.Content as List <Appointment>;

            //Assert
            Assert.AreEqual(expectedResult, appointmentListResult.Count);
        }
        public async void Book_Returns_BookView()
        {
            //Arrange
            var repo   = new Mock <IGenericRepository <Appointment> >();
            var config = new Mock <IConfiguration>();
            var logger = new Mock <ILogger <AppointmentsController> >();
            AppointmentsController controller = new AppointmentsController(logger.Object, repo.Object, config.Object);
            string expectedViewName           = null;

            //Act
            ViewResult result         = (ViewResult)(controller.Book());
            string     actualViewName = result.ViewName;

            //Assert
            Assert.Equal(expectedViewName, actualViewName);
        }
        public void Create_Appointment_RedirectToActionResult()
        {
            var mockContext = new Mock <OnlineClinicContext>();
            var controller  = new AppointmentsController(mockContext.Object);
            var appointment = new Appointment()
            {
                Id      = 1,
                Doctor  = new Doctor(),
                Patient = new Patient(),
                Slot    = new Slot()
            };

            var task = controller.Create(appointment);

            //Assert.IsType<RedirectToActionResult>(task.Result);
        }
Пример #28
0
        public static AppointmentsController SetMockAndGetAppointmentController()
        {
            var mockAppContext = Tools.MockTestDatabaseContext();

            var mockOptions = new Mock <IOptions <SecureAppConfig> >();
            var mockConfig  = new Mock <SecureAppConfig>();
            var mockService = new Mock <ITransactionalEmailService>();

            mockService.Setup(s => s.SendAppointmentEmail(It.IsAny <AppointmentMessageContainer>()));

            mockConfig.Setup(c => c.Owner).Returns("Miladin");
            mockOptions.Setup(c => c.Value).Returns(mockConfig.Object);

            AppointmentsController a = new AppointmentsController(mockAppContext, mockOptions.Object, mockService.Object);

            return(a);
        }
Пример #29
0
        public void AddAppointment_AppointmentSameDay_NotAdded_Test()
        {
            //Arrage
            IDbContext  dbContext        = new MedicalAppointmentContext();
            IRepository repository       = new AppointmentRepository(dbContext);
            var         sut              = new AppointmentsController(repository);
            var         appointmentToAdd = new Appointment()
            {
                Id = 4, PatientId = 2, AppointmentTypeId = 4, Date = new DateTime(2019, 8, 11, 15, 30, 00), IsActive = true
            };

            //Act
            var result = sut.Add(appointmentToAdd) as OkNegotiatedContentResult <bool>;

            //Assert
            Assert.IsTrue(!result.Content);
        }
Пример #30
0
        public void CancelAppointment_AppointmentDateMoreThan24Hours_NotCancelled_Test()
        {
            //Arrage
            IDbContext  dbContext           = new MedicalAppointmentContext();
            IRepository repository          = new AppointmentRepository(dbContext);
            var         sut                 = new AppointmentsController(repository);
            var         appointmentToCancel = new Appointment()
            {
                Id = 4, PatientId = 2, AppointmentTypeId = 4, Date = new DateTime(2019, 8, 11, 15, 30, 00), IsActive = true
            };

            //Act
            var result = sut.Cancel(appointmentToCancel) as OkNegotiatedContentResult <bool>;

            //Assert
            Assert.IsTrue(!result.Content);
        }