Ejemplo n.º 1
0
        public async Task UpdatePartialPatient_Returns_Forbidden_Without_Proper_Scope()
        {
            //Arrange
            var mapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <PatientProfile>();
            }).CreateMapper();

            var fakePatientOne = new FakePatient {
            }.Generate();
            var expectedFinalObject = mapper.Map <PatientDto>(fakePatientOne);
            var id = fakePatientOne.PatientId;

            var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            client.AddAuth(new[] { "" });

            // Act
            var patchResult = await client.PutAsJsonAsync($"api/Patients/{id}", expectedFinalObject)
                              .ConfigureAwait(false);

            // Assert
            patchResult.StatusCode.Should().Be(403);
        }
        public void GetPatient_ParametersMatchExpectedValues()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <LabDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PatientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakePatient = new FakePatient {
            }.Generate();

            //Act
            using (var context = new LabDbContext(dbOptions))
            {
                context.Patients.AddRange(fakePatient);
                context.SaveChanges();

                var service = new PatientRepository(context, new SieveProcessor(sieveOptions));

                //Assert
                var patientById = service.GetPatient(fakePatient.PatientId);
                patientById.PatientId.Should().Be(fakePatient.PatientId);
                patientById.FirstName.Should().Be(fakePatient.FirstName);
                patientById.LastName.Should().Be(fakePatient.LastName);
                patientById.Sex.Should().Be(fakePatient.Sex);
                patientById.Gender.Should().Be(fakePatient.Gender);
                patientById.Race.Should().Be(fakePatient.Race);
                patientById.Ethnicity.Should().Be(fakePatient.Ethnicity);
            }
        }
Ejemplo n.º 3
0
        public async Task UpdateRecordPatients_Returns_Unauthorized_Without_Valid_Token()
        {
            //Arrange
            var mapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <PatientProfile>();
            }).CreateMapper();

            var fakePatientOne = new FakePatient {
            }.Generate();
            var expectedFinalObject = mapper.Map <PatientDto>(fakePatientOne);
            var id = fakePatientOne.PatientId;

            var patchDoc = new JsonPatchDocument <PatientForUpdateDto>();

            patchDoc.Replace(p => p.ExternalId, "");
            var serializedPatientToUpdate = JsonConvert.SerializeObject(patchDoc);

            var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            // Act
            var putResult = await client.PutAsJsonAsync($"api/Patients/{id}", expectedFinalObject)
                            .ConfigureAwait(false);

            // Assert
            putResult.StatusCode.Should().Be(401);
        }
Ejemplo n.º 4
0
        public async Task GetPatients_Returns_Unauthorized_Without_Valid_Token()
        {
            var fakePatientOne = new FakePatient {
            }.Generate();
            var fakePatientTwo = new FakePatient {
            }.Generate();

            var appFactory = _factory;

            using (var scope = appFactory.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <LabDbContext>();
                context.Database.EnsureCreated();

                //context.Patients.RemoveRange(context.Patients);
                context.Patients.AddRange(fakePatientOne, fakePatientTwo);
                context.SaveChanges();
            }

            var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            var result = await client.GetAsync("api/Patients")
                         .ConfigureAwait(false);

            // Assert
            result.StatusCode.Should().Be(401);
        }
Ejemplo n.º 5
0
        public async Task UpdatePartialPatients_Returns_Unauthorized_Without_Valid_Token()
        {
            //Arrange
            var mapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <PatientProfile>();
            }).CreateMapper();

            var fakePatientOne = new FakePatient {
            }.Generate();
            var expectedFinalObject = mapper.Map <PatientDto>(fakePatientOne);
            var id = fakePatientOne.PatientId;

            var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });
            var patchDoc = new JsonPatchDocument <PatientForUpdateDto>();

            patchDoc.Replace(p => p.ExternalId, "");
            var serializedPatientToUpdate = JsonConvert.SerializeObject(patchDoc);

            // Act
            var method       = new HttpMethod("PATCH");
            var patchRequest = new HttpRequestMessage(method, $"api/Patients/{id}")
            {
                Content = new StringContent(serializedPatientToUpdate,
                                            Encoding.Unicode, "application/json")
            };
            var patchResult = await client.SendAsync(patchRequest)
                              .ConfigureAwait(false);

            // Assert
            patchResult.StatusCode.Should().Be(401);
        }
        public async Task DeletePatient204AndFieldsWereSuccessfullyUpdated_WithAuth()
        {
            //Arrange
            var fakePatientOne = new FakePatient {
            }.Generate();

            var appFactory = _factory;

            using (var scope = appFactory.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <VerticalLabTestPostgresDbContext> ();
                context.Database.EnsureCreated();

                context.Patients.RemoveRange(context.Patients);
                context.Patients.AddRange(fakePatientOne);
                context.SaveChanges();
            }

            var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            client.AddAuth(new[] { "patients.read", "patients.delete" });

            // Act
            // get the value i want to update. assumes I can use sieve for this field. if this is not an option, just use something else
            var getResult = await client.GetAsync($"api/Patients/?filters=ExternalId=={fakePatientOne.ExternalId}")
                            .ConfigureAwait(false);

            var getResponseContent = await getResult.Content.ReadAsStringAsync()
                                     .ConfigureAwait(false);

            var getResponse = JsonConvert.DeserializeObject <Response <IEnumerable <PatientDto> > >(getResponseContent);
            var id          = getResponse.Data.FirstOrDefault().PatientId;

            // delete it
            var method        = new HttpMethod("DELETE");
            var deleteRequest = new HttpRequestMessage(method, $"api/Patients/{id}");
            var deleteResult  = await client.SendAsync(deleteRequest)
                                .ConfigureAwait(false);

            // get it again to confirm updates
            var checkResult = await client.GetAsync($"api/Patients/{id}")
                              .ConfigureAwait(false);

            var checkResponseContent = await checkResult.Content.ReadAsStringAsync()
                                       .ConfigureAwait(false);

            var checkResponse = JsonConvert.DeserializeObject <Response <PatientDto> >(checkResponseContent);

            // Assert
            deleteResult.StatusCode.Should().Be(204);
            checkResponse.Data.Should().Be(null);
        }
        public async Task GetPatient_Returns_Unauthorized_Without_Valid_Token()
        {
            var fakePatientOne = new FakePatient {
            }.Generate();
            var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            var result = await client.GetAsync($"api/Patients/{fakePatientOne.PatientId}")
                         .ConfigureAwait(false);

            // Assert
            result.StatusCode.Should().Be(401);
        }
        public async Task GetPatient_Returns_Forbidden_Without_Proper_Scope()
        {
            var fakePatientOne = new FakePatient {
            }.Generate();
            var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            client.AddAuth(new[] { "" });

            var result = await client.GetAsync($"api/Patients/{fakePatientOne.PatientId}")
                         .ConfigureAwait(false);

            // Assert
            result.StatusCode.Should().Be(403);
        }
Ejemplo n.º 9
0
        public async Task GetPatients_ReturnsSuccessCodeAndResourceWithAccurateFields_WithAuth()
        {
            var fakePatientOne = new FakePatient {
            }.Generate();
            var fakePatientTwo = new FakePatient {
            }.Generate();

            var appFactory = _factory;

            using (var scope = appFactory.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <LabDbContext>();
                context.Database.EnsureCreated();

                //context.Patients.RemoveRange(context.Patients);
                context.Patients.AddRange(fakePatientOne, fakePatientTwo);
                context.SaveChanges();
            }

            var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            client.AddAuth(new[] { "patients.read", "openid", "profile" });

            var result = await client.GetAsync("api/Patients")
                         .ConfigureAwait(false);

            var responseContent = await result.Content.ReadAsStringAsync()
                                  .ConfigureAwait(false);

            var response = JsonConvert.DeserializeObject <Response <IEnumerable <PatientDto> > >(responseContent)?.Data;

            // Assert
            result.StatusCode.Should().Be(200);
            response.Should().ContainEquivalentOf(fakePatientOne, options =>
                                                  options.ExcludingMissingMembers());
            response.Should().ContainEquivalentOf(fakePatientTwo, options =>
                                                  options.ExcludingMissingMembers());
        }
        public async void GetPatientsAsync_ReturnExpectedPageSize()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <LabDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PatientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakePatientOne = new FakePatient {
            }.Generate();
            var fakePatientTwo = new FakePatient {
            }.Generate();
            var fakePatientThree = new FakePatient {
            }.Generate();

            // need id's due to default sorting
            fakePatientOne.PatientId   = 1;
            fakePatientTwo.PatientId   = 2;
            fakePatientThree.PatientId = 3;

            //Act
            using (var context = new LabDbContext(dbOptions))
            {
                context.Patients.AddRange(fakePatientOne, fakePatientTwo, fakePatientThree);
                context.SaveChanges();

                var service = new PatientRepository(context, new SieveProcessor(sieveOptions));

                var patientRepo = await service.GetPatientsAsync(new PatientParametersDto { PageSize = 2 });

                //Assert
                patientRepo.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                patientRepo.Should().ContainEquivalentOf(fakePatientOne);
                patientRepo.Should().ContainEquivalentOf(fakePatientTwo);

                context.Database.EnsureDeleted();
            }
        }
        public async Task DeleteRecordPatients_Returns_Unauthorized_Without_Valid_Token()
        {
            //Arrange
            var fakePatientOne = new FakePatient {
            }.Generate();
            var id = fakePatientOne.PatientId;

            var client = _factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            // Act
            var method        = new HttpMethod("DELETE");
            var deleteRequest = new HttpRequestMessage(method, $"api/Patients/{id}");
            var deleteResult  = await client.SendAsync(deleteRequest)
                                .ConfigureAwait(false);

            // Assert
            deleteResult.StatusCode.Should().Be(401);
        }
        public async void GetPatientsAsync_FilterRaceListWithExact()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <LabDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PatientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakePatientOne = new FakePatient {
            }.Generate();

            fakePatientOne.Race = "alpha";

            var fakePatientTwo = new FakePatient {
            }.Generate();

            fakePatientTwo.Race = "bravo";

            var fakePatientThree = new FakePatient {
            }.Generate();

            fakePatientThree.Race = "charlie";

            //Act
            using (var context = new LabDbContext(dbOptions))
            {
                context.Patients.AddRange(fakePatientOne, fakePatientTwo, fakePatientThree);
                context.SaveChanges();

                var service = new PatientRepository(context, new SieveProcessor(sieveOptions));

                var patientRepo = await service.GetPatientsAsync(new PatientParametersDto { Filters = $"Race == {fakePatientTwo.Race}" });

                //Assert
                patientRepo.Should()
                .HaveCount(1);

                context.Database.EnsureDeleted();
            }
        }
        public async void GetPatientsAsync_ListEthnicitySortedInDescOrder()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <LabDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PatientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakePatientOne = new FakePatient {
            }.Generate();

            fakePatientOne.Ethnicity = "bravo";

            var fakePatientTwo = new FakePatient {
            }.Generate();

            fakePatientTwo.Ethnicity = "alpha";

            var fakePatientThree = new FakePatient {
            }.Generate();

            fakePatientThree.Ethnicity = "charlie";

            //Act
            using (var context = new LabDbContext(dbOptions))
            {
                context.Patients.AddRange(fakePatientOne, fakePatientTwo, fakePatientThree);
                context.SaveChanges();

                var service = new PatientRepository(context, new SieveProcessor(sieveOptions));

                var patientRepo = await service.GetPatientsAsync(new PatientParametersDto { SortOrder = "-Ethnicity" });

                //Assert
                patientRepo.Should()
                .ContainInOrder(fakePatientThree, fakePatientOne, fakePatientTwo);

                context.Database.EnsureDeleted();
            }
        }
        public void DeletePatient_ReturnsProperCount()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <LabDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PatientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakePatientOne = new FakePatient {
            }.Generate();
            var fakePatientTwo = new FakePatient {
            }.Generate();
            var fakePatientThree = new FakePatient {
            }.Generate();

            //Act
            using (var context = new LabDbContext(dbOptions))
            {
                context.Patients.AddRange(fakePatientOne, fakePatientTwo, fakePatientThree);

                var service = new PatientRepository(context, new SieveProcessor(sieveOptions));
                service.DeletePatient(fakePatientTwo);

                context.SaveChanges();

                //Assert
                var patientList = context.Patients.ToList();

                patientList.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                patientList.Should().ContainEquivalentOf(fakePatientOne);
                patientList.Should().ContainEquivalentOf(fakePatientThree);
                Assert.DoesNotContain(patientList, p => p == fakePatientTwo);

                context.Database.EnsureDeleted();
            }
        }
        public async Task DeletePatientCommand_Deletes_Patient_From_Db()
        {
            // Arrange
            var fakePatientOne = new FakePatient {
            }.Generate();

            await InsertAsync(fakePatientOne);

            var patient = await ExecuteDbContextAsync(db => db.Patients.SingleOrDefaultAsync());

            var patientId = patient.PatientId;

            // Act
            var command         = new DeletePatientCommand(patientId);
            var patientReturned = await SendAsync(command);

            await SendAsync(command);

            var patients = await ExecuteDbContextAsync(db => db.Patients.ToListAsync());

            // Assert
            patients.Count.Should().Be(0);
        }
        public async void GetPatientsAsync_CountMatchesAndContainsEquivalentObjects()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <LabDbContext>()
                            .UseInMemoryDatabase(databaseName: $"PatientDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakePatientOne = new FakePatient {
            }.Generate();
            var fakePatientTwo = new FakePatient {
            }.Generate();
            var fakePatientThree = new FakePatient {
            }.Generate();

            //Act
            using (var context = new LabDbContext(dbOptions))
            {
                context.Patients.AddRange(fakePatientOne, fakePatientTwo, fakePatientThree);
                context.SaveChanges();

                var service = new PatientRepository(context, new SieveProcessor(sieveOptions));

                var patientRepo = await service.GetPatientsAsync(new PatientParametersDto());

                //Assert
                patientRepo.Should()
                .NotBeEmpty()
                .And.HaveCount(3);

                patientRepo.Should().ContainEquivalentOf(fakePatientOne);
                patientRepo.Should().ContainEquivalentOf(fakePatientTwo);
                patientRepo.Should().ContainEquivalentOf(fakePatientThree);

                context.Database.EnsureDeleted();
            }
        }
Ejemplo n.º 17
0
        public async Task PatchPatient204AndFieldsWereSuccessfullyUpdated()
        {
            //Arrange
            var mapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <PatientProfile>();
            }).CreateMapper();

            var lookupVal = "Easily Identified Value For Test"; // don't know the id at this scope, so need to have another value to lookup
            var fakePatientOne = new FakePatient {
            }.Generate();

            var expectedFinalObject = mapper.Map <PatientDto>(fakePatientOne);

            expectedFinalObject.FirstName = lookupVal;

            var appFactory = _factory;

            using (var scope = appFactory.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <LabDbContext> ();
                context.Database.EnsureCreated();

                context.Patients.RemoveRange(context.Patients);
                context.Patients.AddRange(fakePatientOne);
                context.SaveChanges();
            }

            var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            var patchDoc = new JsonPatchDocument <PatientForUpdateDto>();

            patchDoc.Replace(p => p.FirstName, lookupVal);
            var serializedPatientToUpdate = JsonConvert.SerializeObject(patchDoc);

            // Act
            // get the value i want to update. assumes I can use sieve for this field. if this is not an option, just use something else
            var getResult = await client.GetAsync($"api/Patients/?filters=FirstName=={fakePatientOne.FirstName}")
                            .ConfigureAwait(false);

            var getResponseContent = await getResult.Content.ReadAsStringAsync()
                                     .ConfigureAwait(false);

            var getResponse = JsonConvert.DeserializeObject <Response <IEnumerable <PatientDto> > >(getResponseContent);
            var id          = getResponse.Data.FirstOrDefault().PatientId;

            // patch it
            var method       = new HttpMethod("PATCH");
            var patchRequest = new HttpRequestMessage(method, $"api/Patients/{id}")
            {
                Content = new StringContent(serializedPatientToUpdate,
                                            Encoding.Unicode, "application/json")
            };
            var patchResult = await client.SendAsync(patchRequest)
                              .ConfigureAwait(false);

            // get it again to confirm updates
            var checkResult = await client.GetAsync($"api/Patients/{id}")
                              .ConfigureAwait(false);

            var checkResponseContent = await checkResult.Content.ReadAsStringAsync()
                                       .ConfigureAwait(false);

            var checkResponse = JsonConvert.DeserializeObject <Response <PatientDto> >(checkResponseContent);

            // Assert
            patchResult.StatusCode.Should().Be(204);
            checkResponse.Should().BeEquivalentTo(expectedFinalObject, options =>
                                                  options.ExcludingMissingMembers());
        }
Ejemplo n.º 18
0
        public async Task PutPatientReturnsBodyAndFieldsWereSuccessfullyUpdated()
        {
            //Arrange
            var mapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <PatientProfile>();
            }).CreateMapper();

            var fakePatientOne = new FakePatient {
            }.Generate();
            var expectedFinalObject = mapper.Map <PatientDto>(fakePatientOne);

            expectedFinalObject.FirstName = "Easily Identified Value For Test";

            var appFactory = _factory;

            using (var scope = appFactory.Services.CreateScope())
            {
                var context = scope.ServiceProvider.GetRequiredService <LabDbContext> ();
                context.Database.EnsureCreated();

                context.Patients.RemoveRange(context.Patients);
                context.Patients.AddRange(fakePatientOne);
                context.SaveChanges();
            }

            var client = appFactory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false
            });

            var serializedPatientToUpdate = JsonConvert.SerializeObject(expectedFinalObject);

            // Act
            // get the value i want to update. assumes I can use sieve for this field. if this is not an option, just use something else
            var getResult = await client.GetAsync($"api/Patients/?filters=FirstName=={fakePatientOne.FirstName}")
                            .ConfigureAwait(false);

            var getResponseContent = await getResult.Content.ReadAsStringAsync()
                                     .ConfigureAwait(false);

            var getResponse = JsonConvert.DeserializeObject <Response <IEnumerable <PatientDto> > >(getResponseContent);
            var id          = getResponse.Data.FirstOrDefault().PatientId;

            // put it
            var patchResult = await client.PutAsJsonAsync($"api/Patients/{id}", expectedFinalObject)
                              .ConfigureAwait(false);

            // get it again to confirm updates
            var checkResult = await client.GetAsync($"api/Patients/{id}")
                              .ConfigureAwait(false);

            var checkResponseContent = await checkResult.Content.ReadAsStringAsync()
                                       .ConfigureAwait(false);

            var checkResponse = JsonConvert.DeserializeObject <Response <PatientDto> >(checkResponseContent);

            // Assert
            patchResult.StatusCode.Should().Be(204);
            checkResponse.Should().BeEquivalentTo(expectedFinalObject, options =>
                                                  options.ExcludingMissingMembers());
        }