Inheritance: IMembershipService
示例#1
0
        public ActionResult Index(int dinnerCount = 100)
        {
            const string name = "Nerd";
            var          membershipService = new AccountMembershipService();

            if (membershipService.ValidateUser(name, "password") == false)
            {
                membershipService.CreateUser(name, "password", "*****@*****.**");
            }
            var repo = new DinnerRepository();

            foreach (var d in repo.All)
            {
                repo.Delete(d.DinnerID);
            }
            for (var i = 0; i < dinnerCount; i++)
            {
                var dinner = new Dinner {
                    Title        = "Nerd-Out",
                    Description  = "Nerding out with the nerds",
                    EventDate    = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0)),
                    ContactPhone = "403-999-9999",
                    Address      = "Calgary, AB",
                    Country      = "Canada",
                    HostedById   = name,
                    HostedBy     = name
                };
                var rsvp = new RSVP {
                    AttendeeNameId = name, AttendeeName = name
                };
                dinner.RSVPs = new List <RSVP> {
                    rsvp
                };
                repo.InsertOrUpdate(dinner);
            }
            try {
                repo.Save();
            }
            catch (DbEntityValidationException e) {
                var error = e.EntityValidationErrors.First().ValidationErrors.First();
                return(new ContentResult {
                    Content = string.Format("{0}: {1}", error.PropertyName, error.ErrorMessage)
                });
            }
            return(new ContentResult {
                Content = "Success"
            });
        }
 private static AccountController GetAccountController()
 {
     IFormsAuthentication formsAuth = new MockFormsAuthenticationService();
     MembershipProvider membershipProvider = new MockMembershipProvider();
     AccountMembershipService membershipService = new AccountMembershipService(membershipProvider);
     AccountController controller = new AccountController(formsAuth, membershipService);
     ControllerContext controllerContext = new ControllerContext(new MockHttpContext(), new RouteData(), controller);
     controller.ControllerContext = controllerContext;
     return controller;
 }
        public void ConstructorSetsProperties()
        {
            // Arrange
            IFormsAuthentication formsAuth = new MockFormsAuthenticationService();
            IMembershipService membershipService = new AccountMembershipService();

            // Act
            AccountController controller = new AccountController(formsAuth, membershipService);

            // Assert
            Assert.AreEqual(formsAuth, controller.FormsAuth, "FormsAuth property did not match.");
            Assert.AreEqual(membershipService, controller.MembershipService, "MembershipService property did not match.");
        }