public void GetMessagesMassageLengthTest() { var mockService = new MockTwitterService(); var controller = new MessageController(mockService); var m = new MesageSubmitModel { //257 symbols, allowed 256 Message = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has surv", UserName = "******" }; controller.Configuration = new HttpConfiguration(); controller.Validate(m); var result = controller.AddMessage(m); Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult)); var item = ((InvalidModelStateResult)result).ModelState; // Assert Assert.IsNotNull(item); Assert.IsNotNull(item["Message"]); Assert.IsTrue(item["Message"].Errors.Count > 0); }
public void GetCommentsOkTest() { var mockService = new MockTwitterService(); var controller = new MessageController(mockService); var result = controller.GetComments(1); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <List <MessageModel> >)); var item = ((OkNegotiatedContentResult <List <MessageModel> >)result).Content; // Assert Assert.IsNotNull(item); Assert.IsTrue(item.Count() > 0); }
public void GetCommentsBadParamTest() { var mockService = new MockTwitterService(); var controller = new MessageController(mockService); var result = controller.GetComments(-1); Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult)); var item = ((InvalidModelStateResult)result).ModelState; // Assert Assert.IsNotNull(item); Assert.IsNotNull(item["MessageId"]); Assert.IsTrue(item["MessageId"].Errors.Count > 0); }
public void SetUp() { _sessionIds = new List <string> (); _slot1 = new Slot { StartTime = new DateTime(2014, 10, 1, 8, 0, 0), EndTime = new DateTime(2014, 10, 1, 8, 50, 0), SessionIds = _sessionIds }; _slot2 = new Slot { StartTime = new DateTime(2014, 10, 1, 9, 0, 0), EndTime = new DateTime(2014, 10, 1, 9, 50, 0), SessionIds = _sessionIds }; _days = new List <Day> { new Day { Date = new DateTime(2014, 10, 1), Slots = new List <Slot> { _slot1, _slot2 } } }; _schedule = new Schedule { Days = _days }; _appConfig = new AppConfig(); _repository = new MockRepository { GetDaysResult = _days, GetScheduleResult = _schedule, GetAppConfigResult = _appConfig }; _sessions = new List <Session> (); _repository.GetSessionsResults [_sessionIds] = _sessions; _timeService = new MockTimeService(); _twitterService = new MockTwitterService(); _sut = new HomeViewModel(_repository, _timeService, _twitterService); }
public void SetUp () { _sessionIds = new List<string> (); _slot1 = new Slot { StartTime = new DateTime (2014, 10, 1, 8, 0, 0), EndTime = new DateTime (2014, 10, 1, 8, 50, 0), SessionIds = _sessionIds }; _slot2 = new Slot { StartTime = new DateTime (2014, 10, 1, 9, 0, 0), EndTime = new DateTime (2014, 10, 1, 9, 50, 0), SessionIds = _sessionIds }; _days = new List<Day> { new Day { Date = new DateTime(2014, 10, 1), Slots = new List<Slot> { _slot1, _slot2 } } }; _schedule = new Schedule { Days = _days }; _appConfig = new AppConfig (); _repository = new MockRepository { GetDaysResult = _days, GetScheduleResult = _schedule, GetAppConfigResult = _appConfig }; _sessions = new List<Session> (); _repository.GetSessionsResults [_sessionIds] = _sessions; _timeService = new MockTimeService (); _twitterService = new MockTwitterService (); _sut = new HomeViewModel (_repository, _timeService, _twitterService); }
public void AddMessageOkTest() { var mockService = new MockTwitterService(); var controller = new MessageController(mockService); var m = new MesageSubmitModel { Message = "test", UserName = "******" }; var result = controller.AddMessage(m); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <int>)); var item = ((OkNegotiatedContentResult <int>)result).Content; // Assert Assert.IsNotNull(item); Assert.IsTrue(item > 0); }
public void GetMessagesUserNameLengthTest() { var mockService = new MockTwitterService(); var controller = new MessageController(mockService); var m = new MesageSubmitModel { Message = "test", UserName = "******" //52 symbols, alowed 50 }; controller.Configuration = new HttpConfiguration(); controller.Validate(m); var result = controller.AddMessage(m); Assert.IsInstanceOfType(result, typeof(InvalidModelStateResult)); var item = ((InvalidModelStateResult)result).ModelState; // Assert Assert.IsNotNull(item); Assert.IsNotNull(item["UserName"]); Assert.IsTrue(item["UserName"].Errors.Count > 0); }
public static ITwitterService GetService(UserToken account) { lock (_lockFlag) { if (_services == null) _services = new Dictionary<string, ITwitterService>(); } if (account == null || account.Key == null) return null; ITwitterService srv; lock (_lockFlag) { if (_services.ContainsKey(account.Key)) return _services[account.Key]; if (TestSession) srv = new MockTwitterService(); else { var tempSrv = new TwitterService(); tempSrv.AuthenticateWith(SensitiveData.ConsumerToken, SensitiveData.ConsumerSecret, account.Key, account.Secret); srv = tempSrv; } try { _services.Add(account.Key, srv); } catch { // Again, this sometimes gives some weird exceptions. Investigate! } } return srv; }