public void TestDefaultSerializerWithUnsafeEncoder()
        {
            var serializer = new DefaultLambdaJsonSerializer(x => x.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping);

            var response = new DummyResponse
            {
                BingBong = "Joy"
            };

            MemoryStream ms           = new MemoryStream();
            StreamReader streamReader = new StreamReader(ms);

            serializer.Serialize(response, ms);
            ms.Seek(0, SeekOrigin.Begin);
            var utf8Payload = streamReader.ReadToEnd();

            var albResponse = new Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerResponse
            {
                Body = utf8Payload
            };

            serializer.Serialize(albResponse, ms);
            ms.Seek(0, SeekOrigin.Begin);
            var json = streamReader.ReadToEnd();

            Assert.Equal(90, json.Length);
        }
Exemplo n.º 2
0
        public async Task HandleGetList_ReturnsOkEvenWithEmptyListAsync()
        {
            var client = Mock(new List <DummyEntity>()).CreateClient();
            var result = await client.GetFromJsonAsync <Response <List <DummyEntity> > >("/dummies");

            result.Should().BeEquivalentTo(DummyResponse.GetResponse(new List <DummyEntity>()));
        }
Exemplo n.º 3
0
        public void UseCaseTest()
        {
            Mock <ICreateRequestService <DummyRequest> > createRequestService = new Mock <ICreateRequestService <DummyRequest> >();
            Mock <IClientService> clientService = new Mock <IClientService>();
            Mock <ISerializeService <DummyResponse> > serializeService = new Mock <ISerializeService <DummyResponse> >();

            DummyRequest request = new DummyRequest()
            {
                Age      = 30,
                Location = "DummyLocation",
                Name     = "Dummy"
            };
            DummyResponse response = new DummyResponse()
            {
                Id       = 1,
                RealName = "DummyReal"
            };

            createRequestService.Setup(r => r.GetUrl(request)).Returns("www.dummy.com?foo=2");
            clientService.Setup(s => s.GetData("www.dummy.com?foo=2")).Returns(Task.FromResult("<xml>values</xml>"));
            serializeService.Setup(ss => ss.Deserialize("<xml>values</xml>")).Returns(response);

            RestService <DummyRequest, DummyResponse> restService =
                new RestService <DummyRequest, DummyResponse>(createRequestService.Object, clientService.Object, serializeService.Object);

            var resultResponse = restService.Get(request).Result;

            Assert.AreEqual(response, resultResponse);
        }
Exemplo n.º 4
0
        private static List <DummyResponse> RunDummySql(SqlConnection conn)
        {
            List <DummyResponse> response = new List <DummyResponse>();


            SqlCommand command = new SqlCommand("SELECT ObjectID, Description FROM Insights", conn);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                Console.WriteLine("ObjectId \t Description");
                while (reader.Read())
                {
                    Console.WriteLine(String.Format("{0} \t | {1} \t |  ",
                                                    reader[0], reader[1]));
                    if (reader[1].ToString().Length < 1)
                    {
                        DummyResponse dummy = new DummyResponse
                        {
                            ObjectID    = Int32.Parse(reader[0].ToString()),
                            Description = reader[1].ToString()
                        };
                        response.Add(dummy);
                    }
                }
            }
            return(response);
        }
        public void TestDefaultSerializer()
        {
            var serializer = new DefaultLambdaJsonSerializer();

            var response = new DummyResponse
            {
                BingBong = "Joy"
            };

            MemoryStream ms           = new MemoryStream();
            StreamReader streamReader = new StreamReader(ms);

            serializer.Serialize(response, ms);
            ms.Seek(0, SeekOrigin.Begin);
            var utf8Payload = streamReader.ReadToEnd();

            var albResponse = new Amazon.Lambda.ApplicationLoadBalancerEvents.ApplicationLoadBalancerResponse
            {
                Body = utf8Payload
            };

            serializer.Serialize(albResponse, ms);
            ms.Seek(0, SeekOrigin.Begin);
            var json = streamReader.ReadToEnd();

            Assert.Equal(106, json.Length);
        }
Exemplo n.º 6
0
        public ActionResult Index()
        {
            var test = new DummyResponse {
                Response = "index"
            };

            return(Json(test));
        }
Exemplo n.º 7
0
        public async Task HandleGet_ReturnsOkWithDummyEntityAsync()
        {
            var expectedResult = new DummyEntityFaker().Generate();
            var client         = Mock(expectedResult).CreateClient();

            var result = await client.GetFromJsonAsync <Response <DummyEntity> >($"/dummies/{expectedResult.Id}");

            result.Should().BeEquivalentTo(DummyResponse.GetResponse(expectedResult));
        }
Exemplo n.º 8
0
        public async Task HandleGetList_ReturnsOkWithFilledListAsync()
        {
            var expectedResults = new DummyEntityFaker().Generate(3);
            var client          = Mock(expectedResults).CreateClient();

            var result = await client.GetFromJsonAsync <Response <List <DummyEntity> > >("/dummies");

            result.Should().BeEquivalentTo(DummyResponse.GetResponse(expectedResults));
        }
Exemplo n.º 9
0
        public async Task HandlePatch_ShouldReturnOkWithLinks()
        {
            var entity = new DummyEntityFaker().Generate();
            var client = api.CreateClient();

            var result = await client.PatchAsync($"/dummies/{entity.Id}", JsonContent.Create(entity));

            result.StatusCode.Should().Be(StatusCodes.Status200OK);

            var content = await result.Content.ReadFromJsonAsync <Response <DummyEntity> >();

            content.Should().BeEquivalentTo(DummyResponse.GetResponse());
        }
Exemplo n.º 10
0
        public async Task HandleDelete_ShouldReturnDeletedEntity()
        {
            var expectedResult = new DummyEntityFaker().Generate();
            var client         = Mock(expectedResult).CreateClient();

            var result = await client.DeleteAsync($"/dummies/{expectedResult.Id}");

            result.StatusCode.Should().Be(StatusCodes.Status200OK);

            var content = await result.Content.ReadFromJsonAsync <Response <DummyEntity> >();

            content.Should().BeEquivalentTo(DummyResponse.GetResponse(expectedResult));
        }
Exemplo n.º 11
0
        public async Task HandleCreate_ShouldReturnCreatedEntityWithLocation()
        {
            var expectedResult = new DummyEntityFaker().Generate();
            var client         = Mock(expectedResult).CreateClient();

            var result = await client.PostAsJsonAsync("/dummies", expectedResult);

            result.StatusCode.Should().Be(StatusCodes.Status201Created);
            result.Headers.Location.Should().Be($"/dummies/{expectedResult.Id}");

            var content = await result.Content.ReadFromJsonAsync <Response <DummyEntity> >();

            content.Should().BeEquivalentTo(DummyResponse.GetResponse(expectedResult));
        }
        public async void HandleAsync(IRequest request)
        {
            IRequest notSupportedRequest = request;

            if (notSupportedRequest == null)
            {
                return;
            }

            Response?.Invoke(this, DummyResponse.CreateRequestFailedResponse(notSupportedRequest.ID, $"Requests of type \"{notSupportedRequest.Type}\" are not supported"));

            // Fake Async action to satisfy Compiler
            await Task.CompletedTask;
        }
        public void Serialize_json()
        {
            var sut = new JsonResponseReader <DummyResponse>();

            using (var stream = new MemoryStream())
            {
                var expected = new DummyResponse {
                    Name = "dummy"
                };
                JsonResponseReader <DummyResponse> .Serializer.WriteObject(stream, expected);

                stream.Seek(0, SeekOrigin.Begin);
                var actual = sut.From(stream);

                actual.ShouldBeEquivalentTo(expected);
            }
        }
Exemplo n.º 14
0
        public void TestCamelCase()
        {
            var serializer = new CamelCaseLambdaJsonSerializer();

            var response = new DummyResponse
            {
                BingBong = "Joy"
            };

            MemoryStream ms = new MemoryStream();

            serializer.Serialize(response, ms);
            ms.Position = 0;
            var json = new StreamReader(ms).ReadToEnd();

            var serialized = JObject.Parse(json);

            Assert.Equal("Joy", serialized["bingBong"]?.ToString());
        }
Exemplo n.º 15
0
        public async Task ContentIsSet()
        {
            var controller = new DummyController
            {
                Configuration = new HttpConfiguration(),
                Request       = new HttpRequestMessage()
            };

            controller.Request.Headers.Accept.Clear();
            controller.Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var expectedContent = new DummyResponse {
                Name = "Test", Age = 50
            };
            var actionResult = new AcceptedResult <DummyResponse>(controller, expectedContent);
            var response     = await actionResult.ExecuteAsync(new CancellationToken());

            var responsContent = await response.Content.ReadAsAsync <DummyResponse>();

            responsContent.Should().NotBeNull("because the content set should be present in the response");
            responsContent.ShouldBeEquivalentTo(expectedContent, "because the content should be returned in the response body");
        }
Exemplo n.º 16
0
 private DummyObject ToDummyObject(DummyResponse dummyResponse) =>
 new DummyObject(dummyResponse.Key, dummyResponse.Name);