public void Given_AppointmentRepository_When_AddAsyncingAnAppointment_Then_TheAppointmentShouldBeProperlySaved()
        {
            RunOnDatabase(async ctx =>
            {
                //Arrange
                var repository = new AppointmentRepository(ctx);
                var patient    = Patient.Create("Roland", "Iordache", "*****@*****.**", "asfdsdssd", "Iasi",
                                                new DateTime(1996, 02, 10), "0746524459", null);
                var doctor      = Doctor.Create("a", "b", "*****@*****.**", "adcd", "0334123123", "ads", "ads", "dsd", "dsds", "dsds");
                var appointment = Appointment.Create(new DateTime(1996, 02, 10), doctor, patient);

                //Act
                await repository.AddAsync(appointment);

                //Assert
                Assert.AreEqual(repository.GetAllAsync().Result.Count, 1);
            });
        }
        public void ShouldGetAll()
        {
            var userId             = 35;
            var customerId         = 23;
            var start              = DateTime.Now;
            var end                = start.AddDays(1);
            var searchTerm         = "test";
            var appointments       = fixture.CreateMany <Appointment>().ToList();
            var expectedSqlSegment = " AND appointment.customerId = @customerId AND appointment.userId = @userId AND (username LIKE @searchTerm OR type LIKE @searchTerm OR customer.name LIKE @searchTerm OR crewName LIKE @searchTerm OR title LIKE @searchTerm OR description LIKE @searchTerm OR location LIKE @searchTerm)";

            var sqlMock = new Mock <ISqlOrm>();

            sqlMock.Setup(m => m.QueryListAsync <Appointment>(It.Is <string>(s => s.Contains(expectedSqlSegment)), It.Is <object>(o => JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(new { userId, customerId, start, end, searchTerm = $"%{searchTerm}%" })))).ReturnsAsync(appointments);

            var repo = new AppointmentRepository(sqlMock.Object);

            var result = repo.GetAllAsync(start, end, userId, customerId, searchTerm).Result;

            Assert.Equal(appointments, result);
        }
Beispiel #3
0
        public void Given_AppointmentRepository_When_DeletingAnAppointment_Then_TheAppointmentShouldBeProperlyRemoved()
        {
            RunOnDatabase(async ctx =>
            {
                //Arrange
                var repository          = new AppointmentRepository(ctx);
                var patient             = Patient.Create("1234", "Roland", "Iordache", "*****@*****.**", "asfdsdssd", "Iasi", "Romania", new DateTime(1996, 02, 10), "0746524459", null);
                var doctor              = Doctor.Create("1234", "Mircea", "Cartarescu", "*****@*****.**", "parola", "0746524459", "blasdadsadsada", "Cardiologie", "Sf. Spiridon", "Iasi", "Romania", "Str. Vasile Lupu", true);
                var appointmentInterval = AppointmentInterval.Create(3, new TimeSpan(0, 10, 0, 0), new TimeSpan(0, 11, 0, 0), doctor.DoctorId);
                var appointment         = Appointment.Create(appointmentInterval.AppointmentIntervalId, new DateTime(1996, 02, 10), doctor.DoctorId, patient.PatientId);
                await repository.AddAsync(appointment);

                //Act
                await repository.DeleteAsync(appointment.PatientId);

                //Assert
                string[] includes = { };
                Assert.AreEqual(repository.GetAllAsync(includes).Result.Count, 0);
            });
        }