Esempio n. 1
0
        public void CreateReminder()
        {
            ReminderModel reminder = new ReminderModel()
              {
            Day = 7,
            Month = 6,
            Email = Guid.NewGuid().ToString() + "@gmx.de",
            Name = "Patrick Epstein",
            Password = "******",
            TimeZoneOffset = -2
              };

              //Create reminder with unknown email address
              FakeMessageService messageService = new FakeMessageService();
              HomeController controller = new HomeController( messageService );
              var controllerResult = controller.CreateReminder( reminder ) as ViewResult;

              //Verify Controller Result
              Assert.That( controllerResult.ViewName == "Success" );
              Assert.That( (bool)controllerResult.ViewData["EmailVerified"], Is.False );
              //Assert verification email sent
              Assert.That( messageService.IsVerificationEmailSent(), Is.True );
              string verificationCode = messageService.SentVerificationCode;
              Assert.False( string.IsNullOrEmpty( verificationCode ) );
              Assert.That( messageService.VerificationEmailsSentCount, Is.EqualTo( 1 ) );

              //Try to create another reminder, same mail address still not verfied
              reminder.Name = "Heinz Erhardt";
              reminder.Day = 14;
              reminder.Month = 4;
              controllerResult = controller.CreateReminder( reminder ) as ViewResult;

              //Verify Controller Result
              Assert.That( controllerResult.ViewName == "Success" );
              Assert.That( (bool)controllerResult.ViewData["EmailVerified"], Is.False );
              //Verify no new email was sent out
              Assert.That( messageService.VerificationEmailsSentCount, Is.EqualTo( 1 ) );

              //Try to verify email address (emulate link clicking in email)
              VerificationController verificationController = new VerificationController();
              controllerResult = verificationController.VerifyMailAddress( verificationCode ) as ViewResult;

              //Verify Controller Result
              Assert.True( (bool)controllerResult.ViewData["VerificationSuccess"] );

              //Try to create another reminder, same mail address and now also verfied
              reminder.Name = "Karl Gustav";
              reminder.Day = 18;
              reminder.Month = 2;
              controllerResult = controller.CreateReminder( reminder ) as ViewResult;

              //Verify Controller Result
              Assert.That( controllerResult.ViewName == "Success" );
              Assert.That( (bool)controllerResult.ViewData["EmailVerified"], Is.True );

              //Verify no new email was sent out
              Assert.That( messageService.VerificationEmailsSentCount, Is.EqualTo( 1 ) );
        }
Esempio n. 2
0
        public void GetNextRemindingDateTest()
        {
            var homeController = new HomeController();
              ReminderModel germanyModel = new ReminderModel()
              {
            Day = 7,
            Month = 6,
            TimeZoneOffset = -2 //Germany daylight saving time (sommerzeit)
              };

              //assert with date later than reminder date of this year
              var germanyActual = homeController.GetNextRemindingDate( germanyModel, DateTime.Now );
              DateTime germanyExpected = new DateTime( 2012, 6, 7, 0, 0, 0 );
              Assert.AreEqual( germanyActual, germanyExpected );

              //assert wiht date before reminder date
              DateTime beforeDate = new DateTime( 2009, 6, 4 );
              germanyActual = homeController.GetNextRemindingDate( germanyModel, beforeDate );
              germanyExpected = new DateTime( 2011, 6, 7, 0, 0, 0 );
              Assert.AreEqual( germanyActual, germanyExpected );
        }
Esempio n. 3
0
        public void HourlyMaintenanceTest()
        {
            FakeMessageService messageMock = new FakeMessageService();
              //Create reminder with unknown email address at first
              string emailAddress = Guid.NewGuid().ToString() + "@gmx.de";
              ReminderModel reminder = GetReminder( emailAddress );

              var homeController = new HomeController( messageMock );
              homeController.CreateReminder( reminder );

              //Verify that no reminder mail has been sent
              Assert.That( messageMock.ReminderEmailsSentCount, Is.EqualTo( 0 ) );

              //Insert a remindii directly into the database
              int mailID = _db.GetEmailID( emailAddress );
              _db.AddReminder( reminder, mailID, DateTime.Now.AddDays( -1 ) );

              //Run hourly maintenance and check that no mail is sent out (email not verified yet)
              var maintenanceController = new MaintenanceController( messageMock );

              Assert.That( messageMock.ReminderEmailsSentCount, Is.EqualTo( 0 ) );

              //Verify user
              new VerificationController().VerifyMailAddress( messageMock.SentVerificationCode );

              //Run hourly maintenance and no the reminder should be sent out
              new MaintenanceController( messageMock ).Hourly( "1234" );
              Assert.That( messageMock.ReminderEmailsSentCount, Is.EqualTo( 1 ) );
              Assert.That( messageMock.SentoutReminder.EmailAddress, Is.EqualTo( emailAddress ) );
              Assert.That( messageMock.SentoutReminder.Name, Is.EqualTo( reminder.Name ) );

              //run hourly again and verify that no other reminder will be sent out
              new MaintenanceController( messageMock ).Hourly( "1234" );
              Assert.That( messageMock.ReminderEmailsSentCount, Is.EqualTo( 1 ) );
        }