Example #1
0
        public async void notification_can_be_accepted()
        {
            var    options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase(databaseName: "NotificationTest2").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 = 0, Id = 1, EventId = 1
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "1", MessageType = 0, Id = 2, EventId = 1
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "2", MessageType = 0, 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.AcceptNotification(1);

                // Assert
                Assert.Equal(4, context.Notifications.Count());
                Assert.True(context.Notifications.Any(n => n.MessageType == 1));
                Assert.True(context.Notifications.Any(n => n.SenderId == "1"));
            }
        }
Example #2
0
        public async void accept_notification_with_other_reciver_should_return_unauthorized()
        {
            var    options = new DbContextOptionsBuilder <DatabaseContext>().UseInMemoryDatabase(databaseName: "NotificationTest8").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 = "2", MessageType = 0, Id = 1, EventId = 1
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "1", MessageType = 0, Id = 2, EventId = 1
                });
                context.Notifications.Add(new Notification()
                {
                    ReceiverId = "2", MessageType = 0, Id = 3, EventId = 2
                });
                context.SaveChanges();
                Assert.Equal(3, context.Notifications.Count());
                Assert.False(context.Notifications.Where(n => n.Id == 1).Single().IsDismissed);

                var result = await controller.AcceptNotification(1);

                // Assert
                result.Should().BeOfType <UnauthorizedResult>();
            }
        }