public void Update_ExistingAdultCustomer_Success_Composed(
            [AsAdultPersisted] Customer e,
            CustomerManager sut,
            IFixture fixture)
        {
            var data = fixture.Build<CustomerUpdate>()
                .With(x => x.ID, e.ID)
                .Create();

            sut.Update(data);
        }
        public void Create_ValidData_LogCreate(
            [AutoMapToCustomer] CustomerCreate data,
            [Frozen] Mock<ICustomerLogManager> customerLogManager,
            CustomerManager sut)
        {
            var e = sut.Create(data);

            customerLogManager.Verify(x => x.LogCreate(e));
        }
        public void Update_ExistingAdultCustomer_Success(
            //warning: the declaring order of the attrs
            //does not guarantee that customizations will
            //apply in that order, if ordering is required
            //then combine multiple customizations using
            //CompositeCustomizeAttribute like the example
            //below
            [Persisted][AsAdult] Customer e,
            IFixture fixture,
            [Frozen] Mock<ICustomerLogManager> customerLogManager,
            CustomerManager sut)
        {
            var data = fixture.Build<CustomerUpdate>()
                .With(x => x.ID, e.ID)
                .Create();

            sut.Update(data);

            customerLogManager.Verify(x => x.LogUpdate(It.Is<Customer>(c => c.ID == data.ID)));
        }
        public void Create_ExistingEmail_Exception(
            IDataContextWrapper db,
            CustomerCreate data,
            CustomerManager sut)
        {
            data.Email = db.Set<Customer>().Select(x => x.Email).First();

            Assert.Throws<CustomerManager.EmailAlreadyExistsException>(() =>
                sut.Create(data));
        }
        public void Create_InvalidEmail_InvalidOp___WithInvalidEmailAsAdultComposed(
            [WithInvalidEmailAsAdult] CustomerCreate data,
            [Frozen] Mock<IAuthService> authService,
            [Frozen] Mock<IMailer> mailer,
            CustomerManager sut)
        {
            Assert.True(data.Age == 21);
            Assert.Throws<InvalidOperationException>(() =>
                sut.Create(data));

            mailer.Verify(x => x.Send(data.Email, It.IsAny<string>()), Times.Never);
        }
        public void Create_InvalidEmail_InvalidOp(
            CustomerCreate data,
            [Frozen] Mock<IAuthService> authService,
            [Frozen] Mock<IMailer> mailer,
            CustomerManager sut)
        {
            data.Email = "invalid";

            Assert.Throws<InvalidOperationException>(() =>
                sut.Create(data)
            );

            mailer.Verify(x => x.Send(data.Email, It.IsAny<string>()), Times.Never);
        }
        public void Create_ValidEmail_SendMail2(
            [MapToCustomer] CustomerCreate data,
            [Frozen] Mock<IAuthService> authService,
            [Frozen] Mock<IMailer> mailer,
            CustomerManager sut)
        {
            sut.Create(data);

            mailer.Verify(x => x.Send(data.Email, "Welcome"));
        }