Example #1
0
        public void SetUp()
        {
            var createEmailAccountCommand = new CreateEmailAccount
            {
                SiteId             = Guid.NewGuid(),
                Id                 = Guid.NewGuid(),
                Address            = "*****@*****.**",
                DisplayName        = "My Site",
                Host               = "host",
                Port               = 25,
                UserName           = "******",
                Password           = "******",
                DefaultCredentials = true,
                Ssl                = true
            };
            var createEmailAccountValidatorMock = new Mock <IValidator <CreateEmailAccount> >();

            createEmailAccountValidatorMock.Setup(x => x.Validate(createEmailAccountCommand)).Returns(new ValidationResult());
            _emailAccount = EmailAccount.CreateNew(createEmailAccountCommand, createEmailAccountValidatorMock.Object);

            _command = new DeleteEmailAccount
            {
                SiteId = _emailAccount.SiteId,
                Id     = _emailAccount.Id
            };

            _validatorMock = new Mock <IValidator <DeleteEmailAccount> >();
            _validatorMock.Setup(x => x.Validate(_command)).Returns(new ValidationResult());

            _emailAccount.Delete(_command, _validatorMock.Object);

            _event = _emailAccount.Events.OfType <EmailAccountDeleted>().SingleOrDefault();
        }
        public void Should_have_validation_error_when_site_id_is_empty()
        {
            var command = new DeleteEmailAccount
            {
                SiteId = Guid.Empty,
                Id     = Guid.NewGuid()
            };

            var siteRulesMock = new Mock <ISiteRules>();
            var validator     = new DeleteEmailAccountValidator(siteRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.SiteId, command);
        }
Example #3
0
        public void Delete(DeleteEmailAccount cmd, IValidator <DeleteEmailAccount> validator)
        {
            validator.ValidateCommand(cmd);

            if (Status == EmailAccountStatus.Deleted)
            {
                throw new Exception("Email account already deleted.");
            }

            AddEvent(new EmailAccountDeleted
            {
                SiteId          = SiteId,
                AggregateRootId = Id
            });
        }
        public void Should_have_validation_error_when_site_does_not_exist()
        {
            var command = new DeleteEmailAccount
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var siteRulesMock = new Mock <ISiteRules>();

            siteRulesMock.Setup(x => x.DoesSiteExist(command.SiteId)).Returns(false);

            var validator = new DeleteEmailAccountValidator(siteRulesMock.Object);

            validator.ShouldHaveValidationErrorFor(x => x.SiteId, command);
        }
Example #5
0
        public void Should_throw_exception_when_email_account_is_not_found()
        {
            var command = new DeleteEmailAccount
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var repositoryMock = new Mock <IEmailAccountRepository>();

            repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns((EmailAccount)null);

            var validatorMock = new Mock <IValidator <DeleteEmailAccount> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var deleteEmailAccountHandler = new DeleteEmailAccountHandler(repositoryMock.Object, validatorMock.Object);

            Assert.Throws <Exception>(() => deleteEmailAccountHandler.Handle(command));
        }
Example #6
0
        public void Should_update_emailAccount()
        {
            var command = new DeleteEmailAccount
            {
                SiteId = Guid.NewGuid(),
                Id     = Guid.NewGuid()
            };

            var emailAccountMock = new Mock <EmailAccount>();

            var repositoryMock = new Mock <IEmailAccountRepository>();

            repositoryMock.Setup(x => x.GetById(command.SiteId, command.Id)).Returns(emailAccountMock.Object);

            var validatorMock = new Mock <IValidator <DeleteEmailAccount> >();

            validatorMock.Setup(x => x.Validate(command)).Returns(new ValidationResult());

            var deleteEmailAccountHandler = new DeleteEmailAccountHandler(repositoryMock.Object, validatorMock.Object);

            deleteEmailAccountHandler.Handle(command);

            repositoryMock.Verify(x => x.Update(It.IsAny <EmailAccount>()));
        }