コード例 #1
0
        public void Create_Test_InvalidFormData()
        {
            var mockRepo         = new Mock <DevCmsDb>();
            var emailServiceMock = new Mock <EmailService>(mockRepo.Object);

            var controller = new NotificationController(mockRepo.Object, emailServiceMock.Object);

            var result = controller.Create(null);

            Assert.Equal("Error. Incorrect form data.", result);

            result = controller.Create(new Notification {
                Email = "test", Name = ""
            });
            Assert.Equal("Error. Incorrect form data.", result);
        }
コード例 #2
0
        public void Create_Test()
        {
            var mockRepo = new Mock <DevCmsDb>();

            mockRepo.SetupDbSetMock(db => db.Notifications, new List <Notification>());
            var emailServiceMock = new Mock <EmailService>(mockRepo.Object);

            var controller = new NotificationController(mockRepo.Object, emailServiceMock.Object);

            var model = new Notification
            {
                Email   = "test",
                Name    = "name",
                Phone   = "",
                Message = "message"
            };

            Assert.Equal(0, mockRepo.Object.Notifications.Count());

            var result = controller.Create(model);

            Assert.Equal("success", result);

            mockRepo.Verify(db => db.SaveChanges(), Times.Once());
            emailServiceMock.Verify(s => s.SendEmail(It.IsAny <Notification>()), Times.Once());

            Assert.Equal(1, mockRepo.Object.Notifications.Count());
            Assert.Equal("test", mockRepo.Object.Notifications.First().Email);
            Assert.Equal("name", mockRepo.Object.Notifications.First().Name);
            Assert.Equal("message", mockRepo.Object.Notifications.First().Message);
        }
コード例 #3
0
        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            if (RecipientsListBox.SelectedItems.Count == 0)
            {
                return;
            }
            int           id = _notificationController.GetAll().Count;
            Notification  newNotification    = new Notification(id, NotificationTitle, NotificationContent, DateTime.Now);
            List <string> selectedRecipients = RecipientsListBox.SelectedItems.Cast <string>().ToList();

            newNotification.FillRecipients(selectedRecipients);
            _notificationController.Create(newNotification);
            _parent.UpdateTable();
            Close();
        }
コード例 #4
0
        public async Task NotificationRule_Create_Invalid_Notification_Test()
        {
            //Arrange
            var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.Name, "example name"),
                new Claim(ClaimTypes.NameIdentifier, "1"),
                new Claim("custom-claim", "example claim value"),
            }, "mock"));

            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase(databaseName: "CommerceTestDB");
            var _dbContext = new ApplicationDbContext(optionsBuilder.Options);

            var controller = new NotificationController(_dbContext);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = user
                }
            };

            var notificationRule = new Notification_Rule();

            notificationRule.Type      = "Deposit";
            notificationRule.Condition = "NA";
            notificationRule.Value     = -1;

            //Act
            var result = await controller.Create(notificationRule);

            //Assert
            Assert.NotNull(result);
        }