public async Task Registration_FailsOnInvalidCSRF(string csrfValue)
        {
            var csrfMock = new Mock <ITokenVerifier>();

            csrfMock.Setup(csrf => csrf.IsValidCSRFToken(csrfValue, null, false))
            .Returns(false).Verifiable();

            var notificationsMock = new Mock <IModelUpdateNotificationSender>();
            var jobClientMock     = new Mock <IBackgroundJobClient>();

            await using var database = new NotificationsEnabledDb(dbOptions, notificationsMock.Object);

            var controller = new RegistrationController(logger, dummyRegistrationStatus, csrfMock.Object, database,
                                                        jobClientMock.Object);

            var result = await controller.Post(new RegistrationFormData()
            {
                CSRF             = csrfValue, Email = "*****@*****.**", Name = "test", Password = "******",
                RegistrationCode = RegistrationCode
            });

            var objectResult = Assert.IsAssignableFrom <ObjectResult>(result);

            Assert.Equal(400, objectResult.StatusCode);
            Assert.Empty(database.Users);

            csrfMock.Verify();
        }
        public async Task Register()
        {
            await _controller.Post(new Investor("Web", "Based", "User"));

            //TODO : Assert that the Investor is Registered
            Assert.True(true);
        }
Exemplo n.º 3
0
        public async Task Post_InvalidModelState()
        {
            var logger = new Mock <ILogger <RegistrationController> >();

            var ctrl = new RegistrationController(null, logger.Object);

            ctrl.ModelState.AddModelError("key", "error message");
            var res = await ctrl.Post(new RegistrationModel());

            res.ShouldBeOfType <BadRequestResult>();
        }
Exemplo n.º 4
0
        public void TestPost()
        {
            _service.Setup(s => s.CreateUserWithAccount("aUser")).Returns(new UserRecord(123, "aUser"));

            var response = _controller.Post(new UserInfo(-1, "aUser", ""));
            var body     = (UserInfo)((ObjectResult)response).Value;

            Assert.IsType <CreatedResult>(response);

            Assert.Equal(123, body.Id);
            Assert.Equal("aUser", body.Name);
            Assert.Equal("registration info", body.Info);
        }
Exemplo n.º 5
0
        public void MobilePhoneAndEmailMustUnique()
        {
            // Arrange
            var randomNum = DateTime.Now.Millisecond;
            // Act
            var dummy = new registration()
            {
                date_of_birth = DateTime.Now,
                email         = string.Concat(randomNum, "*****@*****.**"),
                first_name    = "mukti",
                last_name     = "wibowo",
                gender        = "M",
                mobile_number = string.Concat("+6281626", randomNum)
            };

            var results = controller.Post(dummy);

            results = controller.Post(dummy);
            var response = results as OkNegotiatedContentResult <string>;

            Assert.AreEqual("mobile phone and email already exist", response.Content);
        }
Exemplo n.º 6
0
        public async Task Post_InvalidBadTopicNames()
        {
            var tSrv = new Mock <ITopicService>();

            tSrv.Setup(t => t.GetTopicIdsByTopicNames(It.IsAny <string>(), It.IsAny <IEnumerable <TopicRegistration> >()))
            .ReturnsAsync(null as IEnumerable <TopicRegistration>);

            var logger = new Mock <ILogger <RegistrationController> >();
            var ctrl   = new RegistrationController(tSrv.Object, logger.Object);
            var cm     = new RegistrationModel {
                Registrations = new[] { new TopicRegistration() }
            };
            var res = await ctrl.Post(cm);

            res.ShouldBeOfType <BadRequestResult>();
        }
        public async Task Registration_SucceedsAndCreatesUser()
        {
            var csrfValue = "JustSomeRandomString";

            var csrfMock = new Mock <ITokenVerifier>();

            csrfMock.Setup(csrf => csrf.IsValidCSRFToken(csrfValue, null, false))
            .Returns(true).Verifiable();
            var notificationsMock = new Mock <IModelUpdateNotificationSender>();
            var jobClientMock     = new Mock <IBackgroundJobClient>();

            notificationsMock
            .Setup(notifications => notifications.OnChangesDetected(EntityState.Added,
                                                                    It.IsAny <User>(), false)).Verifiable();

            await using var database = new NotificationsEnabledDb(dbOptions, notificationsMock.Object);

            var controller = new RegistrationController(logger, dummyRegistrationStatus, csrfMock.Object, database,
                                                        jobClientMock.Object);

            var result = await controller.Post(new RegistrationFormData()
            {
                CSRF             = csrfValue, Email = "*****@*****.**", Name = "test", Password = "******",
                RegistrationCode = RegistrationCode
            });

            var objectResult = Assert.IsAssignableFrom <ObjectResult>(result);

            Assert.Equal(201, objectResult.StatusCode);

            Assert.NotEmpty(database.Users);
            var user = await database.Users.FirstAsync();

            Assert.Equal("*****@*****.**", user.Email);
            Assert.Equal("test", user.UserName);
            Assert.NotEqual("password12345", user.PasswordHash);
            Assert.True(Passwords.CheckPassword(user.PasswordHash, "password12345"));

            notificationsMock.Verify();
        }
Exemplo n.º 8
0
        public void Add_New_Registration()
        {
            var mockRegistrationService = new Mock <IRegistrationService>();

            var registration = new Registration
            {
                CourseName = "Learn C#",
                DateTime   = DateTime.Now.ToString(),
                Email      = "*****@*****.**",
                Name       = "Someone"
            };

            mockRegistrationService.Setup(r => r.RegisterCourse(registration));
            var controller = new RegistrationController(mockRegistrationService.Object);

            var actionResult = controller.Post(registration);
            var result       = Assert.IsType <OkResult>(actionResult);

            Assert.Equal(200, result.StatusCode);

            mockRegistrationService.Verify(s => s.RegisterCourse(registration), Times.Once());
        }
Exemplo n.º 9
0
        public async Task Post_REturnsRegistrationData()
        {
            var regRes = new[]
            {
                new TopicRegistration()
            };
            var tSrv = new Mock <ITopicService>();

            tSrv.Setup(t => t.GetTopicIdsByTopicNames(It.IsAny <string>(), It.IsAny <IEnumerable <TopicRegistration> >()))
            .ReturnsAsync(regRes);

            var logger = new Mock <ILogger <RegistrationController> >();
            var ctrl   = new RegistrationController(tSrv.Object, logger.Object);
            var cm     = new RegistrationModel {
                Registrations = new[] { new TopicRegistration() }
            };
            var res = await ctrl.Post(cm);

            var ok = res.ShouldBeOfType <OkObjectResult>();

            ok.Value.ShouldBe(regRes);
        }