public async Task GetUser_ExistingUser_ReturnOk()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //Act
            var actionResult = await userController.GetUser(database.First().User.UserName);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(OkObjectResult), "GetUser endpoint on a existing user should return Ok(200)");
        }
        public async Task CreateUser_AlreadyExistingUser_ReturnBadRequest()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //Act
            var actionResult = await userController.CreateUser(database.First().User);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(BadRequestObjectResult), "CreateUser endpoint on already existing user should return BadRequest(400)");
        }
        public async Task CreateUser_NewUser_ReturnCreated()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);
            var user     = UserFactory.GetUser();

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //Act
            var actionResult = await userController.CreateUser(user);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(CreatedResult), "CreateUser endpoint on new user should return Created(201)");
        }
        public async Task DeleteUser_NonExistingUser_ReturnNotFound()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);
            var user     = UserFactory.GetUser();

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //Act
            var actionResult = await userController.DeleteUser(user.UserName);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(NotFoundObjectResult), "DeleteUser endpoint on a non existing user should return NotFound(404)");
        }
        public async Task GetReciept_NonExistingRecieptId_ReturnNotFound()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);
            var reciept  = RecieptFactory.GetReciept();

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //Act
            var actionResult = await userController.GetReciept(database.First().User.UserName, reciept.Id);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(NotFoundObjectResult), "GetReciept endpoint on a existing user but non existing RecieptId should return NotFound(404)");
        }
        public async Task CreateReciept_CorrectReciept_ReturnCreated()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);
            var reciept  = database.First().Reciepts.First();

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //Act
            var actionResult = await userController.CreateReciept(reciept.UserName, reciept);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(CreatedResult), "CreateReciept endpoint on a correct reciept should return Created(201)");
        }
        public async Task CreateReciept_ExistingUserRecieptWithMissingRequiredFields_ReturnBadRequest()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);
            var reciept  = database.First().Reciepts.First();

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //add a error on the ModelState to mock the fail of a model validation
            userController.ModelState.AddModelError("ValidationError", "Missing reciept requiered fields");

            //Act
            var actionResult = await userController.CreateReciept(reciept.UserName, reciept);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(BadRequestObjectResult), "CreateReciept endpoint on a existing User but reciept with missing requiered fields should return BadRequest(400)");
        }
        public async Task CreateUser_UserWithNoPassword_ReturnBadRequest()
        {
            //Arrange
            var database = UserRowFactory.GetDatabase(1);
            var user     = UserFactory.GetUser();

            user.Password = null;

            var mockUserService    = new MockUserService(database);
            var mockRecieptService = new MockRecieptService(database);
            var userController     = new UserController(new Mock <ILogger <UserController> >().Object, mockUserService, mockRecieptService);

            //add a error on the ModelState to mock the fail of a model validation
            userController.ModelState.AddModelError("ValidationError", "Missing Password field");

            //Act
            var actionResult = await userController.CreateUser(user);

            //Assert
            Assert.IsInstanceOfType(actionResult.Result, typeof(BadRequestObjectResult), "CreateUser endpoint on a User with no Password should return BadRequest(400)");
        }