예제 #1
0
        public void CreateUser()
        {
            var generator = new RandomObjectGenerator();
            var profileId = generator.Generate <string>();
            var entity    = EntityCreator.Create <Models.User>(_ => _.ProfileID = profileId);

            var user = new Mock <IUser>(MockBehavior.Strict);

            user.SetupSet(_ => _.BirthDate    = entity.BirthDate);
            user.SetupSet(_ => _.EmailAddress = entity.EmailAddress);
            user.SetupSet(_ => _.FirstName    = entity.FirstName);
            user.SetupSet(_ => _.Gender       = entity.Gender);
            user.SetupSet(_ => _.LastName     = entity.LastName);
            user.SetupSet(_ => _.PostalCode   = entity.PostalCode);
            user.SetupSet(_ => _.UserName     = entity.UserName);
            user.Setup(_ => _.Save()).Returns(null);

            var userFactory = new Mock <IObjectFactory <IUser> >(MockBehavior.Strict);

            userFactory.Setup(_ => _.Create(profileId)).Returns(user.Object);

            var controller = new UserController();

            controller.UserFactory = userFactory.Object;
            controller.Put(entity);

            userFactory.VerifyAll();
            user.VerifyAll();
        }
예제 #2
0
        public void Respond()
        {
            var generator = new RandomObjectGenerator();
            var userId    = generator.Generate <int>();
            var response  = EntityCreator.Create <Models.PollResponse>();

            var pollSubmission = new Mock <IPollSubmission>(MockBehavior.Strict);

            pollSubmission.Setup(_ => _.Save()).Returns(null);

            var pollSubmissionFactory = new Mock <IObjectFactory <IPollSubmission> >(MockBehavior.Strict);

            pollSubmissionFactory.Setup(_ => _.Create(It.IsAny <object>())).Returns(pollSubmission.Object);

            var auth = new Mock <IMyVoteAuthentication>(MockBehavior.Strict);

            auth.Setup(_ => _.GetCurrentUserID()).Returns(userId);

            var controller = new RespondController();

            controller.PollSubmissionFactory = pollSubmissionFactory.Object;
            controller.MyVoteAuthentication  = auth.Object;

            controller.Put(response);

            pollSubmissionFactory.VerifyAll();
            pollSubmission.VerifyAll();
            auth.VerifyAll();
        }
예제 #3
0
        internal static T Create <T>(Action <T> modifier)
            where T : new()
        {
            var entity = EntityCreator.Create <T>();

            modifier(entity);
            return(entity);
        }
예제 #4
0
        private static void TestPollPut(Action <Mock <IObjectFactory <IPoll> >, Poll, Mock <IPoll> > pollFactorySetup,
                                        Func <PollController, Poll, Poll> pollControllerInvocation)
        {
            var pollModel = EntityCreator.Create <Poll>(_ => _.PollOptions = null);

            var poll = new Mock <IPoll>(MockBehavior.Strict);

            poll.SetupSet(_ => _.PollCategoryID       = pollModel.PollCategoryID);
            poll.SetupSet(_ => _.PollQuestion         = pollModel.PollQuestion);
            poll.SetupSet(_ => _.PollImageLink        = pollModel.PollImageLink);
            poll.SetupSet(_ => _.PollMaxAnswers       = pollModel.PollMaxAnswers);
            poll.SetupSet(_ => _.PollMinAnswers       = pollModel.PollMinAnswers);
            poll.SetupSet(_ => _.PollStartDate        = pollModel.PollStartDate);
            poll.SetupSet(_ => _.PollEndDate          = pollModel.PollEndDate);
            poll.SetupSet(_ => _.PollAdminRemovedFlag = pollModel.PollAdminRemovedFlag);
            poll.SetupSet(_ => _.PollDateRemoved      = pollModel.PollDateRemoved);
            poll.SetupSet(_ => _.PollDeletedFlag      = pollModel.PollDeletedFlag);
            poll.SetupSet(_ => _.PollDeletedDate      = pollModel.PollDeletedDate);
            poll.SetupSet(_ => _.PollDescription      = pollModel.PollDescription);

            poll.SetupGet(_ => _.PollID).Returns(pollModel.PollID);
            poll.SetupGet(_ => _.UserID).Returns(pollModel.UserID);
            poll.SetupGet(_ => _.PollCategoryID).Returns(pollModel.PollCategoryID);
            poll.SetupGet(_ => _.PollQuestion).Returns(pollModel.PollQuestion);
            poll.SetupGet(_ => _.PollImageLink).Returns(pollModel.PollImageLink);
            poll.SetupGet(_ => _.PollMaxAnswers).Returns(pollModel.PollMaxAnswers);
            poll.SetupGet(_ => _.PollMinAnswers).Returns(pollModel.PollMinAnswers);
            poll.SetupGet(_ => _.PollStartDate).Returns(pollModel.PollStartDate);
            poll.SetupGet(_ => _.PollEndDate).Returns(pollModel.PollEndDate);
            poll.SetupGet(_ => _.PollAdminRemovedFlag).Returns(pollModel.PollAdminRemovedFlag);
            poll.SetupGet(_ => _.PollDateRemoved).Returns(pollModel.PollDateRemoved);
            poll.SetupGet(_ => _.PollDeletedFlag).Returns(pollModel.PollDeletedFlag);
            poll.SetupGet(_ => _.PollDeletedDate).Returns(pollModel.PollDeletedDate);
            poll.SetupGet(_ => _.PollDescription).Returns(pollModel.PollDescription);
            poll.SetupGet(_ => _.PollOptions).Returns(new BusinessList <IPollOption>());
            poll.Setup(_ => _.Save()).Returns(poll.Object);

            var pollFactory = new Mock <IObjectFactory <IPoll> >(MockBehavior.Strict);

            pollFactorySetup(pollFactory, pollModel, poll);

            var auth = new Mock <IMyVoteAuthentication>(MockBehavior.Strict);

            auth.Setup(_ => _.GetCurrentUserID()).Returns(pollModel.UserID);

            var controller = new PollController();

            controller.PollFactory          = new Lazy <IObjectFactory <IPoll> >(() => pollFactory.Object);
            controller.MyVoteAuthentication = auth.Object;

            var result = pollControllerInvocation(controller, pollModel);

            pollFactory.VerifyAll();
            poll.Verify();
        }