Esempio n. 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);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
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();
        }