public void PassesWhen_TopOfAnHourPrimaryPropertyIsSupplied()
        {
            //arrange
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            //act

           var rule = new TopOfTheHourRule(startTimeProperty.Object);
           
            //assert
           Assert.IsNotNull(rule);
        }
        public void FailsWhen_OnTopOfAnHourPrimaryPropertyValueNotSet()
        {
            // arrange
            var expectedException = default(ArgumentException);
            var primaryProperty = new Mock<IPropertyInfo>();
            primaryProperty.Setup(s => s.Name).Returns("PrimaryProperty");
            primaryProperty.Setup(s => s.Type).Returns(typeof(DateTime));
            
            var wsMock = new Mock<IWorkSchedule>();
            var newRule = new TopOfTheHourRule(primaryProperty.Object);
            var ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { primaryProperty.Object, wsMock.Object.StartTime } });
            var ruleInterface = (IBusinessRule)newRule;

            
            // act
            try
            {
                ruleInterface.Execute(ruleContext);
            }
            catch (ArgumentException ex)
            {
                expectedException = ex;
            }
            
            // assert
            Assert.IsNotNull(expectedException, ValidationMessages.ArgumentExceptionIsExpected);
            Assert.AreEqual(expectedException.Message, ValidationMessages.PropertyValueNotSet);
        }
        public void PassesWhen_PrimaryPropertyValueIsOnTopOfAnHour()
        {
            // arrange
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var wsMock = new Mock<IWorkSchedule>();
            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014, 4, 1, 10, 0, 0));

            var newRule = new TopOfTheHourRule(startTimeProperty.Object);
            var ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime } });
            var ruleInterface = (IBusinessRule)newRule;

            // act
            ruleInterface.Execute(ruleContext);
            // assert
            Assert.IsNull(ruleContext.Results.SingleOrDefault(_ => _.Description == ValidationMessages.NotOnTopOfAnHour.FormatMessage(startTimeProperty.Object.Name)));
        }
        public void PassesWhen_StartTimeIsBeforeEndTime()
        {
            //arrange
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var endTimeProperty = new Mock<IPropertyInfo>();
            endTimeProperty.Setup(s => s.Name).Returns("EndTime");
            endTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));


            var wsMock = new Mock<IWorkSchedule>();
            wsMock.SetupProperty<DateTime>(ws => ws.StartTime, new DateTime(2014,4,1,10,0,0));
            wsMock.SetupProperty<DateTime>(ws => ws.EndTime, new DateTime(2014, 4, 1, 11, 0, 0));

            var innerRule1 = new TopOfTheHourRule(startTimeProperty.Object);
            var innerRule2 = new TopOfTheHourRule(endTimeProperty.Object);
            var newRule = new TimeRangeRule(startTimeProperty.Object, endTimeProperty.Object, innerRule1, innerRule2);
            var ruleContext = new RuleContext(null, newRule, wsMock.Object, new Dictionary<IPropertyInfo, object>() { { startTimeProperty.Object, wsMock.Object.StartTime }, {endTimeProperty.Object, wsMock.Object.EndTime} });
            var ruleInterface = (IBusinessRule)newRule;

            //act
            ruleInterface.Execute(ruleContext);

            //assert

            Assert.IsNull(ruleContext.Results.SingleOrDefault(_ => _.Description == ValidationMessages.InvalidTimeRange));

           
        }
        public void PassesWhen_EndTimePropertyIsValidType()
        {
            //arrange
            var expectedException = default(ArgumentException);
            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var endTimeProperty = new Mock<IPropertyInfo>();
            endTimeProperty.Setup(s => s.Name).Returns("endTime");
            endTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));
            //act
            var innerRule1 = new TopOfTheHourRule(startTimeProperty.Object);
            var innerRule2 = new TopOfTheHourRule(endTimeProperty.Object);
            var newRule = new TimeRangeRule(startTimeProperty.Object, endTimeProperty.Object, innerRule1, innerRule2);

            //assert
            Assert.IsNotNull(newRule);
        }
        public void PassesWhen_EndTimePropertyIsSupplied()
        {
            //arrange

            var startTimeProperty = new Mock<IPropertyInfo>();
            startTimeProperty.Setup(s => s.Name).Returns("StartTime");
            startTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            var endTimeProperty = new Mock<IPropertyInfo>();
            endTimeProperty.Setup(s => s.Name).Returns("endTime");
            endTimeProperty.Setup(s => s.Type).Returns(typeof(DateTime));

            //act
            var innerRule1 = new TopOfTheHourRule(startTimeProperty.Object);
            var innerRule2 = new TopOfTheHourRule(endTimeProperty.Object);
            var newRule = new TimeRangeRule(startTimeProperty.Object, endTimeProperty.Object, innerRule1, innerRule2);

            //asset
            Assert.IsNotNull(newRule);
        }