Beispiel #1
0
        public void TestGoodRequestButSendGridError()
        {
            var stringContent = new StringContent("");
            var tempResponse  = new HttpResponseMessage();

            tempResponse.Headers.Add("deviceId", "1234");
            SendGrid.Response response1 = new SendGrid.Response(HttpStatusCode.BadRequest, stringContent, tempResponse.Headers);
            sendGridClient.Setup(t => t.SendEmail(It.IsAny <SendGridMessage>())).Returns(response1);

            var request  = TestFactory.CreateHttpRequest("{\"Subject\":\"Please Help\",\"Email\":\"[email protected]\",\"Phone\":\"513.204.9321\",\"FullName\":\"Brandon Schenz\",\"Message\":\"I need more info RIGHT away!\"}");
            var response = (BadRequestObjectResult)_fixture.Run(request, testLogger);

            Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
        }
Beispiel #2
0
        public void TestBadRequest()
        {
            var stringContent = new StringContent("");
            var tempResponse  = new HttpResponseMessage();

            tempResponse.Headers.Add("deviceId", "1234");
            SendGrid.Response response1 = new SendGrid.Response(HttpStatusCode.Accepted, stringContent, tempResponse.Headers);
            sendGridClient.Setup(t => t.SendEmail(It.IsAny <SendGridMessage>())).Returns(response1);

            var request  = TestFactory.CreateHttpRequest("");
            var response = (BadRequestObjectResult)_fixture.Run(request, testLogger);

            Assert.AreEqual("Error While Sending Email", response.Value);
        }
Beispiel #3
0
        public void TestGoodRequestButStorageConnectionError()
        {
            var principal = AccessTokenResult.Success(new System.Security.Claims.ClaimsPrincipal());

            tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal);

            var exception = new NullReferenceException("");

            userRepository.Setup(t => t.Add(It.IsAny <UserEntity>(), It.IsAny <String>())).Throws(exception);

            var request  = TestFactory.CreateHttpRequest("{\"id\": \"TEST\",\"name\": \"Test User\",\"family_name\": \"User\",\"given_name\": \"Test\",\"city\": \"\",\"country\": \"\",\"postalCode\": \"\",\"state\": \"\",\"streetAddress\": \"\",\"email\": \"[email protected]\",\"isNew\": false,}");
            var response = (BadRequestObjectResult)_fixture.Run(request, testLogger);

            Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
        }
Beispiel #4
0
        public void TestDuplicateRecordReturnsConflictStatus()
        {
            var principal = AccessTokenResult.Success(new System.Security.Claims.ClaimsPrincipal());

            tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal);

            var exception = new StorageException("Conflict");

            userRoleRepository.Setup(t => t.Add(It.IsAny <UserRoleEntity>())).Throws(exception);

            var request  = TestFactory.CreateHttpRequest("{\"userId\": \"TEST\",\"roleName\": \"TestRole\",}");
            var response = (ConflictObjectResult)_fixture.Run(request, testLogger);

            Assert.AreEqual(StatusCodes.Status409Conflict, response.StatusCode);
        }
Beispiel #5
0
        public void TestGoodRequestButStorageConnectionError()
        {
            var principal = AccessTokenResult.Success(new System.Security.Claims.ClaimsPrincipal());

            tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal);

            var exception = new NullReferenceException("");

            userRoleRepository.Setup(t => t.Get(It.IsAny <String>())).Throws(exception);

            var request  = TestFactory.CreateHttpRequest("{\"userId\": \"TEST\",\"roleName\": \"TestRole\",}");
            var response = (BadRequestObjectResult)_fixture.Run(request, userId, testLogger);

            Assert.AreEqual(StatusCodes.Status400BadRequest, response.StatusCode);
        }
Beispiel #6
0
        public void TestGoodRequest()
        {
            var principal = AccessTokenResult.Success(new System.Security.Claims.ClaimsPrincipal());

            tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal);

            var userEntity = new UserEntity()
            {
                Id            = "TEST",
                Name          = "Test User",
                FamilyName    = "User",
                GivenName     = "Test",
                City          = "",
                Country       = "",
                PostalCode    = "",
                State         = "",
                StreetAddress = "",
                Email         = "*****@*****.**",
            };

            var tableResult = new TableResult();

            tableResult.Result         = userEntity;
            tableResult.HttpStatusCode = StatusCodes.Status201Created;
            userRepository.Setup(t => t.Add(It.IsAny <UserEntity>(), It.IsAny <String>())).Returns(Task.FromResult(tableResult));

            var request  = TestFactory.CreateHttpRequest("{\"id\": \"TEST\",\"name\": \"Test User\",\"family_name\": \"User\",\"given_name\": \"Test\",\"city\": \"\",\"country\": \"\",\"postalCode\": \"\",\"state\": \"\",\"streetAddress\": \"\",\"email\": \"[email protected]\",\"isNew\": false,}");
            var response = (CreatedResult)_fixture.Run(request, testLogger);

            Assert.AreEqual(StatusCodes.Status201Created, response.StatusCode);
            var returnEntity = (UserEntity)((TableResult)response.Value).Result;

            Assert.AreEqual(userEntity.Id, returnEntity.Id);
            Assert.AreEqual(userEntity.Name, returnEntity.Name);
            Assert.AreEqual(userEntity.FamilyName, returnEntity.FamilyName);
            Assert.AreEqual(userEntity.GivenName, returnEntity.GivenName);
            Assert.AreEqual(userEntity.City, returnEntity.City);
            Assert.AreEqual(userEntity.Country, returnEntity.Country);
            Assert.AreEqual(userEntity.PostalCode, returnEntity.PostalCode);
            Assert.AreEqual(userEntity.State, returnEntity.State);
            Assert.AreEqual(userEntity.StreetAddress, returnEntity.StreetAddress);
            Assert.AreEqual(userEntity.Email, returnEntity.Email);
        }