public void Request_ForApiController_Throws_WhenControllerRequestIsNull()
        {
            // Arrange
            ApiController controller = CreateController();

            Assert.Null(controller.Request);
            BadRequestResult result = CreateProductUnderTest(controller);

            // Act & Assert
            InvalidOperationException exception = Assert.Throws <InvalidOperationException>(() =>
                                                                                            { HttpRequestMessage ignore = result.Request; }, "ApiController.Request must not be null.");
        }
Exemple #2
0
        public void Request_Returns_InstanceProvided()
        {
            // Arrange
            using (HttpRequestMessage expectedRequest = CreateRequest())
            {
                BadRequestResult result = CreateProductUnderTest(expectedRequest);

                // Act
                HttpRequestMessage request = result.Request;

                // Assert
                Assert.Same(expectedRequest, request);
            }
        }
Exemple #3
0
        public void ApiControllerBadRequest_CreatesCorrectResult()
        {
            // Arrange
            ApiController controller = CreateController();

            // Act
            BadRequestResult result = controller.BadRequest();

            // Assert
            Assert.NotNull(result);

            using (HttpRequestMessage expectedRequest = CreateRequest())
            {
                controller.Request = expectedRequest;
                Assert.Same(expectedRequest, result.Request);
            }
        }
Exemple #4
0
        public void Request_ForApiController_EvaluatesLazily()
        {
            // Arrange
            ApiController    controller = CreateController();
            BadRequestResult result     = CreateProductUnderTest(controller);

            using (HttpRequestMessage expectedRequest = CreateRequest())
            {
                controller.Request = expectedRequest;

                // Act
                HttpRequestMessage request = result.Request;

                // Assert
                Assert.Same(expectedRequest, request);
            }
        }
        public void Get_ConfirmEmail_Should_Return_BadRequest_ModelState()
        {
            //Action
            GenerateData("1", new[] { "NoRoles" });
            RegisterController registerController = new RegisterController(userService.Object,
                tokenValidation.Object,
                incUserMapper.Object,
                mesService.Object);

            //Arrange
            int userId = 0;
            string code = "";

            Assert.AreEqual(userId, 0);
            Assert.AreEqual(code, "");

            var actual = registerController.ConfirmEmail(userId, code);
            var badRequestResult = new BadRequestResult(registerController);
            InvalidModelStateResult invalidModel = new InvalidModelStateResult(registerController.ModelState, registerController);
            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.GetType(), invalidModel.GetType());
        }
        public async Task Post_Register_Should_Return_BadRequest()
        {
            //Arrange
            var registerUser = new RegisterUserModel
            {
                Login = "******",
                Email = "*****@*****.**",
                Password = "******",
                Id = 0
            };

            var incomingUser = new IncomingUser
            {
                Name = "Cat-Ok",
                Email = "*****@*****.**",
                Password = "******",
                Token = "asdf",
                Id = 1
            };

            var user = new User
            {
                Name = "Roman Hapatyn",
                Email = "*****@*****.**",
                Password = "******",
                HashedToken = "asdf",
                Id = 1
            };

            TokenModel token = new TokenModel();
            token.RolesToken = "Student";

            //Action
            GenerateData("1", new[] { "NoRoles" });
            RegisterController registerController = new RegisterController(userService.Object,
                tokenValidation.Object,
                incUserMapper.Object,
                mesService.Object);
            var tokenModel = new TokenModel();
            string locationUrl = "http://location/";

            var message = new IdentityMessage
            {
                Body = "Please confirm your account at: www.xxx.xxx ",
                Destination = "*****@*****.**",
                Subject = "Confirm your registration"
            };

            urlHelper.Setup(x => x.Link(It.IsAny<string>(), It.IsAny<object>()))
                .Returns(locationUrl);
            registerController.Url = urlHelper.Object;

            mesService
                .Setup(x => x.SendAsync(message))
                .Returns(Task.FromResult(0));
           
            incUserMapper
                .Setup(x => x.ToIncomingUser(registerUser))
                .Returns(incomingUser);

            userMapper
                .Setup(x => x.Map(registerUser))
                .Returns(user);

            userService
                .Setup(x => x.Exists(incomingUser))
                .Returns(true);

            tokenValidation
                .Setup(x => x.GetHashSha256("asdf"))
                .Returns("fdsa");

            var actual = await registerController.Post(registerUser);
            var badRequestResult = new BadRequestResult(registerController);
            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(actual.GetType(), badRequestResult.GetType());
        }