Ejemplo n.º 1
0
        public void Save_ThrowsExceptionOnSave_SavesLog()
        {
            var user = new User()
            {
                Name  = "John",
                Email = "*****@*****.**"
            };

            var exception = new Exception("Fail to connect to database");

            var emailValidation = MockRepository.GenerateStub <IEmailValidation>();
            var userRepository  = MockRepository.GenerateStub <IUserRepository>();
            var logService      = MockRepository.GenerateMock <ILogService>();

            emailValidation.Stub(p => p.isValid(It.IsAny <string>())).Return(true);
            userRepository.Stub(p => p.Save(It.Is <User>(u => u.Equals(user)))).Throw(exception);
            logService.Expect(p => p.LogError(It.Is <Exception>(e => e.Equals(exception))));

            var userService = new UserService(userRepository, emailValidation);

            userService.LogService = logService;

            userService.Save(user);

            userRepository.VerifyAllExpectations();
        }
        public void IsMockableWithRhino()
        {
            var paletteHelper = MockRepository.GenerateStub <PaletteHelper>();

            paletteHelper.SetLightDark(true);

            paletteHelper.AssertWasCalled(ph => ph.SetLightDark(true));
        }
Ejemplo n.º 3
0
        public void Save_InvalidEmail_ThrowsException()
        {
            var user = new User()
            {
                Name  = "John",
                Email = "email"
            };

            var emailValidation = MockRepository.GenerateStub <IEmailValidation>();

            emailValidation.Stub(p => p.isValid(It.IsAny <string>())).Return(false);

            var userService = new UserService(null, emailValidation);

            Assert.Throws(typeof(ArgumentException), () => userService.Save(user), "Email is invalid");
        }
Ejemplo n.º 4
0
        public void Save_ValidUser_Success()
        {
            var user = new User()
            {
                Name  = "John",
                Email = "*****@*****.**"
            };

            var emailValidation = MockRepository.GenerateStub <IEmailValidation>();
            var userRepository  = MockRepository.GenerateMock <IUserRepository>();

            emailValidation.Stub(p => p.isValid(It.IsAny <string>())).Return(true);
            userRepository.Expect(p => p.Save(It.Is <User>(u => u.Equals(user))));

            var userService = new UserService(userRepository, emailValidation);

            userService.Save(user);

            userRepository.VerifyAllExpectations();
        }