示例#1
0
        public void Register_LoginNameAlreadyExist()
        {
            const string loginName = "user001";

            var mockIAccountDataStore = new Mock <IAccountDataStore>();

            var controller = new RegisterController(mockIAccountDataStore.Object);

            mockIAccountDataStore.Setup(m => m.CheckLoginNameExist(loginName)).Returns(() => new Response <bool>()
            {
                Data = true, ErrorMessage = string.Empty
            });

            var result = controller.Create(new RegistrationViewModel()
            {
                LoginName    = loginName,
                Address      = string.Empty,
                FirstName    = string.Empty,
                LastName     = string.Empty,
                Password     = string.Empty,
                EmailAddress = string.Empty
            });

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.True(viewResult.ViewData.ModelState[""].Errors.Count == 1);
            Assert.Equal("Index", viewResult.ViewName);
        }
示例#2
0
        public void Register_Success()
        {
            const string loginName = "user001";

            var mockIAccountDataStore = new Mock <IAccountDataStore>();

            var controller = new RegisterController(mockIAccountDataStore.Object);

            mockIAccountDataStore.Setup(m => m.CheckLoginNameExist(loginName)).Returns(() => new Response <bool>()
            {
                Data = false, ErrorMessage = string.Empty
            });

            mockIAccountDataStore.Setup(m => m.Register(It.IsAny <AccountDetails>())).Returns(() => new Response <bool>()
            {
                Data = true, ErrorMessage = string.Empty
            });

            var result = controller.Create(new RegistrationViewModel()
            {
                LoginName    = loginName,
                Address      = string.Empty,
                FirstName    = string.Empty,
                LastName     = string.Empty,
                Password     = string.Empty,
                EmailAddress = string.Empty
            });

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal("Successfully created new account.", viewResult.ViewData["Success"]);
            Assert.Equal("Index", viewResult.ViewName);
        }