public async Task NotifiationListAsync() { // Arrange NotificationsController controller = new NotificationsController(); // Act ActionResult result = await controller.Index(); var viewResult = (ViewResult)result; var objlist = (List <Notification>)viewResult.Model; // Assert Assert.IsNotNull(result); Assert.AreEqual(2, objlist.Count); }
public void Index_Test() { var mockRepo = new Mock <DevCmsDb>(); mockRepo.SetupDbSetMock(db => db.Notifications, GetNotifications()); var controller = new NotificationsController(mockRepo.Object); var result = controller.Index(); var viewResult = Assert.IsType <ViewResult>(result); var resultModel = Assert.IsAssignableFrom <NotificationView>( viewResult.ViewData.Model); Assert.Single(resultModel.New); Assert.Single(resultModel.Viewed); Assert.Equal("test 2", resultModel.Viewed.First().Name); Assert.Equal("test 1", resultModel.New.First().Name); }
public void NotificationsListTest() { var account = TestHelper.GetTestAccount(); var user = TestHelper.GetAccountAdminUser(account.Id); var component = account.CreateRandomComponentControl(); var eventType = TestHelper.GetTestEventType(account.Id); var dispatcher = DispatcherHelper.GetDispatcherService(); var eventRequest = new SendEventRequest() { Token = account.GetCoreToken(), Data = new SendEventData() { ComponentId = component.Info.Id, TypeSystemName = eventType.SystemName, Category = EventCategory.ComponentEvent, Version = "1.2.3.4", JoinInterval = TimeSpan.FromSeconds(0).TotalSeconds } }; var sendEventResponse = dispatcher.SendEvent(eventRequest); Assert.True(sendEventResponse.Success); var eventId = sendEventResponse.Data.EventId; var dispatcherClient = TestHelper.GetDispatcherClient(); var response = dispatcherClient.CreateSubscription( account.Id, new CreateSubscriptionRequestData() { UserId = user.Id, Object = SubscriptionObject.ComponentType, ComponentTypeId = component.Type.Info.Id, Channel = SubscriptionChannel.Email }); var subscription = response.Data; Notification notification; using (var accountDbContext = account.CreateAccountDbContext()) { var repository = accountDbContext.GetNotificationRepository(); notification = new Notification() { Id = Guid.NewGuid(), CreationDate = DateTime.Now, EventId = eventId, SendDate = DateTime.Now.AddDays(1), Status = NotificationStatus.Sended, SubscriptionId = subscription.Id, Type = Core.AccountsDb.NotificationType.Email, UserId = user.Id, Address = "*****@*****.**" }; notification = repository.Add(notification); accountDbContext.SaveChanges(); } using (var controller = new NotificationsController(account.Id, user.Id)) { var result = (ViewResultBase)controller.Index(component.Info.Id); var model = (NotificationsListModel)result.Model; var item = model.Notifications.SingleOrDefault(t => t.Id == notification.Id); Assert.NotNull(item); Assert.Equal(notification.EventId, item.Event.Id); Assert.Equal(notification.Status, item.Status); Assert.Equal(notification.Type, item.Channel); Assert.Equal(notification.UserId, item.User.Id); } }