public RegisterContextHelper()
        {
            var o = new DbContextOptionsBuilder <NotificationContext>();

            o.UseSqlite(m_dataSource);

            using (var ctx = new NotificationContext(o.Options))
            {
                ctx.Database.Migrate();

                if (!ctx.Users.Any())
                {
                    ctx.Notifications.AddRange(NotificationFaker.Generate(50));

                    //создадим тестового пользователя номер 1. Он будет владельцем комнаты номер 1 и ему пренадлежит сообщение номер 1.
                    User user = ctx.Users.Add(new Models.User()
                    {
                        Id    = "5BE86359-073C-434B-AD2D-A3932222DABE",
                        Name  = "Тестовый пользователь номер 1",
                        Email = "*****@*****.**"
                    }).Entity;

                    user.Notifications = new List <Models.Notification>();

                    List <Models.Notification> notifications = new List <Models.Notification>(NotificationFaker.Generate(25));
                    foreach (Models.Notification notification in notifications)
                    {
                        notification.UserId = user.Id;
                        user.Notifications.Add(notification);
                    }
                    user.UserSubscriptions = new List <UserSubscription>();

                    List <UserSubscription> userSubscriptions = new List <UserSubscription>(UserSubscriptionFaker.Generate(6));
                    foreach (UserSubscription userSubscription in userSubscriptions)
                    {
                        user.UserSubscriptions.Add(userSubscription);
                    }

                    ctx.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        public void Setup()
        {
            Context.Notifications.AddRange(NotificationFaker.Generate());
            Context.SaveChanges();
            m_notificationService = new NotificationService(Context, Mapper);



            Mock <IOptionsMonitor <SenderConfig> > mockSenderConfig = new Mock <IOptionsMonitor <SenderConfig> >();

            mockSenderConfig.Setup(x => x.CurrentValue).Returns(new SenderConfig {
                Email = m_eamil, Name = m_name, Password = m_password
            });

            Mock <IEmailSenderService> mockSenderService = new Mock <IEmailSenderService>();

            mockSenderService.Setup(x => x.SendEmailAsync(It.IsAny <SendEmailRequest>(), It.Is <SenderConfig>((config) => config.Email == m_eamil &&
                                                                                                              config.Name == m_name &&
                                                                                                              config.Password == m_password))).Returns(Task.FromResult(false));

            m_emailNotificationService = new EmailNotificationService(Context, mockSenderService.Object, Mapper, mockSenderConfig.Object);
        }