public HandshakeResponse(MessageResponseCode responseCode, SemanticVersion protocolVersion) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, responseCode), nameof(responseCode)); } if (responseCode == MessageResponseCode.Success) { if (protocolVersion == null) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(protocolVersion)); } } else if (protocolVersion != null) { throw new ArgumentException( Strings.Plugin_ProtocolVersionNotSupportedOnError, nameof(protocolVersion)); } ResponseCode = responseCode; ProtocolVersion = protocolVersion; }
public async Task GetPackageHashAsync_ReturnsNullForNonSuccess(MessageResponseCode responseCode) { var hashAlgorithm = "a"; var response = new GetPackageHashResponse(responseCode, hash: null); var connection = new Mock <IConnection>(MockBehavior.Strict); connection.Setup(x => x.SendRequestAndReceiveResponseAsync <GetPackageHashRequest, GetPackageHashResponse>( It.Is <MessageMethod>(m => m == MessageMethod.GetPackageHash), It.Is <GetPackageHashRequest>(c => c.PackageId == _packageIdentity.Id && c.PackageVersion == _packageIdentity.Version.ToNormalizedString() && c.PackageSourceRepository == _packageSourceRepository && c.HashAlgorithm == hashAlgorithm), It.IsAny <CancellationToken>())) .ReturnsAsync(response); using (var test = PluginPackageDownloaderTest.Create()) { test.Plugin.SetupGet(x => x.Connection) .Returns(connection.Object); var packageHash = await test.Downloader.GetPackageHashAsync( hashAlgorithm, CancellationToken.None); Assert.Null(packageHash); } }
internal static async Task <PluginFindPackageByIdResourceTest> CreateAsync( MessageResponseCode responseCode = MessageResponseCode.Error) { var packageIdentity = new PackageIdentity(id: "a", version: NuGetVersion.Parse("1.0.0")); var testDirectory = TestDirectory.Create(); var packageSource = new PackageSource("http://unit.test"); var package = await SimpleTestPackageUtility.CreateFullPackageAsync( testDirectory.Path, packageIdentity.Id, packageIdentity.Version.ToNormalizedString()); var packageBytes = File.ReadAllBytes(package.FullName); var plugin = new Mock <IPlugin>(); var dispatcher = new Mock <IMessageDispatcher>(); var connection = new Mock <IConnection>(); dispatcher.SetupGet(x => x.RequestHandlers) .Returns(new RequestHandlers()); connection.SetupGet(x => x.MessageDispatcher) .Returns(dispatcher.Object); var versions = responseCode == MessageResponseCode.Success ? new[] { "1.0.0", "2.0.0", "3.0.0" } : null; var response = new GetPackageVersionsResponse(responseCode, versions); connection.Setup(x => x.SendRequestAndReceiveResponseAsync <GetPackageVersionsRequest, GetPackageVersionsResponse>( It.Is <MessageMethod>(m => m == MessageMethod.GetPackageVersions), It.Is <GetPackageVersionsRequest>( c => string.Equals(c.PackageId, packageIdentity.Id, StringComparison.OrdinalIgnoreCase) && c.PackageSourceRepository == packageSource.Source), It.IsAny <CancellationToken>())) .ReturnsAsync(response); plugin.SetupGet(x => x.Connection) .Returns(connection.Object); var utilities = new Mock <IPluginMulticlientUtilities>(); var credentialService = new Mock <ICredentialService>(); var credentialsProvider = new GetCredentialsRequestHandler( plugin.Object, proxy: null, credentialService: credentialService.Object); var resource = new PluginFindPackageByIdResource( plugin.Object, utilities.Object, packageSource); return(new PluginFindPackageByIdResourceTest( resource, package, packageIdentity, connection, new SourceCacheContext(), testDirectory)); }
public void JsonDeserialization_ReturnsCorrectObject( string json, MessageResponseCode responseCode, string hash) { var response = JsonSerializationUtilities.Deserialize <GetPackageHashResponse>(json); Assert.Equal(responseCode, response.ResponseCode); Assert.Equal(hash, response.Hash); }
public void Constructor_InitializesProperties( MessageResponseCode responseCode, string username, string password) { var response = new GetCredentialsResponse(responseCode, username, password); Assert.Equal(responseCode, response.ResponseCode); Assert.Equal(username, response.Username); Assert.Equal(password, response.Password); }
public void JsonSerialization_ReturnsCorrectJson( MessageResponseCode responseCode, string hash, string expectedJson) { var response = new GetPackageHashResponse(responseCode, hash); var actualJson = TestUtilities.Serialize(response); Assert.Equal(expectedJson, actualJson); }
public void JsonSerialization_ReturnsCorrectJson( MessageResponseCode responseCode, string username, string password, string expectedJson) { var response = new GetCredentialsResponse(responseCode, username, password); var actualJson = TestUtilities.Serialize(response); Assert.Equal(expectedJson, actualJson); }
public void JsonDeserialization_ReturnsCorrectObject( string json, MessageResponseCode responseCode, string username, string password) { var response = JsonSerializationUtilities.Deserialize <GetCredentialsResponse>(json); Assert.Equal(responseCode, response.ResponseCode); Assert.Equal(username, response.Username); Assert.Equal(password, response.Password); }
public void JsonDeserialization_ReturnsCorrectObject( string json, MessageResponseCode responseCode, string versionString) { var version = versionString == null ? null : SemanticVersion.Parse(versionString); var response = JsonSerializationUtilities.Deserialize <HandshakeResponse>(json); Assert.Equal(responseCode, response.ResponseCode); Assert.Equal(version, response.ProtocolVersion); }
public PrefetchPackageResponse(MessageResponseCode responseCode) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, responseCode), nameof(responseCode)); } ResponseCode = responseCode; }
public void AJsonDeserialization_ReturnsCorrectObject( string json, string username, string password, string message, string[] authenticationTypes, MessageResponseCode messageResponseCode) { var response = JsonSerializationUtilities.Deserialize<GetAuthenticationCredentialsResponse>(json); Assert.Equal(response.Username, username); Assert.Equal(response.Password, password); Assert.Equal(response.Message, message); Assert.Equal(response.AuthenticationTypes, authenticationTypes); Assert.Equal(response.ResponseCode, messageResponseCode); }
public GetAuthenticationCredentialsResponse(string username, string password, string message, IList <string> authenticationTypes, MessageResponseCode responseCode) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, nameof(responseCode))); } Username = username; Password = password; Message = message; AuthenticationTypes = authenticationTypes; ResponseCode = responseCode; }
public GetCredentialsResponse( MessageResponseCode responseCode, string username, string password) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, responseCode), nameof(responseCode)); } ResponseCode = responseCode; Username = username; Password = password; }
public GetFilesInPackageResponse(MessageResponseCode responseCode, IEnumerable <string> files) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, responseCode), nameof(responseCode)); } if (responseCode == MessageResponseCode.Success && (files == null || !files.Any())) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(files)); } ResponseCode = responseCode; Files = files; }
public GetPackageHashResponse(MessageResponseCode responseCode, string hash) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, responseCode), nameof(responseCode)); } if (responseCode == MessageResponseCode.Success && string.IsNullOrEmpty(hash)) { throw new ArgumentException(Strings.ArgumentCannotBeNullOrEmpty, nameof(hash)); } ResponseCode = responseCode; Hash = hash; }
public GetServiceIndexResponse(MessageResponseCode responseCode, JObject serviceIndex) { if (!Enum.IsDefined(typeof(MessageResponseCode), responseCode)) { throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, Strings.Plugin_UnrecognizedEnumValue, responseCode), nameof(responseCode)); } if (responseCode == MessageResponseCode.Success && serviceIndex == null) { throw new ArgumentNullException(nameof(serviceIndex)); } ResponseCode = responseCode; ServiceIndex = serviceIndex; }
public void AJsonSerialization_ReturnsCorrectJson( string username, string password, string message, string[] authenticationTypes, MessageResponseCode messageResponseCode ) { var authTypesBuilder = new StringBuilder(); if (authenticationTypes != null) { authTypesBuilder.Append("\",\"AuthenticationTypes\":[\""); authTypesBuilder.Append(string.Join("\",\"", authenticationTypes)); authTypesBuilder.Append("\"]"); } else { authTypesBuilder.Append("\""); } var expectedJson = "{\"Username\":\"" + username + "\",\"Password\":\"" + password + "\",\"Message\":\"" + message + authTypesBuilder.ToString() + ",\"ResponseCode\":\"" + messageResponseCode + "\"}"; var response = new GetAuthenticationCredentialsResponse( username, password, message, authenticationTypes, messageResponseCode); var actualJson = TestUtilities.Serialize(response); Assert.Equal(expectedJson, actualJson); }
private async Task HandleResponseAsync( LogLevel handlerLogLevel, LogLevel requestLogLevel, MessageResponseCode responseCode, bool expectLog) { var test = new LogRequestHandlerTest(handlerLogLevel); var payload = new LogRequest(requestLogLevel, message: "a"); var request = MessageUtilities.Create( requestId: "b", type: MessageType.Request, method: MessageMethod.Log, payload: payload); var responseHandler = new Mock <IResponseHandler>(MockBehavior.Strict); responseHandler.Setup(x => x.SendResponseAsync( It.Is <Message>(message => message == request), It.Is <LogResponse>(response => response.ResponseCode == responseCode), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(0)); if (expectLog) { test.Logger.Setup( x => x.Log(It.Is <ILogMessage>(m => m.Message == payload.Message && m.Level == requestLogLevel))); } await test.Handler.HandleResponseAsync( Mock.Of <IConnection>(), request, responseHandler.Object, CancellationToken.None); test.Logger.Verify(); }
public void JsonDeserialization_ReturnsCorrectObject(string json, MessageResponseCode responseCode) { var response = JsonSerializationUtilities.Deserialize <InitializeResponse>(json); Assert.Equal(responseCode, response.ResponseCode); }
private Task <GetAuthenticationCredentialsResponse> GetResponse(string username, string password, string message, MessageResponseCode responseCode) { return(Task.FromResult(new GetAuthenticationCredentialsResponse( username: username, password: password, message: message, authenticationTypes: new List <string> { "Basic" }, responseCode: responseCode))); }