コード例 #1
0
        public async Task Login_InvalidState_BadRequest()
        {
            // Arrange
            const string field        = "apple-error";
            const string errorMessage = "how do you like them apples";
            var          service      = new MockAccountService
            {
                MLogin = (model) => "Doesn't really matter a second time"
            };
            var controller = new AccountController(service);

            controller.ModelState.AddModelError(field, errorMessage);

            // Act
            var result = await controller.Login(MockLoginViewModel.Get(0)) as BadRequestObjectResult;

            var error = result?.Value as SerializableError;

            // Assert
            Assert.NotNull(error);
            Assert.Equal(400, result.StatusCode);
            Assert.Single(error.Keys);
            Assert.True(error.ContainsKey(field));
            Assert.Equal(new[] { errorMessage }, error.GetValueOrDefault(field));
        }
コード例 #2
0
        public void LoginViewModel_AllFieldsValid_NoErrors()
        {
            // Arrange
            var model = MockLoginViewModel.Get(1);

            // Act
            var validation = ModelValidator.ValidateModel(model);

            // Assert
            Assert.Equal(0, validation.Count);
        }
コード例 #3
0
        public void LoginViewModel_Setter_Modifies()
        {
            // Arrange
            var model = MockLoginViewModel.Get(0);

            // Act
            model.Password = "******";
            model.Email    = "*****@*****.**";

            // Assert
            Assert.Equal("*****@*****.**", model.Email);
            Assert.Equal("St0p-Making-S3ns3", model.Password);
        }
コード例 #4
0
        public async Task Login_LoginFailException_Unauthorized()
        {
            // Arrange
            var service = new MockAccountService {
                MLogin = (model) => throw new LoginFailException()
            };
            var controller = new AccountController(service);

            // Act
            var result = await controller.Login(MockLoginViewModel.Get(1)) as UnauthorizedResult;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(401, result.StatusCode);
        }
コード例 #5
0
        public async Task Login_Valid_OkWithToken()
        {
            // Arrange
            const string mockToken = "This is not a love-token song";
            var          service   = new MockAccountService {
                MLogin = (model) => string.Copy(mockToken)
            };
            var controller = new AccountController(service);

            // Act
            var result = await controller.Login(MockLoginViewModel.Get(1)) as OkObjectResult;

            var tokenReceived = result?.Value as string;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(200, result.StatusCode);
            Assert.NotNull(tokenReceived);
            Assert.Equal(string.Copy(mockToken), tokenReceived);
        }