Esempio n. 1
0
        public void TestSave()
        {
            WeighInUser actualUser = null;

            Mock <IDynamoDBContext> context = new Mock <IDynamoDBContext>();

            context.Setup(C => C.SaveAsync <WeighInUser>(It.IsAny <WeighInUser>(), It.IsAny <CancellationToken>())).Returns((WeighInUser user, object t) =>
            {
                actualUser = user;
                return(Task.CompletedTask);
            });

            TestAwsFactory factory = new TestAwsFactory()
            {
                DynamoDBContext = context.Object
            };

            WeighInUser testUser = new WeighInUser()
            {
                UserId             = "TestUserId",
                FirstName          = "Unit",
                StartingWeight     = 88.8m,
                StartingWeightDate = new DateTime(2018, 7, 16)
            };
            string testUserJson = JsonConvert.SerializeObject(testUser);

            using (PostUser postUser = new PostUser(factory))
            {
                string userOutputJson = postUser.Save(testUserJson);

                Assert.That(actualUser, Is.Not.Null, "actualUser");
                Assert.That(actualUser.UserId, Is.EqualTo("TestUserId"), "actualUserId");
                Assert.That(actualUser.FirstName, Is.EqualTo("Unit"), "actualFirstName");
                Assert.That(actualUser.StartingWeight, Is.EqualTo(88.8m), "actualStartingWeight");
                Assert.That(actualUser.StartingWeightDate, Is.EqualTo(new DateTime(2018, 7, 16)), "actualStartingWeightDate");
                Assert.That(actualUser.UserKey, Is.Not.Null.And.Not.Empty, "actualUserKey");


                dynamic user = JObject.Parse(userOutputJson);
                Assert.That((string)user.UserId, Is.EqualTo("TestUserId"), "UserId");
                Assert.That((string)user.FirstName, Is.EqualTo("Unit"), "FirstName");
                Assert.That((decimal)user.StartingWeight, Is.EqualTo(88.8m), "StartingWeight");
                Assert.That((DateTime)user.StartingWeightDate, Is.EqualTo(new DateTime(2018, 7, 16)), "StartingWeightDate");
                Assert.That((string)user.UserKey, Is.Not.Null.And.Not.Empty, "UserKey");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public APIGatewayProxyResponse FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            context.Logger.Log("Starting User Post call");

            using (AwsFactory factory = new AwsFactory(context.Logger))
            {
                using (PostUser postUser = new PostUser(factory))
                {
                    context.Logger.Log($"Request body: {request.Body}");

                    string jsonResponse = postUser.Save(request.Body);

                    context.Logger.LogLine($"Response: {jsonResponse}");

                    APIGatewayProxyResponse response = new APIGatewayProxyResponse()
                    {
                        Body       = jsonResponse,
                        StatusCode = 200
                    };

                    return(response);
                }
            }
        }