Ejemplo n.º 1
0
        public async Task ShouldPostValidFi()
        {
            // arrange;
            const string name     = "TEST_FI";
            var          command  = new Post.Command(name, null);
            var          expected = new FoodItemDto
            {
                Name       = name,
                PictureUrl = null
            };

            // act;
            var res = await SendMediatorRequestInScope(command);

            // assert;
            res
            .Should()
            .BeEquivalentTo(expected, o => o.Excluding(o => o.FoodItemId));

            // clean up;
            var fiToRemove = await Context.FoodItems
                             .FirstOrDefaultAsync(fi => fi.FoodItemId == res !.FoodItemId);

            Context.FoodItems.Remove(fiToRemove);
            await Context.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task ShouldPostValidBm()
        {
            // arrange;
            var dateTime = new DateTime(2021, 1, 1, 0, 0, 0);
            var command  = new Post.Command(dateTime, true, true);
            var expected = new BowelMovementEventDto
            {
                ContainedBlood = true,
                ContainedMucus = true,
                DateTime       = dateTime,
                PatientId      = TestUserHelper.TestPatientId
            };

            // act;
            var res = await SendMediatorRequestInScopeOnBehalfOfTheTestPatient(command);

            // assert;
            res
            .Should()
            .BeEquivalentTo(expected, options => options.Excluding(o => o.BowelMovementEventId));

            // clean up;
            var bmToRemove = await Context.BowelMovementEvents
                             .FirstOrDefaultAsync(bm => bm.BowelMovementEventId.Equals(res !.BowelMovementEventId));

            Context.BowelMovementEvents.Remove(bmToRemove);
            await Context.SaveChangesAsync();
        }
Ejemplo n.º 3
0
        public async Task ShouldPostValidAppointment()
        {
            // arrange;
            const string doctorId  = "auth0|6076cf2ec42780006af85a96";
            var          startDate = new DateTime(2021, 10, 10);
            const int    duration  = 60;

            var command = new Post.Command(TestUserHelper.TestPatientId, doctorId,
                                           startDate, duration, null, null);
            var expected = new AppointmentDto
            {
                PatientId       = TestUserHelper.TestPatientId,
                DoctorId        = "auth0|6076cf2ec42780006af85a96",
                StartDateTime   = startDate,
                DurationMinutes = duration,
                DoctorNotes     = null,
                PatientNotes    = null
            };

            // act;
            var res = await SendMediatorRequestInScopeOnBehalfOfTheTestPatient(command);

            // assert;
            res.Should().BeEquivalentTo(expected, options => options
                                        .Excluding(o => o.Location)
                                        .Excluding(o => o.AppointmentId)
                                        .Excluding(o => o.DoctorName));

            // clean up;
            var appointmentToRemove =
                await Context.Appointments.FirstOrDefaultAsync(a => a.AppointmentId.Equals(res.AppointmentId));

            Context.Appointments.Remove(appointmentToRemove);
            await Context.SaveChangesAsync();
        }
        public async Task <ActionResult <BowelMovementEventDto> > PostBmForMe(
            [FromBody] Post.Command command)
        {
            var res = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetOneForMeById), new { bowelMovementEventId = res.BowelMovementEventId }, res));
        }
Ejemplo n.º 5
0
        public async Task ShouldFailIfDoctorDoesNotExist()
        {
            // arrange;
            const string doctorId  = "THIS_DOCTOR_ID_DOES_NOT_EXIST";
            var          startDate = new DateTime(2021, 10, 10);
            const int    duration  = 60;
            var          command   = new Post.Command(TestUserHelper.TestPatientId, doctorId,
                                                      startDate, duration, null, null);

            // act;
            Func <Task <AppointmentDto?> > act = async() =>
                                                 await SendMediatorRequestInScopeOnBehalfOfTheTestPatient(command);

            // arrange;
            await act
            .Should()
            .ThrowAsync <DbUpdateException>();
        }
Ejemplo n.º 6
0
        public async Task CommandHandler_CreatesDocument()
        {
            // the setup

            var db = CreateDbContext();

            var userContext = new Mock<IUserContext>();

            userContext
                .Setup(x => x.UserId)
                .Returns("TestUser");

            var fileMover = new Mock<IFileMover>();

            fileMover
                .Setup(x => x.Move(It.IsAny<byte[]>(), It.IsAny<byte[]>()))
                .Returns(Task.FromResult(@"\\127.0.0.1\nofile"));

            var fileEncryptor = new Mock<IFileEncryptor>();

            fileEncryptor
                .Setup(x => x.Encrypt(It.IsAny<byte[]>(), It.IsAny<byte[]>()))
                .Returns(new byte[] {});

            var testFile = CreateTestFile();
            var fileInfo = CreateFileInfo(testFile);

            var fileDecoder = new Mock<IFileDecoder>();

            fileDecoder
                .Setup(x => x.Decode(It.IsAny<string>(), It.IsAny<byte[]>()))
                .Returns(fileInfo);

            var commandHandler = new Post.CommandHandler(db, userContext.Object, fileMover.Object,
                fileDecoder.Object, fileEncryptor.Object);

            var command = new Post.Command
            {
                File = testFile
            };

            var result = await commandHandler.Handle(command);

            // the test

            Assert.NotNull(result);
            Assert.True(result.Status == Post.Result.StatusTypes.Success);
            Assert.True(result.DocumentId == 1);

            var document = await db.Documents
                .Include(d => d.Content)
                .Include(d => d.Files)
                .SingleOrDefaultAsync(d => d.Id == result.DocumentId);

            Assert.NotNull(document);
            Assert.True(document.Status == StatusTypes.Active);

            Assert.Equal(document.Abstract, fileInfo.Abstract);

            Assert.NotNull(document.Content);
            Assert.NotNull(document.Content?.Content);
            Assert.Equal(document.Content?.Content, fileInfo.Content);

            Assert.True(document.Files.Count == 1);

            var file = document.Files.First();

            Assert.NotNull(file.Extension);
            Assert.Equal(file.Extension, Path.GetExtension(testFile.FileName));

            Assert.NotNull(file.Path);
            Assert.NotNull(file.ThumbnailPath);
            Assert.NotNull(file.Key);
            
        }
        public async Task <ActionResult <AppointmentDto> > PostAppointmentForMe([FromBody] Post.Command command)
        {
            var res = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetOneForMeById), new { appointmentId = res.AppointmentId }, res));
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <GlobalNotificationDto> > Post([FromBody] Post.Command command)
        {
            var res = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetById), new { id = res.GlobalNotificationId }, res));
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <PainEventDto> > PostForMe([FromBody] Post.Command command)
        {
            var res = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetForMeById), new { painEventId = res.PainEventId }, res));
        }
Ejemplo n.º 10
0
 public async Task <ActionResult> Post([FromBody] Post.Command command) =>
 await _mediator.Send(command);
Ejemplo n.º 11
0
        public async Task <ActionResult> Post([FromBody] Post.Command command)
        {
            var res = await _mediator.Send(command);

            return(CreatedAtAction(nameof(GetById), new { id = res.BowelMovementEventId }, res));
        }
    public async Task <IActionResult> Post([FromBody] Post.Command command)
    {
        var model = await mediator.Send(command);

        return(Ok(model));
    }
Ejemplo n.º 13
0
 public async Task <ActionResult <Unit> > Post([FromBody] Post.Command command)
 {
     return(await Mediator.Send(command));
 }
Ejemplo n.º 14
0
        public async Task CommandHandler_CreatesDocument()
        {
            // the setup

            var db = CreateDbContext();

            var userContext = new Mock <IUserContext>();

            userContext
            .Setup(x => x.UserId)
            .Returns("TestUser");

            var fileMover = new Mock <IFileMover>();

            fileMover
            .Setup(x => x.Move(It.IsAny <byte[]>(), It.IsAny <byte[]>()))
            .Returns(Task.FromResult(@"\\127.0.0.1\nofile"));

            var fileEncryptor = new Mock <IFileEncryptor>();

            fileEncryptor
            .Setup(x => x.Encrypt(It.IsAny <byte[]>(), It.IsAny <byte[]>()))
            .Returns(new byte[] {});

            var testFile = CreateTestFile();
            var fileInfo = CreateFileInfo(testFile);

            var fileDecoder = new Mock <IFileDecoder>();

            fileDecoder
            .Setup(x => x.Decode(It.IsAny <string>(), It.IsAny <byte[]>()))
            .Returns(fileInfo);

            var commandHandler = new Post.CommandHandler(db, userContext.Object, fileMover.Object,
                                                         fileDecoder.Object, fileEncryptor.Object);

            var command = new Post.Command
            {
                File = testFile
            };

            var result = await commandHandler.Handle(command);

            // the test

            Assert.NotNull(result);
            Assert.True(result.Status == Post.Result.StatusTypes.Success);
            Assert.True(result.DocumentId == 1);

            var document = await db.Documents
                           .Include(d => d.Content)
                           .Include(d => d.Files)
                           .SingleOrDefaultAsync(d => d.Id == result.DocumentId);

            Assert.NotNull(document);
            Assert.True(document.Status == StatusTypes.Active);

            Assert.Equal(document.Abstract, fileInfo.Abstract);

            Assert.NotNull(document.Content);
            Assert.NotNull(document.Content?.Content);
            Assert.Equal(document.Content?.Content, fileInfo.Content);

            Assert.True(document.Files.Count == 1);

            var file = document.Files.First();

            Assert.NotNull(file.Extension);
            Assert.Equal(file.Extension, Path.GetExtension(testFile.FileName));

            Assert.NotNull(file.Path);
            Assert.NotNull(file.ThumbnailPath);
            Assert.NotNull(file.Key);
        }