示例#1
0
        public void SendNotificationTest()
        {
            //Arrange
            new NotificationRepository(context).Save(new Notification()
            {
                NotificationId   = 777777,
                NotificationType = new NotificationTypeRepository(context).FindById(1),
                Contents         = "TEST",
                Status           = new StatusService(context).FindStatusByStatusId(1),
                CreatedFor       = new UserService(context).FindUserByEmail("*****@*****.**"),
                CreatedDateTime  = DateTime.Now,
            });

            var controller = new NotificationApiController
            {
                Request         = new HttpRequestMessage(),
                Configuration   = new HttpConfiguration(),
                CurrentUserName = "******"
            };

            //Act
            IHttpActionResult actionResult = controller.SendNotification("777777");

            //Assert
            Assert.IsNotNull(actionResult);
        }
示例#2
0
        public void GetNotifications_ContainsResult()
        {
            // Arrange
            new NotificationRepository(context).Save(new Notification()
            {
                NotificationId   = 999999,
                NotificationType = new NotificationTypeRepository(context).FindById(1),
                Contents         = "TEST",
                Status           = new StatusService(context).FindStatusByStatusId(1),
                CreatedFor       = new UserService(context).FindUserByEmail("*****@*****.**"),
                CreatedDateTime  = DateTime.Now,
            });
            var expected   = "TEST";
            var controller = new NotificationApiController
            {
                Request         = new HttpRequestMessage(),
                Configuration   = new HttpConfiguration(),
                CurrentUserName = "******"
            };

            // Act
            IHttpActionResult actionResult = controller.GetCurrentUser();
            var contentResult = actionResult as OkNegotiatedContentResult <IEnumerable <NotificationViewModel> >;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.IsTrue(contentResult.Content.Select(x => x.Contents).Contains(expected));
        }
        // --------------------------------- Utility ---------------------------------
        private (WebmailContext, NotificationApiController) CreateTestTools(string name)
        {
            var context    = CreateTestContext(name);
            var controller = new NotificationApiController(new SqlUserService(context, new SqlMessageService(context)))
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext {
                        User = new ClaimsPrincipal()
                    }
                }
            };

            return(context, controller);
        }
示例#4
0
        public void GetNotifications_NotFound()
        {
            // Arrange
            var controller = new NotificationApiController
            {
                Request         = new HttpRequestMessage(),
                Configuration   = new HttpConfiguration(),
                CurrentUserName = "******"
            };

            // Act
            IHttpActionResult actionResult = controller.GetCurrentUser();

            // Assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
        /// <summary>
        /// Setup the test
        /// </summary>
        public NotificationApiUnitTest()
        {
            DbContextOptions <DbAppContext> options      = new DbContextOptions <DbAppContext>();
            Mock <DbAppContext>             dbAppContext = new Mock <DbAppContext>(options);

            /*
             *
             * Here you will need to mock up the context.
             *
             * ItemType fakeItem = new ItemType(...);
             *
             * Mock<DbSet<ItemType>> mockList = MockDbSet.Create(fakeItem);
             *
             * dbAppContext.Setup(x => x.ModelEndpoint).Returns(mockItem.Object);
             *
             */

            NotificationApiService _service = new NotificationApiService(dbAppContext.Object);

            _NotificationApi = new NotificationApiController(_service);
        }