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 UserRoleEntity() { UserId = "TEST", RoleName = "TestRole", }; var tableResult = new TableResult(); tableResult.Result = userEntity; tableResult.HttpStatusCode = StatusCodes.Status201Created; userRoleRepository.Setup(t => t.Add(It.IsAny <UserRoleEntity>())).Returns(Task.FromResult(tableResult)); var request = TestFactory.CreateHttpRequest("{\"userId\": \"TEST\",\"roleName\": \"TestRole\",}"); var response = (CreatedResult)_fixture.Run(request, testLogger); Assert.AreEqual(StatusCodes.Status201Created, response.StatusCode); var returnEntity = (UserRoleEntity)((TableResult)response.Value).Result; Assert.AreEqual(userEntity.UserId, returnEntity.UserId); Assert.AreEqual(userEntity.RoleName, returnEntity.RoleName); }
public void TestGoodRequest() { var principal = AccessTokenResult.Success(new System.Security.Claims.ClaimsPrincipal()); tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal); var userRoleEntity = new UserRoleEntity() { UserId = "TEST", RoleName = "TestRole", PartitionKey = "TestRole", RowKey = "TEST" }; var ctor = typeof(TableQuerySegment <UserRoleEntity>) .GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic) .FirstOrDefault(c => c.GetParameters().Count() == 1); var mockQuerySegment = ctor.Invoke(new object[] { new List <UserRoleEntity>() { userRoleEntity } }) as TableQuerySegment <UserRoleEntity>; userRoleRepository.Setup(t => t.Get(It.IsAny <String>())).Returns(Task.FromResult(mockQuerySegment)); var request = TestFactory.CreateHttpRequest("{\"userId\": \"TEST\",\"roleName\": \"TestRole\",}"); var response = (OkObjectResult)_fixture.Run(request, userId, testLogger); Assert.AreEqual(StatusCodes.Status200OK, response.StatusCode); var returnEntityList = (TableQuerySegment <UserRoleEntity>)response.Value; var returnEntity = returnEntityList.FirstOrDefault(); Assert.AreEqual(userRoleEntity.UserId, returnEntity.UserId); Assert.AreEqual(userRoleEntity.RoleName, returnEntity.RoleName); }
public void TestBadRequestWithAuthToken() { var principal = AccessTokenResult.Success(new System.Security.Claims.ClaimsPrincipal()); tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal); var request = TestFactory.CreateHttpRequest(""); var response = (BadRequestObjectResult)_fixture.Run(request, testLogger); Assert.AreEqual(response.StatusCode, StatusCodes.Status400BadRequest); }
public void TestBadRequestNoAuthToken() { var principal = AccessTokenResult.NoToken(); tokenProvider.Setup(t => t.ValidateToken(It.IsAny <HttpRequest>())).Returns(principal); var request = TestFactory.CreateHttpRequest(""); var response = (UnauthorizedResult)_fixture.Run(request, testLogger); Assert.AreEqual(response.StatusCode, StatusCodes.Status401Unauthorized); }
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); }
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); }
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); }
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); }
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); }
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); }