Пример #1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(EventReq))
            {
                return(_defaultReq);
            }
            ValueProviderResult valFrom = bindingContext.ValueProvider.GetValue("from");

            if (valFrom == null)
            {
                return(_defaultReq);
            }
            var valueFrom             = valFrom.AttemptedValue ?? _defaultReq.From;
            ValueProviderResult valTo = bindingContext.ValueProvider.GetValue("to");
            string valueTo            = String.Empty;

            if (valTo == null)

            {
                valueTo = _defaultReq.To;
            }
            else
            {
                valueTo = valTo.AttemptedValue;
            }

            // if from tom Time is given in sortable format with T in middle remove it.
            var valueReq = new EventReq()
            {
                To = valueTo.Replace("T", String.Empty), From = valueFrom.Replace("T", String.Empty)
            };

            return(valueReq);
        }
Пример #2
0
 public EventReqModelBinder()
 {
     _defaultReq = new EventReq()
     {
         To = DateTime.Now.ToString(Global_Const.DATE_FORMAT), From = DateTime.Now.AddHours(-6).ToString(Global_Const.DATE_FORMAT)
     };
 }
        public void Index()
        {
            // Arrange
            EventsController controller = new EventsController();

            var eventReq = new EventReq {From = "20130613154515", To = "20130614163022"};
              //  var eventReq = new EventReq {From = "20130618202500", To = "20130619182551"};
            // TODO this test need better DTO that gives some data. Should SearchTerm be injected ?
              //  var eventReq = new EventReq {  };
             //   var eventService = new EventService { Repository = TestContainer.Resolve<IEventRepository>() };

            // Act
            ViewResult result = controller.Index(eventReq) as ViewResult;

            // Assert

            Assert.AreEqual("Here is a list of all filtered events from all server nodes.", result.ViewBag.Message);
            Assert.IsNotNull(result, "Response from Eventservice is null");
            Assert.IsInstanceOfType(result.Model, typeof(IEventRecListViewModel), "Returns the wrong ViewModel");
            int evRlCount = ((IEventRecListViewModel)result.Model).EventList.Count;
            Assert.IsTrue(evRlCount > 0, "There should be more then 0 item in the event test list");
              //  Assert.IsTrue(evRlCount == 20, "There should be 20 item in the event test list");
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelType != typeof(EventReq))
            {
                return _defaultReq;
            }
            ValueProviderResult valFrom = bindingContext.ValueProvider.GetValue("from");
            if (valFrom == null)
            {
                return _defaultReq;
            }
            var valueFrom = valFrom.AttemptedValue ?? _defaultReq.From;
            ValueProviderResult valTo = bindingContext.ValueProvider.GetValue("to");
            string valueTo = String.Empty;
            if (valTo == null)

            {
                valueTo = _defaultReq.To;
            }
            else
            {
                valueTo = valTo.AttemptedValue;
            }

            // if from tom Time is given in sortable format with T in middle remove it.
            var valueReq = new EventReq() { To = valueTo.Replace("T", String.Empty), From = valueFrom.Replace("T", String.Empty) };
            return valueReq;
        }
 public EventReqModelBinder()
 {
     _defaultReq = new EventReq() { To = DateTime.Now.ToString(Global_Const.DATE_FORMAT), From = DateTime.Now.AddHours(-6).ToString(Global_Const.DATE_FORMAT) };
 }