Exemplo n.º 1
0
        public void GetByUserId_UnknownIntPassed_ReturnsNotFoundResult()
        {
            //Arrange
            var mockService = new Mock <INotificationsService>();
            var mockLogger  = new Mock <ILogger <NotificationsController> >();
            var userId      = 0;

            mockService.Setup(s => s.GetNotificationsByUser(userId))
            .ReturnsAsync(GetUserTestNotifications(userId));
            var controller = new NotificationsController(mockService.Object, mockLogger.Object);
            // Act
            var notFoundResult = controller.Get(userId);

            // Assert
            Assert.IsType <NotFoundResult>(notFoundResult.Result);
        }
Exemplo n.º 2
0
        public async Task Get_WhenCalled_ReturnsOkResult()
        {
            //Arrange
            var mockService = new Mock <INotificationsService>();
            var mockLogger  = new Mock <ILogger <NotificationsController> >();

            mockService.Setup(s => s.GetAllNotifications())
            .ReturnsAsync(GetTestNotifications());
            var controller = new NotificationsController(mockService.Object, mockLogger.Object);

            // Act
            //var result = await controller.Get();
            var okResult = await controller.Get();

            //Assert
            Assert.IsType <OkObjectResult>(okResult);
        }
        public void Get()
        {
            // Set up Prerequisites
            var controller = new NotificationsController();

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();


            // Act on Test
            var response      = controller.Get(1);
            var contentResult = response as HttpResponseMessage;

            // Assert the result
            Assert.AreEqual(HttpStatusCode.OK, contentResult.StatusCode);
            List <Notification> notifications;

            Assert.IsTrue(response.TryGetContentValue <List <Notification> >(out notifications));
        }
Exemplo n.º 4
0
        public async Task Get_WhenCalled_ReturnsAllNotifications()
        {
            //Arrange
            var mockService = new Mock <INotificationsService>();
            var mockLogger  = new Mock <ILogger <NotificationsController> >();

            mockService.Setup(s => s.GetAllNotifications())
            .ReturnsAsync(GetTestNotifications());
            var controller = new NotificationsController(mockService.Object, mockLogger.Object);

            // Act
            var okResult = await controller.Get() as OkObjectResult;

            // Assert
            if (okResult != null)
            {
                var items = Assert.IsAssignableFrom <IReadOnlyCollection <NotificationModel> >(okResult.Value);
                Assert.Equal(2, items.Count);
            }
        }
Exemplo n.º 5
0
        public void Process(GetContentEditorWarningsArgs arguments)
        {
            Assert.ArgumentNotNull(arguments, "arguments");
            if (arguments.Item == null || Sitecore.Context.User.IsAdministrator)
            {
                return;
            }

            NotificationsController controller    = new NotificationsController();
            List <Notification>     notifications = notifications = controller.Get(arguments.Item, arguments.Item.HasPresentation());

            if (notifications.Count > 0)
            {
                for (int i = 0; i < notifications.Count; i++)
                {
                    var notification = arguments.Add();
                    notification.Text = notifications[i].Message;
                    notification.Icon = Constants.WarningIcon;
                    notification.AddOption(notifications[i].CommandDisplayName, notifications[i].Command);
                }
            }
        }