Exemple #1
0
        public void CanSendTemplateEmail()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                var outboundEmailDaemon = new OutboundEmail();

                // SETUP
                var email = fixture.TestEmail1();

                // EXECUTE
                //var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "template", null);
                var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "a16da250-a48b-42ad-88e1-bdde24ae1dee", null);
                uow.SaveChanges();

                //adding user for alerts at outboundemail.cs  //If we don't add user, AlertManager at outboundemail generates error and test fails.
                AddNewTestCustomer(email.From);
                
                var mockEmailer = new Mock<IEmailPackager>();
                mockEmailer.Setup(a => a.Send(envelope)).Verifiable();
                ObjectFactory.Configure(
                    a => a.For<IEmailPackager>().Use(mockEmailer.Object).Named(EnvelopeDO.SendGridHander));
                DaemonTests.RunDaemonOnce(outboundEmailDaemon);

                // VERIFY
                mockEmailer.Verify(a => a.Send(envelope), "OutboundEmail daemon didn't dispatch email via Mandrill.");
            }
        }
Exemple #2
0
        public void Setup()
        {
            StructureMapBootStrapper.ConfigureDependencies("test");

            _uow = ObjectFactory.GetInstance<IUnitOfWork>();

            userRepo = new UserRepository(_uow);
            _fixture = new FixtureData(_uow);
        }
        public void Setup()
        {
            StructureMapBootStrapper.ConfigureDependencies("test");
            _uow = ObjectFactory.GetInstance<IUnitOfWork>();

            _trackingStatusRepository = new TrackingStatusRepository(_uow);
            _emailRepo = new EmailRepository(_uow);


            _trackingStatus = new TrackingStatus<EmailDO>(_trackingStatusRepository, _emailRepo);

            _fixture = new FixtureData(_uow);
        }
        public void FailsToGenetrateBRNeedsProceessingEmail() 
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
              //  var testBookingRequest = fixture.TestBookingRequest1();
               // uow.BookingRequestRepository.Add(testBookingRequest);
                uow.SaveChanges();

                var configRepository = ObjectFactory.GetInstance<IConfigRepository>();
                configRepository.Set("EmailAddress_BrNotify", "");

                var communicationManager = new CommunicationManager(configRepository, new EmailAddress(configRepository));

                Assert.Throws<Exception>(() =>
                {
            //        communicationManager.BookingRequestNeedsProcessing(testBookingRequest.Id);
                });
            }
        }
        public void CanGenetrateBRNeedsProceessingEmail()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
              //  var testBookingRequest = fixture.TestBookingRequest1();
              //  uow.BookingRequestRepository.Add(testBookingRequest);
                uow.SaveChanges();

                var configRepository = ObjectFactory.GetInstance<IConfigRepository>();

                var communicationManager = new CommunicationManager(configRepository, new EmailAddress(configRepository));
              //  communicationManager.BookingRequestNeedsProcessing(testBookingRequest.Id);

                var emailDO = uow.EmailRepository.GetQuery().Where(e => e.Subject == "BookingRequest Needs Processing");
                Assert.AreEqual("BookingRequest Needs Processing <br/>Subject : Booking request subject", emailDO.First().HTMLText);
                Assert.AreEqual(1, emailDO.Count());
                Assert.AreEqual(1, uow.EnvelopeRepository.GetQuery().Where(e => e.EmailID == emailDO.First().Id).Count());
            }
        }
Exemple #6
0
        public async void ITest_CanResetPassword()
        {
            string email;
            string id;
            // SETUP
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixtureData = new FixtureData(uow);
                var userDO = fixtureData.TestUser1();
                uow.UserRepository.Add(userDO);
                uow.SaveChanges();
                id = userDO.Id;
                email = userDO.EmailAddress.Address;
            }

            // EXECUTE
            // generate a forgot password email
            var account = ObjectFactory.GetInstance<Account>();
            await account.ForgotPasswordAsync(email);
            // get callback url from generated email
            string callbackUrl;
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var envelopeDO = uow.EnvelopeRepository.GetQuery().Single();
                callbackUrl = (String)envelopeDO.MergeData["-callback_url-"];
            }
            var userId = Regex.Match(callbackUrl,
                                     "userId=(?<userId>[-a-f\\d]+)",
                                     RegexOptions.IgnoreCase)
                .Groups["userId"].Value;
            var code = Regex.Match(callbackUrl,
                                     "code=(?<code>[\\d]+)",
                                     RegexOptions.IgnoreCase)
                .Groups["code"].Value;
            var result = await account.ResetPasswordAsync(userId, code, "123456");

            // VERIFY
            Assert.AreEqual(id, userId);
            Assert.IsTrue(result.Succeeded, string.Join(", ", result.Errors));
        }
        public void CanOAuthRedirectToCallbackUrl()
        {
            // SETUP
            UserDO user;
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixtureData = new FixtureData(uow);
                user = fixtureData.TestUser1();
                uow.SaveChanges();
            }

            // EXECUTE
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var oauthProviders = uow.RemoteCalendarProviderRepository.GetQuery().Where(p => p.AuthType == ServiceAuthorizationType.OAuth2).ToArray();
                Assert.That(oauthProviders.Length > 0, "No OAuth providers.");
                foreach (var provider in oauthProviders)
                {
                    var authorizer = ObjectFactory.GetNamedInstance<IOAuthAuthorizer>(provider.Name);
                    var result = authorizer.AuthorizeAsync(
                        user.Id,
                        user.EmailAddress.Address,
                        UserController.GetCallbackUrl(provider.Name, "https://www.kwasant.com/"),
                        "https://www.kwasant.com/",
                        CancellationToken.None).Result;

                    // VERIFY
                    Assert.IsFalse(result.IsAuthorized, "User should be unauthorized.");
                    using (var httpClient = new HttpClient())
                    {
                        using (var response = httpClient.GetAsync(result.RedirectUri).Result)
                        {
                            // now here we are getting "403 Unathorized" instead of expected "200 OK" or "400 Bad Request", have to deal with google authorization somehow
                            Assert.IsTrue(response.IsSuccessStatusCode, string.Format("Redirected URL returned: {0}", response.StatusCode));
                        }
                    }
                }
            }
        }
Exemple #8
0
        public void Customer_Add_CanCreateUser()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                //SETUP
                //create a customer from fixture data
                UserDO curUserDO = fixture.TestUser1();

                //EXECUTE
                uow.UserRepository.Add(curUserDO);
                uow.SaveChanges();

                //VERIFY
                //check that it was saved to the db
                UserDO savedUserDO = uow.UserRepository.GetQuery().FirstOrDefault(u => u.Id == curUserDO.Id);
                Assert.AreEqual(curUserDO.FirstName, savedUserDO.FirstName);
                Assert.AreEqual(curUserDO.EmailAddress, savedUserDO.EmailAddress);

            }

        }
Exemple #9
0
        public void FailsToSendInvalidEnvelope()
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                var outboundEmailDaemon = new OutboundEmail();

                // SETUP
                var email = fixture.TestEmail1();

                // EXECUTE
                var envelope = uow.EnvelopeRepository.ConfigureTemplatedEmail(email, "a16da250-a48b-42ad-88e1-bdde24ae1dee", null);

                envelope.Handler = "INVALID EMAIL PACKAGER";
                uow.SaveChanges();

                //adding user for alerts at outboundemail.cs  //If we don't add user, AlertManager at outboundemail generates error and test fails.
                AddNewTestCustomer(email.From);

                var mockMandrillEmailer = new Mock<IEmailPackager>();
                mockMandrillEmailer.Setup(a => a.Send(envelope)).Throws<ApplicationException>(); // shouldn't be invoked
                ObjectFactory.Configure(
                    a => a.For<IEmailPackager>().Use(mockMandrillEmailer.Object).Named(EnvelopeDO.SendGridHander));
                var mockSendGridEmailer = new Mock<IEmailPackager>();
                mockSendGridEmailer.Setup(a => a.Send(envelope)).Throws<ApplicationException>(); // shouldn't be invoked
                ObjectFactory.Configure(
                    a => a.For<IEmailPackager>().Use(mockSendGridEmailer.Object).Named(EnvelopeDO.SendGridHander));

                // VERIFY
                Assert.Throws<UnknownEmailPackagerException>(
                    () => DaemonTests.RunDaemonOnce(outboundEmailDaemon),
                    "OutboundEmail daemon didn't throw an exception for invalid EnvelopeDO.");
            }
        }
Exemple #10
0
        private void AddNewTestCustomer(EmailAddressDO emailAddress)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var fixture = new FixtureData(uow);
                var outboundEmailDaemon = new OutboundEmail();

                emailAddress.Recipients = new List<RecipientDO>()
                {
                    new RecipientDO()
                    {
                        EmailAddress = Email.GenerateEmailAddress(uow, new MailAddress("*****@*****.**")),
                        EmailParticipantType = EmailParticipantType.To
                    }
                };
                uow.AspNetRolesRepository.Add(fixture.TestRole());
                var u = new UserDO();
                var user = new User();
                UserDO currUserDO = new UserDO();
                currUserDO.EmailAddress = emailAddress;
                uow.UserRepository.Add(currUserDO);
            }
        }