Example #1
0
        public static void Initialize(TestContext _)
        {
            var options = new DbContextOptionsBuilder <MailingApiContext>().UseInMemoryDatabase(databaseName: "BusinessLayerTests")
                          .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)).Options;
            var context         = new MailingApiContext(options);
            var owner           = DataLayerTestHelper.CreateMailUser("name", "password");
            var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider();
            var factory         = serviceProvider.GetService <ILoggerFactory>();

            _data     = new DataLayer(context, factory);
            _buisness = new BusinessLayer(_data);
            _data.InsertUser(owner);
            var groups = new List <MailingGroup>()
            {
                DataLayerTestHelper.CreateMailingGroup("name1", owner.Id),
                DataLayerTestHelper.CreateMailingGroup("name2", owner.Id),
                DataLayerTestHelper.CreateMailingGroup("nameToDelete3", owner.Id),
                DataLayerTestHelper.CreateMailingGroup("nameToDelete4", owner.Id),
            };

            foreach (var g in groups)
            {
                var consumers = new List <MailConsumer>()
                {
                    DataLayerTestHelper.CreateMailConsumer("*****@*****.**", g.Id),
                };
                _data.InsertGroup(g, consumers);
            }
        }
Example #2
0
        public static void Initialize(TestContext _)
        {
            var options = new DbContextOptionsBuilder <MailingApiContext>().UseInMemoryDatabase(databaseName: "DataLayerTests")
                          .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)).Options;

            _context = new MailingApiContext(options);
            var serviceProvider = new ServiceCollection().AddLogging().BuildServiceProvider();
            var factory         = serviceProvider.GetService <ILoggerFactory>();

            _data = new DataLayer(_context, factory);
            var owner = DataLayerTestHelper.CreateMailUser("name", "password");

            _context.GroupOwners.Add(owner);
            _context.SaveChanges();
            var groups = new List <MailingGroup>()
            {
                DataLayerTestHelper.CreateMailingGroup("name1", owner.Id),
                DataLayerTestHelper.CreateMailingGroup("name2", owner.Id),
                DataLayerTestHelper.CreateMailingGroup("nameToDelete3", owner.Id),
                DataLayerTestHelper.CreateMailingGroup("nameToDelete4", owner.Id),
            };

            _context.Groups.AddRange(groups);
            _context.SaveChanges();
            var consumerList = new List <MailConsumer>();

            foreach (var g in groups)
            {
                consumerList.Add(DataLayerTestHelper.CreateMailConsumer($"name{g.Id}", g.Id));
            }
            _context.Consumers.AddRange(consumerList);
            _context.SaveChanges();
        }