Esempio n. 1
0
        public async Task UserControllerTest_Delete_returnsNotFound()
        {
            // Arrange
            var user = new UserViewModel {
                FirstName = "Jonathan"
            };

            // Act
            var controller = new UserApiController(_userStore.Object);
            var res        = await controller.Delete("*****@*****.**");

            // Assert
            Assert.IsInstanceOfType(res, typeof(NotFoundResult));
        }
Esempio n. 2
0
        public async Task UserControllerTest_Delete_returnsBadRequest()
        {
            // Arrange
            var user = new UserViewModel {
                FirstName = "Jonathan"
            };

            // Act
            var controller = new UserApiController(_userStore.Object);
            var res        = await controller.Delete("");

            // Assert
            Assert.IsInstanceOfType(res, typeof(BadRequestErrorMessageResult));
        }
Esempio n. 3
0
        public async Task UserControllerTest_Delete_returnsInternalServerError()
        {
            // Arrange
            _userStore.Setup(x => x.Get(It.IsAny <string>())).Throws(new Exception("asd"));
            var user = new UserViewModel {
                FirstName = "Jonathan"
            };

            // Act
            var controller = new UserApiController(_userStore.Object);
            var res        = await controller.Delete("*****@*****.**");

            // Assert
            Assert.IsInstanceOfType(res, typeof(ExceptionResult));
        }
Esempio n. 4
0
        public async Task UserControllerTest_Delete_returnsOk()
        {
            // Arrange
            var user = new UserViewModel()
            {
                FirstName = "Jonathan"
            };

            _userStore.Setup(x => x.Get(It.IsAny <string>())).Returns(Task.FromResult <IAzureUser>(user));

            // Act
            var controller = new UserApiController(_userStore.Object);
            var res        = await controller.Delete("*****@*****.**");

            // Assert
            _userStore.Verify(x => x.DeleteUser(It.IsAny <IAzureUser>()));
            Assert.IsInstanceOfType(res, typeof(OkResult));
        }
        public void DeleteUser()
        {
            unitOfWork.Data = new MockData
            {
                Users = new List <User>
                {
                    new User
                    {
                        id            = 1,
                        email         = "user",
                        customer_code = "c1",
                        Roles         = new List <Role>
                        {
                            new Role {
                                id = Role.Admin
                            }
                        }
                    },
                    new User
                    {
                        id       = 2,
                        username = "******",
                        Roles    = new List <Role>
                        {
                            new Role {
                                id = Role.User
                            }
                        }
                    },
                    new User
                    {
                        id            = 3,
                        username      = "******",
                        customer_code = "c0",
                        Roles         = new List <Role>
                        {
                            new Role {
                                id = Role.BranchAdmin
                            }
                        }
                    },
                    new User
                    {
                        id            = 4,
                        username      = "******",
                        customer_code = "c2",
                        Roles         = new List <Role>
                        {
                            new Role {
                                id = Role.BranchAdmin
                            }
                        }
                    }
                },
                Customers = new List <Customer>
                {
                    new Customer {
                        code = "c0"
                    },
                    new Customer {
                        code = "c1", invoice_customer = "c0"
                    },
                    new Customer {
                        code = "c2"
                    }
                }
            };

            //User
            controller.Request.Headers.Authorization = new AuthenticationHeaderValue("jwt", "2");
            var result = controller.Delete(4);

            Assert.IsInstanceOfType(result, typeof(HttpResponseMessage));
            var message = result as HttpResponseMessage;

            Assert.AreEqual(HttpStatusCode.Unauthorized, message?.StatusCode);

            //Correct
            controller.Request.Headers.Authorization = new AuthenticationHeaderValue("jwt", "3");
            result = controller.Delete(4);
            Assert.IsNotInstanceOfType(result, typeof(HttpResponseMessage));
            Assert.AreEqual(3, unitOfWork.Data.Users.Count);
            Assert.AreEqual(true, result);
        }