public async void HandleTypeAsync_AllSeries([Values(true, false)] bool useCache) { // Arrange var mockProvider = new MockProvider(); var seriesInfoProvider = mockProvider.GetSeriesInfoProviderFake(); var seriesQuery = Substitute.For<IDicomQuery<SeriesInfo>>(); seriesInfoProvider.GetSeries().Returns(seriesQuery); var seriesTypeHandler = new SeriesTypeHandler(seriesInfoProvider, mockProvider.GetStudyInfoProviderFake()); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "series", UseCache = useCache }; // Act await seriesTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()); // Assert if (useCache) { Assert.That(() => seriesQuery.Received(1).LoadFromCache(), Throws.Nothing); } Assert.That(() => seriesInfoProvider.Received(1).GetSeries(), Throws.Nothing); }
public void GetPatientByBirthNumberAsync_NullBirthNumber_ThrowsException() { // Arrange var mockProvider = new MockProvider(); var patientInfoProvider = new PatientInfoProvider(mockProvider.GetDicomQueryProviderForPatientsFake(), mockProvider.GetStudyInfoProviderFake(), mockProvider.GetBirthNumberParserFake()); // Act var exception = patientInfoProvider.GetPatientByBirthNumberAsync(null).Exception; // Act + Assert Assert.That(exception.InnerExceptions.First(), Is.TypeOf<ArgumentNullException>()); }
public void GetPatients_ProperQueryIsCreated() { // Arrange var mockProvider = new MockProvider(); var queryProvider = Substitute.For<IDicomQueryProvider<PatientInfo>>(); var patientInfoProvider = new PatientInfoProvider(queryProvider,mockProvider.GetStudyInfoProviderFake(), mockProvider.GetBirthNumberParserFake()); // Act patientInfoProvider.GetPatients(); // Assert Assert.That(() => queryProvider.Received(1).GetDicomQuery(), Throws.Nothing); }
public void HandleTypeAsync_InvalidType_ThrowsException() { // Arrange var mockProvider = new MockProvider(); var studyTypeHandler = new StudyTypeHandler(mockProvider.GetStudyInfoProviderFake(), mockProvider.GetPatientInfoProviderFake()); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "UnknownType" }; // Act var exception = studyTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()).Exception; // Assert Assert.That(exception.InnerExceptions.First(), Is.TypeOf<ArgumentException>()); }
public async void HandleTypeAsync_SingleStudy([Values(true, false)] bool useCache) { // Arrange var mockProvider = new MockProvider(); var studyInfoProvider = mockProvider.GetStudyInfoProviderFake(); var studyTypeHandler = new StudyTypeHandler(studyInfoProvider, mockProvider.GetPatientInfoProviderFake()); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "study", Identifier = "123", UseCache = useCache }; // Act await studyTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()); // Assert Assert.That(() => studyInfoProvider.Received(1).GetStudyByIDAsync(new InfoIdentifier("123"), useCache), Throws.Nothing); }
public async void HandleTypeAsync_SingleStudy_Download() { // Arrange var mockProvider = new MockProvider(); var studyInfoProvider = mockProvider.GetStudyInfoProviderFake(); var studyTypeHandler = new StudyTypeHandler(studyInfoProvider, mockProvider.GetPatientInfoProviderFake()); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "study", Identifier = "123", Download = true }; // Act await studyTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()); // Assert Assert.That(() => studyInfoProvider.Received(1).GetStudyByIDAsync(new InfoIdentifier("123")), Throws.Nothing); Assert.That(() => studyInfoProvider.Received(1).DownloadImagesAsync(Arg.Any<StudyInfo>()), Throws.Nothing); }
public async void GetPatientByBirthNumber_FromServer_ProperQueryIsCreated([Values("910725/6444", "9107256444")] string birthNumber) { // Arrange var mockProvider = new MockProvider(); var queryProvider = Substitute.For<IDicomQueryProvider<PatientInfo>>(); var dataLoader = Substitute.For<IDicomDataLoader<PatientInfo>>(); var whereCollection = Substitute.For<IWhereCollection<PatientInfo>>(); var query = Substitute.For<DicomQuery<PatientInfo>>(mockProvider.GetGeneralizedInfoProviderFake(), dataLoader, whereCollection); queryProvider.GetDicomQuery().Returns(query); var patientInfoProvider = new PatientInfoProvider(queryProvider, mockProvider.GetStudyInfoProviderFake(), mockProvider.GetBirthNumberParserFake()); // Act await patientInfoProvider.GetPatientByBirthNumberAsync(birthNumber); // Assert Assert.That(() => whereCollection.Received(1).WhereEquals(DicomTags.PatientID, "910725/6444"), Throws.Nothing); Assert.That(() => whereCollection.Received(1).WhereEquals(DicomTags.PatientID, "9107256444"), Throws.Nothing); }
public async void DownloadImages_ProperMethodsAreCalled() { // Arrange var mockProvider = new MockProvider(); var studyInfoProvider = Substitute.For<IStudyInfoProvider>(); var dataLoader = Substitute.For<IDicomDataLoader<StudyInfo>>(); var whereCollection = Substitute.For<WhereCollection<StudyInfo>>(mockProvider.GetDicomMappingFake()); var query = Substitute.For<DicomQuery<StudyInfo>>(mockProvider.GetGeneralizedInfoProviderFake(), dataLoader, whereCollection); dataLoader.LoadDataFromServerAsync(Arg.Any<IWhereCollection<StudyInfo>>()).Returns(c => Task<IImmutableList<StudyInfo>>.Factory.StartNew(() => new List<StudyInfo> { new StudyInfo(), new StudyInfo() }.ToImmutableList())); studyInfoProvider.GetStudiesForPatient(Arg.Any<PatientInfo>()).Returns(query); var patientInfoProvider = new PatientInfoProvider(mockProvider.GetDicomQueryProviderForPatientsFake(), studyInfoProvider, mockProvider.GetBirthNumberParserFake()); var patient = new PatientInfo(); // Act await patientInfoProvider.DownloadImagesAsync(patient); // Assert Assert.That(() => studyInfoProvider.Received(1).GetStudiesForPatient(patient), Throws.Nothing); Assert.That(() => studyInfoProvider.Received(2).DownloadImagesAsync(Arg.Any<StudyInfo>(), Arg.Any<Func<InfoIdentifier, InfoIdentifier, Stream>>()), Throws.Nothing); }
public void DownloadImages_NullPatient_ThrowsException() { // Arrange var mockProvider = new MockProvider(); var patientInfoProvider = new PatientInfoProvider(mockProvider.GetDicomQueryProviderForPatientsFake(), mockProvider.GetStudyInfoProviderFake(), mockProvider.GetBirthNumberParserFake()); // Act + Assert Assert.That(() => patientInfoProvider.DownloadImagesAsync(null).Exception.InnerExceptions[0], Is.InstanceOf<ArgumentNullException>()); }
public async void HandleTypeAsync_ForPatient([Values(true, false)] bool useCache) { // Arrange var mockProvider = new MockProvider(); var studyInfoProvider = mockProvider.GetStudyInfoProviderFake(); var studyQuery = Substitute.For<IDicomQuery<StudyInfo>>(); studyInfoProvider.GetStudiesForPatient(Arg.Any<PatientInfo>()).Returns(studyQuery); var patientInfoProvider = mockProvider.GetPatientInfoProviderFake(); var studyTypeHandler = new StudyTypeHandler(studyInfoProvider, patientInfoProvider); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "study", ParentIdentifier = "123", UseCache = useCache }; // Act await studyTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()); // Assert if (useCache) { Assert.That(() => studyQuery.Received(1).LoadFromCache(), Throws.Nothing); } Assert.That(() => patientInfoProvider.Received(1).GetPatientByBirthNumberAsync("123", useCache), Throws.Nothing); Assert.That(() => studyInfoProvider.Received(1).GetStudiesForPatient(Arg.Any<PatientInfo>()), Throws.Nothing); }