public void Deserialize_UsesJsonProperties_True() { // Arrange var testResponse = new TestResponse() { id_str = "123", created_at = "Sun Dec 16 20:56:33 +0000 2018", full_text = "Wello Horld! http://www.Steve.com", truncated = false, }; var serializer = new LambdaRestSerializer(); var stream = new MemoryStream(); TwitterResponse result = null; // Act serializer.Serialize <TestResponse>(testResponse, stream); stream.Position = 0; result = serializer.Deserialize <TwitterResponse>(stream); // Assert Assert.Equal(result.UID, testResponse.id_str); Assert.Equal(result.CreatedAt, new DateTimeOffset(2018, 12, 16, 20, 56, 33, new TimeSpan(0))); Assert.Equal(result.FullText, testResponse.full_text); Assert.Equal(result.Truncated, testResponse.truncated); }
public SimpleStorageService(string keyId, string secretKey, string bucketName) { Client = new AmazonS3Client(keyId, secretKey, RegionEndpoint.USWest2); Serializer = new LambdaRestSerializer(); BucketName = bucketName; }
public void PutObject_SerializesData_True() { // Arrange var s3Mock = new Mock <IAmazonS3>(); var service = new SimpleStorageService(string.Empty, string.Empty, string.Empty); var stream = new MemoryStream(); var serializer = new LambdaRestSerializer(); string serializedContentFromService = null; string serializedContentFromTest = null; var mockRequests = new List <AlexaRequest>() { new AlexaRequest() { UID = "1", MainText = "Hello there", TitleText = "Test 1", UpdateDate = DateTime.Now, RedirectionUrl = "http://www.google.com" }, new AlexaRequest() { UID = "2", MainText = "Bye", TitleText = "Test 2", UpdateDate = DateTime.Now.AddHours(-1), RedirectionUrl = "http://www.amazon.com" } }; serializer.Serialize <List <AlexaRequest> >(mockRequests, stream); stream.Position = 0; serializedContentFromTest = new StreamReader(stream).ReadToEnd(); // Act s3Mock .Setup(x => x.PutObjectAsync(It.IsAny <PutObjectRequest>(), It.IsAny <CancellationToken>())) .Callback((PutObjectRequest request, CancellationToken token) => { serializedContentFromService = request.ContentBody; }) .Returns(Task.FromResult(new PutObjectResponse() { HttpStatusCode = HttpStatusCode.OK })); service.Client = s3Mock.Object; service.PutObject <List <AlexaRequest> >(mockRequests, It.IsAny <string>()); // Assert Assert.Equal(serializedContentFromTest, serializedContentFromService); }