public void Initialize() { this.semaphore = new SemaphoreSlim(1, 1); this.client = new Mock <IClient>(); this.environment = new EnvironmentResponse(1, 20000); this.stream = new MemoryStream(); this.writer = new StreamWriter(this.stream); this.reader = new StreamReader(this.stream); this.client .Setup(c => c.Environment) .Returns(this.environment); this.client .Setup(c => c.Semaphore) .Returns(this.semaphore); this.client .Setup(c => c.GetStream()) .Returns(this.stream); this.client .Setup(c => c.GetStreamAsync()) .Returns(Task.FromResult((Stream)this.stream)); // TODO: Separate testing for locking session to another test. this.session = new LockingSession(new Session(this.client.Object), this.client.Object); }
public void LambdaGetFunctionConfiguration() { #region to-retrieve-a-lambda-functions-event-source-mapping-1481661622799 var response = client.GetFunctionConfiguration(new GetFunctionConfigurationRequest { FunctionName = "myFunction", Qualifier = "1" }); string codeSha256 = response.CodeSha256; long codeSize = response.CodeSize; DeadLetterConfig deadLetterConfig = response.DeadLetterConfig; string description = response.Description; EnvironmentResponse environment = response.Environment; string functionArn = response.FunctionArn; string functionName = response.FunctionName; string handler = response.Handler; string kmsKeyArn = response.KMSKeyArn; string lastModified = response.LastModified; int memorySize = response.MemorySize; string role = response.Role; string runtime = response.Runtime; int timeout = response.Timeout; string version = response.Version; VpcConfigDetail vpcConfig = response.VpcConfig; #endregion }
public async Task GetStreamAsync_ShouldConnectIfNotConnected() { // Arrange var sequence = new MockSequence(); var expectedEnvironment = new EnvironmentResponse(42, 32); using var expectedStream = new MemoryStream(); this.tcpClient .InSequence(sequence) .Setup(tc => tc.Connected) .Returns(false); this.connector .InSequence(sequence) .Setup(c => c.ConnectAsync(this.client, this.tcpClient.Object, this.configuration)) .Returns(Task.FromResult(expectedEnvironment)); this.tcpClient .InSequence(sequence) .Setup(tc => tc.GetStream()) .Returns(expectedStream); // Act var result = await this.client.GetStreamAsync(); // Assert Assert.AreSame(expectedStream, result); Assert.AreEqual(expectedEnvironment, this.client.Environment); }
public void LambdaPublishVersion() { #region to-publish-a-version-of-a-lambda-function-1481650704986 var response = client.PublishVersion(new PublishVersionRequest { CodeSha256 = "", Description = "", FunctionName = "myFunction" }); string codeSha256 = response.CodeSha256; long codeSize = response.CodeSize; string description = response.Description; EnvironmentResponse environment = response.Environment; string functionArn = response.FunctionArn; string functionName = response.FunctionName; string handler = response.Handler; string kmsKeyArn = response.KMSKeyArn; string lastModified = response.LastModified; string lastUpdateStatus = response.LastUpdateStatus; int memorySize = response.MemorySize; string revisionId = response.RevisionId; string role = response.Role; string runtime = response.Runtime; string state = response.State; int timeout = response.Timeout; TracingConfigResponse tracingConfig = response.TracingConfig; string version = response.Version; #endregion }
public void LambdaGetFunctionConfiguration() { #region to-get-a-lambda-functions-event-source-mapping-1481661622799 var response = client.GetFunctionConfiguration(new GetFunctionConfigurationRequest { FunctionName = "my-function", Qualifier = "1" }); string codeSha256 = response.CodeSha256; long codeSize = response.CodeSize; string description = response.Description; EnvironmentResponse environment = response.Environment; string functionArn = response.FunctionArn; string functionName = response.FunctionName; string handler = response.Handler; string kmsKeyArn = response.KMSKeyArn; string lastModified = response.LastModified; string lastUpdateStatus = response.LastUpdateStatus; int memorySize = response.MemorySize; string revisionId = response.RevisionId; string role = response.Role; string runtime = response.Runtime; string state = response.State; int timeout = response.Timeout; TracingConfigResponse tracingConfig = response.TracingConfig; string version = response.Version; #endregion }
public void GetStreamReader_ShouldConnectIfNotConnected() { // Arrange var sequence = new MockSequence(); var expectedEnvironment = new EnvironmentResponse(42, 32); using var expected = new StreamReader(new MemoryStream()); this.tcpClient .InSequence(sequence) .Setup(tc => tc.Connected) .Returns(false); this.connector .InSequence(sequence) .Setup(c => c.Connect(this.client, this.tcpClient.Object, this.configuration)) .Returns(expectedEnvironment); this.tcpClient .InSequence(sequence) .Setup(tc => tc.StreamReader) .Returns(expected); // Act var result = this.client.GetStreamReader(); // Assert Assert.AreSame(expected, result); Assert.AreEqual(expectedEnvironment, this.client.Environment); }
public void Connect() { this.SessionFactory = this.sessionFactoryProvider.Create(hostname, port); using (var session = this.SessionFactory.Create(this.Environment)) { this.Environment = this.RequestWriter.WriteStart(session, this.Mode, this.secret); } }
public void ShouldGetEnvironmentAsync() { // Arrange ISystemApi systemApi = CreateSystemApi(); // Act EnvironmentResponse environment = systemApi.GetEnvironmentAsync().Result; // Assert environment.server.server_os.ShouldBe("linux"); }
public void ShouldGetEnvironmentAsync() { // Arrange ISystemApi systemApi = CreateSystemApi(); // Act EnvironmentResponse environment = systemApi.GetEnvironmentAsync().Result; // Assert environment.Platform.VersionCurrent.ShouldBe("2.0"); }
public void LambdaCreateFunction() { #region to-create-a-function-1586492061186 var response = client.CreateFunction(new CreateFunctionRequest { Code = new FunctionCode { S3Bucket = "my-bucket-1xpuxmplzrlbh", S3Key = "function.zip" }, Description = "Process image objects from Amazon S3.", Environment = new Environment { Variables = new Dictionary <string, string> { { "BUCKET", "my-bucket-1xpuxmplzrlbh" }, { "PREFIX", "inbound" } } }, FunctionName = "my-function", Handler = "index.handler", KMSKeyArn = "arn:aws:kms:us-west-2:123456789012:key/b0844d6c-xmpl-4463-97a4-d49f50839966", MemorySize = 256, Publish = true, Role = "arn:aws:iam::123456789012:role/lambda-role", Runtime = "nodejs12.x", Tags = new Dictionary <string, string> { { "DEPARTMENT", "Assets" } }, Timeout = 15, TracingConfig = new TracingConfig { Mode = "Active" } }); string codeSha256 = response.CodeSha256; long codeSize = response.CodeSize; string description = response.Description; EnvironmentResponse environment = response.Environment; string functionArn = response.FunctionArn; string functionName = response.FunctionName; string handler = response.Handler; string kmsKeyArn = response.KMSKeyArn; string lastModified = response.LastModified; string lastUpdateStatus = response.LastUpdateStatus; int memorySize = response.MemorySize; string revisionId = response.RevisionId; string role = response.Role; string runtime = response.Runtime; string state = response.State; int timeout = response.Timeout; TracingConfigResponse tracingConfig = response.TracingConfig; string version = response.Version; #endregion }
public void ShouldBeAbleToCreateSonicSession() { // Arrange var environment = new EnvironmentResponse(1, 42); // Act / Assert using (var result = this.factory.Create(environment)) { Assert.AreSame(this.client.Object, ((SonicSession)result).Client); Assert.AreEqual(environment, ((SonicSession)result).Environment); } }
public void Initialize() { this.client = new Mock <ITcpClient>(); this.environment = new EnvironmentResponse(1, 20000); this.stream = new MemoryStream(); this.writer = new StreamWriter(this.stream); this.reader = new StreamReader(this.stream); this.client .Setup(c => c.GetStream()) .Returns(() => this.stream); this.session = new SonicSession(this.client.Object, new SemaphoreSlim(1, 1), environment); }
public void ShouldCreateNonLockingSession() { // Arrange var factory = new NonLockingSessionFactory(); var tcpClient = Mock.Of <IClient>(stc => stc.Semaphore == new SemaphoreSlim(1, 1)); var environment = new EnvironmentResponse(1, 42); // Act var result = factory.Create(tcpClient); // Assert Assert.IsInstanceOfType(result, typeof(Session)); }
public void ShouldCreateSonicSessionFactoryAndSessionsForProvidedEndpoint() { var environment = new EnvironmentResponse(1, 20000); using (var sessionFactory = this.provider.Create("localhost", Port)) { Assert.IsNotNull(sessionFactory); Assert.IsInstanceOfType(sessionFactory, typeof(SonicSessionFactory)); using (var session = sessionFactory.Create(environment)) { Assert.IsNotNull(session); Assert.IsInstanceOfType(session, typeof(SonicSession)); } } }
static void Main(string[] args) { var environment = new EnvironmentResponse(1, 20000); using (var sessionFactory = new SonicSessionFactory(new TcpClientAdapter("localhost", 1491))) using (var session = sessionFactory.Create(environment)) { Console.WriteLine(".NET Sonic Terminal"); Console.WriteLine("Write .read to read next line from the server."); while (true) { var response = session.Read(); Console.WriteLine($"R > {response}"); if (response.StartsWith("ENDED")) { break; } while (true) { Console.Write($"W > "); var input = Console.ReadLine(); if (input.ToLower().Trim() == ".read") { break; } else if (!string.IsNullOrWhiteSpace(input)) { session.Write(input); break; } } } } }