コード例 #1
0
        public async void Details_ReturnsNotFound()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "DetailsNotFoundSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Kenni",
                LastName    = "Bobber",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 1
            });
            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Nidolaj",
                LastName    = "Molle",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 2
            });
            context.SaveChanges();
            SubscriberController controller = new SubscriberController(context);

            // Act
            IActionResult result = await controller.Details(6);

            Assert.IsType <NotFoundResult>(result);
        }
コード例 #2
0
ファイル: SeedDB.cs プロジェクト: jimm1034/VitecPlusAPI
        public static void Seed(VitecContext context)
        {
            if (context.Products.Any())
            {
                return;
            }

            Array products = new Product[3]
            {
                new Product
                {
                    Name        = "CD Ord",
                    Price       = 299.95,
                    Description = "Et program som hjælper dig, som er ordblind."
                },
                new Product
                {
                    Name        = "CD Ord - Premium",
                    Price       = 599.95,
                    Description = "Et produkt som hjælper dig, der har brug for hjælp."
                },
                new Product
                {
                    Name        = "Into Words",
                    Price       = 99.95,
                    Description = "Frihed til at læse, skrive og søge viden. For alle."
                }
            };

            //Array users = new VitecUser[3]
            //{
            //    new VitecUser
            //    {
            //        FirstMidName = "Debra",
            //        LastName = "Bobdóttir"

            //    },
            //    new VitecUser
            //    {
            //        FirstMidName = "Line",
            //        LastName = "Debradóttir"
            //    },
            //    new VitecUser
            //    {
            //        FirstMidName = "UnknownHacker",
            //        LastName = "RemoveHim!"
            //    }
            //};
            foreach (Product p in products)
            {
                context.Products.Add(p);
            }
            //foreach (VitecUser u in users)
            //{
            //    context.VitecUsers.Add(u);
            //}

            context.SaveChanges();
        }
コード例 #3
0
 public UsersController(VitecContext context)
 {
     _context = context;
     if (context.VitecUsers.Count() == 0)
     {
         SeedData.Seed(context);
     }
 }
コード例 #4
0
 public ProductsController(VitecContext context)
 {
     _context = context;
     if (context.Products.Count() == 0)
     {
         SeedData.Seed(context);
     }
 }
コード例 #5
0
 public ProductController(ILogger <ProductController> logger, VitecContext context)
 {
     _logger                 = logger;
     _context                = context;
     _productRepository      = new ProductRepository(_connectionString + "/api/products");
     _subscriptionRepository = new SubscriptionRepository(_connectionString + "/api/subscriptions");
     _priceRepository        = new PriceRepository(_connectionString + "/api/prices");
 }
コード例 #6
0
ファイル: SeedDB.cs プロジェクト: jimm1034/VitecPlusAPI
        public static async Task InitializeAsync(IServiceProvider serviceProvider, string testUserPw)
        {
            using (var context = new VitecContext(
                       serviceProvider.GetRequiredService <DbContextOptions <VitecContext> >()))
            {
                // For sample purposes seed both with the same password.
                // Password is set with the following:
                // dotnet user-secrets set SeedUserPW <pw>
                // The admin user can do anything

                var adminID = await EnsureUser(serviceProvider, testUserPw, "*****@*****.**");
                await EnsureRole(serviceProvider, adminID, Constants.AdministratorsRole);

                // allowed user can create and edit contacts that they create
                var managerID = await EnsureUser(serviceProvider, testUserPw, "*****@*****.**");
                await EnsureRole(serviceProvider, managerID, Constants.ManagersRole);

                SeedDBAsync(context, adminID);
            }
        }
コード例 #7
0
        public async void Details_ReturnsRequested_Model()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "DetailsSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Kenni",
                LastName    = "Bobber",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 1
            });
            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Nidolaj",
                LastName    = "Molle",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**",
                ID          = 2
            });
            context.SaveChanges();
            SubscriberController controller = new SubscriberController(context);

            // Act
            IActionResult result = await controller.Details(2);

            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            // Assert that it's a subscriber as model
            Subscriber sub = Assert.IsAssignableFrom <Subscriber>(viewResult.ViewData.Model);

            // Assert that it's the correct subsriber
            Assert.Equal("Nidolaj", sub.FirstName);
        }
コード例 #8
0
        public async void Index_ReturnsAViewResult_WithListOfSubscribers()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "IndexSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Kenni",
                LastName    = "Bobber",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**"
            });
            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Nidolaj",
                LastName    = "Molle",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**"
            });
            context.SaveChanges();

            SubscriberController controller = new SubscriberController(context);

            // Act
            IActionResult result = await controller.Index();

            // Assert that it's a viewResult
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            // Assert that the model returned is a list of subscribers
            List <Subscriber> model = Assert.IsAssignableFrom <List <Subscriber> >(viewResult.ViewData.Model);

            // Asser that there's 2 subscribers
            Assert.Equal(2, model.Count);
        }
コード例 #9
0
ファイル: SeedDB.cs プロジェクト: jimm1034/VitecPlusAPI
        public static async Task SeedDBAsync(VitecContext context, string adminID)
        {
            if (context.VitecUsers.Any())
            {
                return;   // DB has been seeded
            }
            //if (ModelState.IsValid)
            //{
            //    var user = new IdentityUser { UserName = model.Username };
            //    var result = await _userManager.CreateAsync(user, model.Password);

            //}
            //context.VitecUsers.AddRange(
            //    new VitecUser
            //    {
            //        OwnerID = adminID,
            //        FirstMidName = "Jimmy",
            //        LastName = "Henriksen",
            //        Email = "*****@*****.**",
            //        PasswordProvided = "Raprap_1"
            //    }
            // );

            VitecUser u = new VitecUser()
            {
                OwnerID          = adminID,
                FirstMidName     = "Jimmy",
                LastName         = "Henriksen",
                Email            = "*****@*****.**",
                PasswordProvided = "Raprap_1"
            };

            //var user = new IdentityUser { UserName = u.Email };
            //var result = await _userManager.CreateAsync(user, u.PasswordHash);
            context.SaveChanges();
        }
コード例 #10
0
 public ProductController(VitecContext context)
 {
     _context = context;
 }
コード例 #11
0
 public EmployeeController(VitecContext context)
 {
     _context = context;
 }
コード例 #12
0
 public SubscriberController(VitecContext context)
 {
     _context = context;
 }
コード例 #13
0
 public HomeController(ILogger <HomeController> logger, VitecContext context, IHttpClientFactory clientFactory)
 {
     _logger    = logger;
     _context   = context;
     _apiHelper = new APIHelper(clientFactory);
 }
コード例 #14
0
        public static void Initialize(VitecContext context)
        {
            context.Database.EnsureCreated();

            if (context.PaymentInterval.Any())
            {
                return; // database has been seeded
            }

            var paymentIntervals = new PaymentInterval[]
            {
                new PaymentInterval {
                    Interval = new TimeSpan(30), Discount = 0
                },
                new PaymentInterval {
                    Interval = new TimeSpan(90), Discount = 2.5
                },
                new PaymentInterval {
                    Interval = new TimeSpan(180), Discount = 5
                },
                new PaymentInterval {
                    Interval = new TimeSpan(360), Discount = 7.5
                }
            };

            foreach (PaymentInterval p in paymentIntervals)
            {
                context.PaymentInterval.Add(p);
            }

            context.SaveChanges();

            //Look for any subscribers


            var subscribers = new Subscriber[]
            {
                new Subscriber {
                    FirstName = "Victor", LastName = "West-Larsen", Email = "*****@*****.**", PhoneNumber = "12345678", Active = false
                },
                new Subscriber {
                    FirstName = "Kenni", LastName = "Holm", Email = "*****@*****.**", PhoneNumber = "11223344", Active = true
                },
                new Subscriber {
                    FirstName = "Nikolaj", LastName = "Lauridsen", Email = "*****@*****.**", PhoneNumber = "12312312", Active = true
                },
                new Subscriber {
                    FirstName = "Kasper", LastName = "Hoffmann", Email = "*****@*****.**", PhoneNumber = "12341234", Active = false
                }
            };

            foreach (Subscriber s in subscribers)
            {
                context.Subscriber.Add(s);
            }
            context.SaveChanges();

            var products = new Product[]
            {
                new Product {
                    Name = "IntoWords", Description = "Digitalt værktøj der hjælper dig med at skrive og læse, på både bærbare computere, tablets og mobil telefoner", Price = 30
                },
                new Product {
                    Name = "C-Pen", Description = "Skan ord eller sætninger ind på computeren så de kan læses op", Price = 20
                },
                new Product {
                    Name = "Grammateket", Description = "Tjekker din tekst for fejl i stavning, grammatik og kommatering", Price = 25
                },
                new Product {
                    Name = "Matematikleg Flex", Description = "Hjælp til elever med matematikvanskeligheder", Price = 40
                },
                new Product {
                    Name = "MiVo", Description = "Træner brugen af skrivehjælpen i CD-ORD og IntoWords  ", Price = 15
                }
            };

            foreach (Product p in products)
            {
                context.Product.Add(p);
            }
            context.SaveChanges();

            var subscriberProducts = new SubscriberProduct[]
            {
                new SubscriberProduct {
                    SubscribtionStart = DateTime.Now, SubscribtionEnd = Convert.ToDateTime("10,10,2020"),
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 0.0).ID,
                    ProductID         = products.Single(p => p.Name == "MiVo").ID,
                    SubscriberID      = subscribers.Single(s => s.Email == "*****@*****.**").ID
                },

                new SubscriberProduct {
                    SubscribtionStart = DateTime.Now, SubscribtionEnd = Convert.ToDateTime("10,12,2022"),
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 2.5).ID,
                    ProductID         = products.Single(p => p.Name == "IntoWords").ID,
                    SubscriberID      = subscribers.Single(s => s.Email == "*****@*****.**").ID
                }
            };

            foreach (SubscriberProduct s in subscriberProducts)
            {
                context.SubscriberProduct.Add(s);
            }
            context.SaveChanges();


            var productPaymentIntervals = new ProductPaymentInterval[]
            {
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "IntoWords").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "IntoWords").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 2.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "IntoWords").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 5.0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "IntoWords").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 7.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "C-Pen").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "C-Pen").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 2.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "C-Pen").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 5.0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "C-Pen").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 7.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Grammateket").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Grammateket").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 2.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Grammateket").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 5.0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Grammateket").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 7.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Matematikleg Flex").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Matematikleg Flex").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 2.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Matematikleg Flex").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 5.0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "Matematikleg Flex").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 7.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "MiVo").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "MiVo").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 2.5).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "MiVo").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 5.0).ID
                },
                new ProductPaymentInterval {
                    ProductID         = products.Single(p => p.Name == "MiVo").ID,
                    PaymentIntervalID = paymentIntervals.Single(p => p.Discount == 7.5).ID
                },
            };

            foreach (ProductPaymentInterval p in productPaymentIntervals)
            {
                context.ProductPaymentInterval.Add(p);
            }
            context.SaveChanges();
        }
コード例 #15
0
 public UserService(VitecContext context, UserManager <WebUser> userManager, SignInManager <WebUser> signInManager)
 {
     _context       = context;
     _userManager   = userManager;
     _signInManager = signInManager;
 }
コード例 #16
0
 public ProductController(VitecContext context, IHttpClientFactory clientFactory)
 {
     _context   = context;
     _apiHelper = new Helpers.APIHelper(clientFactory);
 }
コード例 #17
0
 public CampaignsController(VitecContext context)
 {
     _context = context;
 }
コード例 #18
0
        public HomeController(ILogger <HomeController> logger, IUserService userService, VitecContext context)
        {
            _logger = logger;

            /*if (!context.Users.Any())
             * {
             *  userService.CreateNewUser("Doduchis", "a", "Emilie", "Holst", "Kohaven 20", 1699);
             *  userService.CreateNewUser("Forculd", "a", "Nina", "Jepsen", "Grønvejen 46", 3210);
             *  userService.CreateNewUser("MarBri", "a", "Marianne", "Briansen", "Maevej 41", 5690);
             * }*/
        }