示例#1
0
        public async void can_dismiss_notification()
        {
            var    options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase(databaseName: "NotificationTest1").Options;
            string userId  = "1";

            using (var context = new DatabaseContext(options))
            {
                // Act
                var controller = new NotificationsController(context);
                AddUserClaim(controller, userId);
                context.Users.Add(new User()
                {
                    FacebookId = userId
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "1", MessageType = 1, Id = 1, EventId = 1
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "1", MessageType = 1, Id = 2, EventId = 1
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "2", MessageType = 1, Id = 3, EventId = 2
                });
                context.SaveChanges();
                Assert.Equal(3, context.Notifications.Count());
                Assert.False(context.Notifications.Where(n => n.Id == 1).Single().IsDismissed);

                await controller.DismissNotification(1);

                // Assert
                Assert.Equal(3, context.Notifications.Count());
                Assert.True(context.Notifications.Where(n => n.Id == 1).Single().IsDismissed);
            }
        }