public void GitHubHostProvider_IsSupported(string protocol, string host, bool expected) { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = protocol, ["host"] = host, }); var provider = new GitHubHostProvider(new TestCommandContext()); Assert.Equal(expected, provider.IsSupported(input)); }
public void GitHubHostProvider_GetCredentialServiceUrl(string protocol, string host, string expectedService) { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = protocol, ["host"] = host, }); var provider = new GitHubHostProvider(new TestCommandContext()); Assert.Equal(expectedService, provider.GetServiceName(input)); }
public void AzureReposProvider_IsSupported_AzureHost_MissingPath_ReturnsTrue() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "dev.azure.com", }); var provider = new AzureReposHostProvider(new TestCommandContext()); Assert.True(provider.IsSupported(input)); }
public void AzureReposProvider_IsSupported_VisualStudioHost_ReturnsTrue() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "org.visualstudio.com", }); var provider = new AzureReposHostProvider(new TestCommandContext()); Assert.True(provider.IsSupported(input)); }
public void InputArguments_CommonArguments_ValueMissing_ReturnsNull() { var dict = new Dictionary <string, string>(); var inputArgs = new InputArguments(dict); Assert.Null(inputArgs.Protocol); Assert.Null(inputArgs.Host); Assert.Null(inputArgs.Path); Assert.Null(inputArgs.UserName); Assert.Null(inputArgs.Password); }
public void GitHubHostProvider_IsSupported_NonHttpHttps_ReturnsTrue() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "ssh", ["host"] = "github.com", }); var provider = new GitHubHostProvider(new TestCommandContext()); Assert.False(provider.IsSupported(input)); }
public void InputArguments_OtherArguments() { var dict = new Dictionary <string, string> { ["foo"] = "bar" }; var inputArgs = new InputArguments(dict); Assert.Equal("bar", inputArgs["foo"]); Assert.Equal("bar", inputArgs.GetArgumentOrDefault("foo")); }
public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoCachedAuthority_NoUser_ReturnsCredential() { var orgName = "org"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "dev.azure.com", ["path"] = "org/proj/_git/repo" }); var expectedOrgUri = new Uri("https://dev.azure.com/org"); var remoteUri = new Uri("https://dev.azure.com/org/proj/_git/repo"); var authorityUrl = "https://login.microsoftonline.com/common"; var expectedClientId = AzureDevOpsConstants.AadClientId; var expectedRedirectUri = AzureDevOpsConstants.AadRedirectUri; var expectedScopes = AzureDevOpsConstants.AzureDevOpsDefaultScopes; var accessToken = "ACCESS-TOKEN"; var account = "john.doe"; var authResult = CreateAuthResult(account, accessToken); var context = new TestCommandContext(); // Use OAuth Access Tokens context.Environment.Variables[AzureDevOpsConstants.EnvironmentVariables.CredentialType] = AzureDevOpsConstants.OAuthCredentialType; var azDevOpsMock = new Mock <IAzureDevOpsRestApi>(MockBehavior.Strict); azDevOpsMock.Setup(x => x.GetAuthorityAsync(expectedOrgUri)).ReturnsAsync(authorityUrl); var msAuthMock = new Mock <IMicrosoftAuthentication>(MockBehavior.Strict); msAuthMock.Setup(x => x.GetTokenAsync(authorityUrl, expectedClientId, expectedRedirectUri, expectedScopes, null)) .ReturnsAsync(authResult); var authorityCacheMock = new Mock <IAzureDevOpsAuthorityCache>(MockBehavior.Strict); authorityCacheMock.Setup(x => x.GetAuthority(It.IsAny <string>())).Returns((string)null); authorityCacheMock.Setup(x => x.UpdateAuthority(orgName, authorityUrl)); var userMgrMock = new Mock <IAzureReposBindingManager>(MockBehavior.Strict); userMgrMock.Setup(x => x.GetBinding(orgName)).Returns((AzureReposBinding)null); var provider = new AzureReposHostProvider(context, azDevOpsMock.Object, msAuthMock.Object, authorityCacheMock.Object, userMgrMock.Object); ICredential credential = await provider.GetCredentialAsync(input); Assert.NotNull(credential); Assert.Equal(account, credential.Account); Assert.Equal(accessToken, credential.Password); }
private static void ShowArgumentsText(InputArguments inputArguments) { Console.WriteLine(" Running application with the following arguments:"); Console.WriteLine(); Console.WriteLine(" 1 - Spotify URL: \"{0}\"", inputArguments.SpotifyUrl.Value); Console.WriteLine(" 2 - Minutes to fade in system volume: {0}", inputArguments.MinutesToFadeInVolume.Value); Console.WriteLine( " 3 - Milliseconds to sleep between each increase of volume by 2 (Automaticly converted): {0}", inputArguments.MilliSecondsToSleep.Value.TotalMilliseconds); Console.WriteLine(); }
private static Uri GetTargetUri(InputArguments input) { Uri uri = new UriBuilder { Scheme = input.Protocol, Host = input.Host, Path = input.Path, UserName = input.UserName }.Uri; return(uri); }
/// <summary> /// Create a URI for the Azure DevOps organization from the give Git input query arguments. /// </summary> /// <param name="input">Git query arguments.</param> /// <returns>Azure DevOps organization URI</returns> /// <exception cref="InvalidOperationException"> /// Thrown if <see cref="InputArguments.Protocol"/> is null or white space. /// <para/> /// Thrown if <see cref="InputArguments.Host"/> is null or white space. /// <para/> /// Thrown if <see cref="InputArguments.Host"/> is not an Azure DevOps hostname. /// <para/> /// Thrown if both of <see cref="InputArguments.UserName"/> or <see cref="InputArguments.Path"/> /// are null or white space when <see cref="InputArguments.Host"/> is an Azure-style URL /// ('dev.azure.com' rather than '*.visualstudio.com'). /// </exception> public static Uri CreateOrganizationUri(InputArguments input) { EnsureArgument.NotNull(input, nameof(input)); if (string.IsNullOrWhiteSpace(input.Protocol)) { throw new InvalidOperationException("Input arguments must include protocol"); } if (string.IsNullOrWhiteSpace(input.Host)) { throw new InvalidOperationException("Input arguments must include host"); } if (!IsAzureDevOpsHost(input.Host)) { throw new InvalidOperationException("Host is not Azure DevOps"); } var ub = new UriBuilder { Scheme = input.Protocol, Host = input.Host, }; // Extract the organization name for Azure ('dev.azure.com') style URLs. // The older *.visualstudio.com URLs contained the organization name in the host already. if (StringComparer.OrdinalIgnoreCase.Equals(input.Host, AzureDevOpsConstants.AzureDevOpsHost)) { // dev.azure.com/{org} string[] pathParts = input.Path?.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (pathParts?.Length > 0) { ub.Path = pathParts[0]; } // {org}@dev.azure.com else if (!string.IsNullOrWhiteSpace(input.UserName)) { ub.Path = input.UserName; } else { throw new InvalidOperationException( "Cannot determine the organization name for this 'dev.azure.com' remote URL. " + "Ensure the `credential.useHttpPath` configuration value is set, or set the organization " + "name as the user in the remote URL '{org}@dev.azure.com'." ); } } return(ub.Uri); }
private static string GetRefreshTokenServiceName(InputArguments input) { Uri baseUri = input.GetRemoteUri(includeUser: false); // The refresh token key never includes the path component. // Instead we use the path component to specify this is the "refresh_token". Uri uri = new UriBuilder(baseUri) { Path = "/refresh_token" }.Uri; return(uri.AbsoluteUri.TrimEnd('/')); }
public void UriHelpers_CreateOrganizationUri_VisualStudioHost_ReturnsCorrectUri() { var expected = new Uri("https://myorg.visualstudio.com/"); var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "myorg.visualstudio.com", }); Uri actual = UriHelpers.CreateOrganizationUri(input); Assert.Equal(expected, actual); }
public void InputArguments_TryGetHostAndPort_NoHostNoPort_ReturnsFalse() { var dict = new Dictionary <string, string> { ["protocol"] = "https", }; var inputArgs = new InputArguments(dict); bool result = inputArgs.TryGetHostAndPort(out _, out _); Assert.False(result); }
/// <summary> /// Attempts to read connection properties from input arguments and sets Config properties accordingly. /// <para>Input arguments must contain the following keys: -database DATABASE_FILE_PATH</para> /// </summary> /// <param name="args">Args to set connection properties from.</param> /// <returns>True if all properties are available and set, otherwise false.</returns> internal static bool TrySetConnectionParameters(InputArguments args) { if (args.Contains("database")) { Config.Instance.Database = args["database"]; } else { return(false); } return(true); }
public void GenericHostProvider_IsSupported(string protocol, bool expected) { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = protocol, ["host"] = "example.com", ["path"] = "foo/bar", }); var provider = new GenericHostProvider(new TestCommandContext()); Assert.Equal(expected, provider.IsSupported(input)); }
public Task StoreCredentialAsync(InputArguments input) { // It doesn't matter if this is an OAuth access token, or the literal username & password // because we store them the same way, against the same credential key in the store. // The OAuth refresh token is already stored on the 'get' request. string service = GetServiceName(input); _context.Trace.WriteLine("Storing credential..."); _context.CredentialStore.AddOrUpdate(service, input.UserName, input.Password); _context.Trace.WriteLine("Credential was successfully stored."); return(Task.CompletedTask); }
public void AzureReposProvider_IsSupported_NonAzureRepos_ReturnsFalse() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "example.com", ["path"] = "org/proj/_git/repo", }); var provider = new AzureReposHostProvider(new TestCommandContext()); Assert.False(provider.IsSupported(input)); }
private void VerifyInteractiveOAuthFlowNeverRan(InputArguments input, System.Threading.Tasks.Task <ICredential> credential) { var remoteUri = input.GetRemoteUri(); // never prompt user through OAuth flow bitbucketAuthentication.Verify(m => m.ShowOAuthRequiredPromptAsync(), Times.Never); // Never try to refresh Access Token bitbucketAuthentication.Verify(m => m.RefreshOAuthCredentialsAsync(It.IsAny <string>()), Times.Never); // never check access token works bitbucketApi.Verify(m => m.GetUserInformationAsync(null, MOCK_ACCESS_TOKEN, true), Times.Never); }
private void VerifyInteractiveBasicAuthFlowRan(string password, InputArguments input, Task <ICredential> credential) { var remoteUri = input.GetRemoteUri(); // verify users was prompted for username/password credentials bitbucketAuthentication.Verify(m => m.GetCredentialsAsync(remoteUri, input.UserName, It.IsAny <AuthenticationModes>()), Times.Once); // check username/password for Bitbucket.org if (BITBUCKET_DOT_ORG_HOST == remoteUri.Host) { bitbucketApi.Verify(m => m.GetUserInformationAsync(input.UserName, password, false), Times.Once); } }
public async Task GitHubHostProvider_GenerateCredentialAsync_Basic_1FAOnly_ReturnsCredential() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "github.com", }); var expectedTargetUri = new Uri("https://github.com/"); var expectedUserName = "******"; var expectedPassword = "******"; // [SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Fake credential")] IEnumerable <string> expectedPatScopes = new[] { GitHubConstants.TokenScopes.Gist, GitHubConstants.TokenScopes.Repo, }; var patValue = "PERSONAL-ACCESS-TOKEN"; var response = new AuthenticationResult(GitHubAuthenticationResultType.Success, patValue); var context = new TestCommandContext(); var ghAuthMock = new Mock <IGitHubAuthentication>(MockBehavior.Strict); ghAuthMock.Setup(x => x.GetAuthenticationAsync(expectedTargetUri, null, It.IsAny <AuthenticationModes>())) .ReturnsAsync(new AuthenticationPromptResult( AuthenticationModes.Basic, new GitCredential(expectedUserName, expectedPassword))); var ghApiMock = new Mock <IGitHubRestApi>(MockBehavior.Strict); ghApiMock.Setup(x => x.CreatePersonalAccessTokenAsync(expectedTargetUri, expectedUserName, expectedPassword, null, It.IsAny <IEnumerable <string> >())) .ReturnsAsync(response); ghApiMock.Setup(x => x.GetUserInfoAsync(expectedTargetUri, patValue)) .ReturnsAsync(new GitHubUserInfo { Login = expectedUserName }); var provider = new GitHubHostProvider(context, ghApiMock.Object, ghAuthMock.Object); ICredential credential = await provider.GenerateCredentialAsync(input); Assert.NotNull(credential); Assert.Equal(expectedUserName, credential.Account); Assert.Equal(patValue, credential.Password); ghApiMock.Verify( x => x.CreatePersonalAccessTokenAsync( expectedTargetUri, expectedUserName, expectedPassword, null, expectedPatScopes), Times.Once); }
public async Task GitHubHostProvider_GenerateCredentialAsync_OAuth_ReturnsCredential() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "github.com", }); var expectedTargetUri = new Uri("https://github.com/"); IEnumerable <string> expectedOAuthScopes = new[] { GitHubConstants.OAuthScopes.Repo, GitHubConstants.OAuthScopes.Gist, GitHubConstants.OAuthScopes.Workflow, }; var expectedUserName = "******"; var tokenValue = "OAUTH-TOKEN"; var response = new OAuth2TokenResult(tokenValue, "bearer"); var context = new TestCommandContext(); var ghAuthMock = new Mock <IGitHubAuthentication>(MockBehavior.Strict); ghAuthMock.Setup(x => x.GetAuthenticationAsync(expectedTargetUri, null, It.IsAny <AuthenticationModes>())) .ReturnsAsync(new AuthenticationPromptResult(AuthenticationModes.OAuth)); ghAuthMock.Setup(x => x.GetOAuthTokenAsync(expectedTargetUri, It.IsAny <IEnumerable <string> >())) .ReturnsAsync(response); var ghApiMock = new Mock <IGitHubRestApi>(MockBehavior.Strict); ghApiMock.Setup(x => x.GetUserInfoAsync(expectedTargetUri, tokenValue)) .ReturnsAsync(new GitHubUserInfo { Login = expectedUserName }); var provider = new GitHubHostProvider(context, ghApiMock.Object, ghAuthMock.Object); ICredential credential = await provider.GenerateCredentialAsync(input); Assert.NotNull(credential); Assert.Equal(expectedUserName, credential.Account); Assert.Equal(tokenValue, credential.Password); ghAuthMock.Verify( x => x.GetOAuthTokenAsync( expectedTargetUri, expectedOAuthScopes), Times.Once); }
private static bool IsRunningAsDesiredUser() { if (InputArguments.RunAsSystem && !WindowsIdentity.GetCurrent().IsSystem) { return(false); } if ((int)InputArguments.GetIntegrityLevel() != ProcessHelper.GetCurrentIntegrityLevel()) { return(false); } return(true); }
private string GetBitbucketServerCredentialKey(InputArguments input) { // The credential (user/pass or an OAuth access token) key is the full target URI. // If the full path is included (credential.useHttpPath = true) then respect that. string url = GetBitbucketServerTargetUri(input).AbsoluteUri; // Trim trailing slash if (url.EndsWith("/")) { url = url.Substring(0, url.Length - 1); } return($"git:{url}"); }
public void GitHubHostProvider_IsSupported_GistHost_UnencryptedHttp_ReturnsTrue() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "http", ["host"] = "gist.github.com", }); var provider = new GitHubHostProvider(new TestCommandContext()); // We report that we support unencrypted HTTP here so that we can fail and // show a helpful error message in the call to `GenerateCredentialAsync` instead. Assert.True(provider.IsSupported(input)); }
public void AzureReposProvider_IsSupported_VisualStudioHost_UnencryptedHttp_ReturnsTrue() { var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "http", ["host"] = "org.visualstudio.com", }); var provider = new AzureReposHostProvider(new TestCommandContext()); // We report that we support unencrypted HTTP here so that we can fail and // show a helpful error message in the call to `CreateCredentialAsync` instead. Assert.True(provider.IsSupported(input)); }
public void UriHelpers_CreateOrganizationUri_AzureHost_InputArgsMissingPath_HasUser_UsesUserOrg() { var expected = new Uri("https://dev.azure.com/myorg-user"); var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "dev.azure.com", ["username"] = "******" }); Uri actual = UriHelpers.CreateOrganizationUri(input); Assert.Equal(expected, actual); }
public void UriHelpers_CreateOrganizationUri_AzureHost_WithPort_ReturnsCorrectUri() { var expected = new Uri("https://dev.azure.com:456/myorg"); var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "dev.azure.com:456", ["path"] = "myorg/myproject/_git/myrepo" }); Uri actual = UriHelpers.CreateOrganizationUri(input); Assert.Equal(expected, actual); }
public override async Task <ICredential> GenerateCredentialAsync(InputArguments input) { ThrowIfDisposed(); // We should not allow unencrypted communication and should inform the user if (StringComparer.OrdinalIgnoreCase.Equals(input.Protocol, "http")) { throw new Exception("Unencrypted HTTP is not supported for Azure Repos. Ensure the repository remote URL is using HTTPS."); } Uri orgUri = UriHelpers.CreateOrganizationUri(input); Uri remoteUri = input.GetRemoteUri(); // Determine the MS authentication authority for this organization Context.Trace.WriteLine("Determining Microsoft Authentication Authority..."); string authAuthority = await _azDevOps.GetAuthorityAsync(orgUri); Context.Trace.WriteLine($"Authority is '{authAuthority}'."); // Get an AAD access token for the Azure DevOps SPS Context.Trace.WriteLine("Getting Azure AD access token..."); JsonWebToken accessToken = await _msAuth.GetAccessTokenAsync( authAuthority, AzureDevOpsConstants.AadClientId, AzureDevOpsConstants.AadRedirectUri, AzureDevOpsConstants.AadResourceId, remoteUri, null); string atUser = accessToken.GetAzureUserName(); Context.Trace.WriteLineSecrets($"Acquired Azure access token. User='******' Token='{{0}}'", new object[] { accessToken.EncodedToken }); // Ask the Azure DevOps instance to create a new PAT var patScopes = new[] { AzureDevOpsConstants.PersonalAccessTokenScopes.ReposWrite, AzureDevOpsConstants.PersonalAccessTokenScopes.ArtifactsRead }; Context.Trace.WriteLine($"Creating Azure DevOps PAT with scopes '{string.Join(", ", patScopes)}'..."); string pat = await _azDevOps.CreatePersonalAccessTokenAsync( orgUri, accessToken, patScopes); Context.Trace.WriteLineSecrets("PAT created. PAT='{0}'", new object[] { pat }); return(new GitCredential(Constants.PersonalAccessTokenUserName, pat)); }
public void GitHubHostProvider_GetCredentialKey_GistHost_ReturnsCorrectKey() { const string expectedKey = "git:https://github.com"; var input = new InputArguments(new Dictionary <string, string> { ["protocol"] = "https", ["host"] = "gist.github.com", }); var provider = new GitHubHostProvider(new TestCommandContext()); string actualKey = provider.GetCredentialKey(input); Assert.Equal(expectedKey, actualKey); }
public QueueInfo(string name, bool autoDelete, bool durable, InputArguments arguments) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (arguments == null) { throw new ArgumentNullException("arguments"); } this.name = name; AutoDelete = autoDelete; this.Durable = durable; this.Arguments = arguments; }
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); }
//[STAThread] private static int Main(string[] args) { Console.WriteLine("digiCamControl command line utility"); Console.WriteLine(); _arguments = new InputArguments(args, "/"); if (!args.Any() || _arguments.Contains("help")) { ShowHelp(); Console.ReadLine(); return 0; } InitApplication(); Thread.Sleep(1000); while (CamerasAreBusy()) { Thread.Sleep(1); } if (args != null && args.Count() == 1 && File.Exists(args[0])) { RunScript(args[0]); return 0; } if (ServiceProvider.DeviceManager.ConnectedDevices.Count == 0) { Console.WriteLine("No connected device was found ! Exiting"); return 0; } int exitCodes = ExecuteArgs(); Thread.Sleep(250); Thread thread = new Thread(WaitForCameras); thread.Start(); Dispatcher.Run(); return exitCodes; }
public async void HandleTypeAsync_ForStudy([Values(true, false)] bool useCache) { // Arrange var mockProvider = new MockProvider(); var seriesInfoProvider = mockProvider.GetSeriesInfoProviderFake(); var seriesQuery = Substitute.For<IDicomQuery<SeriesInfo>>(); seriesInfoProvider.GetSeriesForStudy(Arg.Any<StudyInfo>()).Returns(seriesQuery); var studyInfoProvider = mockProvider.GetStudyInfoProviderFake(); var seriesTypeHandler = new SeriesTypeHandler(seriesInfoProvider, studyInfoProvider); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "series", ParentIdentifier = "123", UseCache = useCache }; // Act await seriesTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()); // Assert if (useCache) { Assert.That(() => seriesQuery.Received(1).LoadFromCache(), Throws.Nothing); } Assert.That(() => studyInfoProvider.Received(1).GetStudyByIDAsync("123", useCache), Throws.Nothing); Assert.That(() => seriesInfoProvider.Received(1).GetSeriesForStudy(Arg.Any<StudyInfo>()), Throws.Nothing); }
private InputArguments GetDefaultInputArguments() { var mockProvider = new MockProvider(); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), new BirthNumberParser()) { CalledApplicationEntity = "calledAE", CallingApplicationEntity = "callingAE", RemoteAddress = "remoteAddr", RemotePort = 666, DestinationApplicationEntity = "destinationAE", LocalAddress = "localAddr", LocalPort = 666 }; return inputArguments; }
public BindingInfo(string routingKey, InputArguments arguments) { routing_key = routingKey; this.arguments = arguments; }
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 Object[] PopulateAttributes(MethodInfo methodInfo, InputArguments inputArgs, List<string> outputKeys) { ParameterInfo[] infos = methodInfo.GetParameters(); Object[] attributes = null; if (infos.Length == 0) { return new Object[] { }; } if (infos.Length == 2) { attributes = new Object[2] { inputArgs.attribute, outputKeys }; } else { attributes = new Object[1] { inputArgs.attribute }; } return attributes; }
public InputArguments MapInputArguments(Model.Arguments arguments) { var mapping = new InputArguments(); foreach (var argument in arguments) mapping.Add(argument.Key, argument.Value); return mapping; }
public async void HandleTypeAsync_AllStudies([Values(true, false)] bool useCache) { // Arrange var mockProvider = new MockProvider(); var studyInfoProvider = mockProvider.GetStudyInfoProviderFake(); var query = Substitute.For<IDicomQuery<StudyInfo>>(); studyInfoProvider.GetStudies().Returns(query); var studyTypeHandler = new StudyTypeHandler(studyInfoProvider, mockProvider.GetPatientInfoProviderFake()); var inputArguments = new InputArguments(mockProvider.GetSettingsProviderFake(), mockProvider.GetBirthNumberParserFake()) { Type = "study", UseCache = useCache }; // Act await studyTypeHandler.HandleTypeAsync(inputArguments, GetMemoryTextWriter()); // Assert if (useCache) { Assert.That(() => query.Received(1).LoadFromCache(), Throws.Nothing); } Assert.That(() => studyInfoProvider.Received(1).GetStudies(), Throws.Nothing); }
public InputArguments ReadArgumentsFromNode(XmlNode inputNode, string inputType) { InputArguments inputs = new InputArguments(); inputs.visibleArgDic = ReadDicFromNode(inputNode, inputType, false); if (inputType == InputType.DIC) { inputs.attribute = ReadDicFromNode(inputNode, inputType); } else { inputs.attribute = ReadXmlFromNode(inputNode); } return inputs; }
public BindingInfo(string routingKey, InputArguments arguments) { RoutingKey = routingKey; Arguments = arguments; }