示例#1
0
        public void ReturnCorrectErrorWhenEndDateTimeIsLessThanStartDateTime()
        {
            var validator      = new EventEditViewModelValidator();
            var parentCampaign = new CampaignSummaryViewModel {
                EndDate = new DateTimeOffset(new DateTime(1999, 2, 1))
            };
            var model = new EventEditViewModel
            {
                StartDateTime = new DateTimeOffset(new DateTime(2000, 1, 1)),
                EndDateTime   = new DateTimeOffset(new DateTime(1999, 1, 1))
            };

            var errors = validator.Validate(model, parentCampaign);

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be earlier than the start date");
        }
示例#2
0
        public void RetrunCorrectErrorWhenModelsEndDateTimeIsGreaterThanParentCampaignsEndDate()
        {
            var validator      = new EventEditViewModelValidator();
            var parentCampaign = new CampaignSummaryViewModel
            {
                StartDate = new DateTimeOffset(new DateTime(2000, 1, 1)),
                EndDate   = new DateTimeOffset(new DateTime(2001, 1, 1))
            };
            var model = new EventEditViewModel
            {
                StartDateTime = new DateTimeOffset(new DateTime(2001, 1, 1)),
                EndDateTime   = new DateTimeOffset(new DateTime(2001, 2, 1)),
            };

            var errors = validator.Validate(model, parentCampaign);

            Assert.True(errors.Exists(x => x.Key.Equals("EndDateTime")));
            Assert.Equal(errors.Find(x => x.Key == "EndDateTime").Value, "End date cannot be later than the campaign end date " + parentCampaign.EndDate.ToString("d"));
        }