コード例 #1
0
        public void GetAllCustomers_OnDifferentCustomers_ReturnsAJsonObject()
        {
            var options = new DbContextOptionsBuilder <HasserisDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert seed data into the database using one instance of the context
            ContactInfo contactInfo = new ContactInfo("*****@*****.**", "41126263");
            Address     address     = new Address("Brandstrupsgade 12", "9000", "Aalborg");


            using (var context = new HasserisDbContext(options, true))
            {
                context.Customers.Add(new Private("Christoffer", "Hollensen", address, contactInfo));
                context.Customers.Add(new Public(address, contactInfo, "Jammerbugt Kommune", "420133769"));
                context.Customers.Add(new Business(address, contactInfo, "Skovsgaard Hotel", "32217696969"));
                context.SaveChanges();
            }

            // Use a clean instance of the context to run the test
            using (var context = new HasserisDbContext(options, true))
            {
                var service = new CustomerController(context); // getting access to that database
                var result  = service.GetAllCustomers();

                //dynamic jsonResult = JsonConvert.DeserializeObject(result.ToString());                Console.WriteLine(result);
                dynamic json = JsonConvert.DeserializeObject(result);

                // we check that the type is of JArray
                Assert.AreEqual(typeof(Newtonsoft.Json.Linq.JArray), json.GetType());
                //Assert.IsInstanceOf<Newtonsoft.Json.Linq.JArray>( json.GetType() );
            }
        }
コード例 #2
0
        public void GetAllCustomers_OnSomeCustomers_IsNotNull()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <HasserisDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert seed data into the database using one instance of the context
            ContactInfo contactInfo = new ContactInfo("*****@*****.**", "41126263");
            Address     address     = new Address("Brandstrupsgade 12", "9000", "Aalborg");

            using (var context = new HasserisDbContext(options, true))
            {
                context.Customers.Add(new Private("Christoffer", "Hollensen", address, contactInfo));
                context.Customers.Add(new Public(address, contactInfo, "Jammerbugt Kommune", "420133769"));
                context.Customers.Add(new Business(address, contactInfo, "Skovsgaard Hotel", "32217696969"));
                context.SaveChanges();
            }

            // Act
            using (var context = new HasserisDbContext(options, true))
            {
                var service = new CustomerController(context); // getting access to that database
                var result  = service.GetAllCustomers();

                // Assert
                Assert.That(result, Is.Not.Null);
            }
        }
コード例 #3
0
        public void GetSpecificCustomer_OnExistingPrivateCustomerWithID1_ReturnsThatCustomer()
        {
            var options = new DbContextOptionsBuilder <HasserisDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert data into the database context
            ContactInfo contactInfo = new ContactInfo("*****@*****.**", "41126263");
            Address     address     = new Address("Brandstrupsgade 12", "9000", "Aalborg");

            using (var context = new HasserisDbContext(options, true))
            {
                context.Customers.Add(new Private("Christoffer", "Hollensen", address, contactInfo));
                context.Customers.Add(new Public(address, contactInfo, "Jammerbugt Kommune", "420133769"));
                context.Customers.Add(new Business(address, contactInfo, "Skovsgaard Hotel", "32217696969"));
                context.SaveChanges();
            }

            // Act
            // Use a clean instance of the context to run the test
            using (var context = new HasserisDbContext(options, true))
            {
                var customerController = new CustomerController(context); // getting access to that database

                // It selects from the same id so it will change the existing object in the database.
                var actual = customerController.GetSpecificCustomer(1);
                // Deserialzie our object into a Private type so we can access the properties such as Firstname and assert
                var actualObj = Newtonsoft.Json.JsonConvert.DeserializeObject <Private>(actual);

                // Without getting a dependency on the method that retrieves all we will do it manually again.
                Private customer = (Private)context.Customers.FirstOrDefault(c => c.ID == 1);

                Assert.That(actualObj.Firstname, Is.EqualTo("Christoffer"));
            }
        }
コード例 #4
0
        public void EditBusinessCustomer_OnBusinessCustomer_ReturnsAnEditedObject()
        {
            var options = new DbContextOptionsBuilder <HasserisDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert data into the database context
            ContactInfo contactInfo = new ContactInfo("*****@*****.**", "41126263");
            Address     address     = new Address("Brandstrupsgade 12", "9000", "Aalborg");

            using (var context = new HasserisDbContext(options, true))
            {
                context.Customers.Add(new Private("Christoffer", "Hollensen", address, contactInfo));
                context.Customers.Add(new Public(address, contactInfo, "Jammerbugt Kommune", "420133769"));
                context.Customers.Add(new Business(address, contactInfo, "Skovsgaard Hotel", "32217696969"));
                context.SaveChanges();
            }

            // Object to edit
            Business customerToEdit = new Business(address, contactInfo, "Fønix Hotel", "420133769");

            // We change the ID the customerToEdit object, so we get the same customer to edit
            customerToEdit.ID = 3;

            // Act
            // Use a clean instance of the context to run the test
            using (var context = new HasserisDbContext(options, true))
            {
                var customerController = new CustomerController(context); // getting access to that database

                // We have to serialize our object as JSON so it looks like the one being sent from our view component.
                string json = JsonConvert.SerializeObject(customerToEdit, Formatting.Indented);

                // It selects from the same id so it will change the existing object in the database.
                customerController.EditBusinessCustomer(json);

                // Without getting a dependency on the method that retrieves all we will do it manually again.
                Business customer = (Business)context.Customers.FirstOrDefault(c => c.ID == customerToEdit.ID);


                //dynamic jsonResult = JsonConvert.DeserializeObject("asd".ToString());

                // Get all customers to get reference to old one

                // Assert that the old one and the edited customer are the same by looking at the name cuz we edited that information
                Assert.That(customerToEdit.Name, Is.EqualTo("Fønix Hotel"));
            }
        }
コード例 #5
0
        public void DeleteCustomer_OnLegitCustomer_ReturnsNewDBMinusTheCustomer()
        {
            var options = new DbContextOptionsBuilder <HasserisDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert data into the database context
            ContactInfo contactInfo = new ContactInfo("*****@*****.**", "41126263");
            Address     address     = new Address("Brandstrupsgade 12", "9000", "Aalborg");

            using (var context = new HasserisDbContext(options, true))
            {
                context.Customers.Add(new Private("Christoffer", "Hollensen", address, contactInfo));
                context.Customers.Add(new Public(address, contactInfo, "Jammerbugt Kommune", "420133769"));
                context.Customers.Add(new Business(address, contactInfo, "Skovsgaard Hotel", "32217696969"));
                context.SaveChanges();
            }

            // Object to delete
            Private customerToDelete = new Private("Christoffer", "Hollensen", address, contactInfo);

            // We change the ID the customerToEdit object, so we get the same customer to delete
            customerToDelete.ID = 1;

            // Act
            // Use a clean instance of the context to run the test
            using (var context = new HasserisDbContext(options, true))
            {
                var customerController = new CustomerController(context); // getting access to that database

                // We have to serialize our object as JSON so it looks like the one being sent from our view component.
                string json = JsonConvert.SerializeObject(customerToDelete, Formatting.Indented);

                // It selects from the same id so it will change the existing object in the database.
                customerController.DeleteCustomer(json);

                // Without getting a dependency on the other method that retrieves all, we will do it manually again.
                Private customer = (Private)context.Customers.FirstOrDefault(c => c.ID == customerToDelete.ID);

                Assert.That(context.Customers.Contains(customer), Is.EqualTo(false));
            }
        }
コード例 #6
0
        public void AddPrivateCustomer_AddsLegitPrivateCustomer_ReturnsNewDBPlusCustomer()
        {
            var options = new DbContextOptionsBuilder <HasserisDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            // Insert data into the database context
            ContactInfo contactInfo = new ContactInfo("*****@*****.**", "41126263");
            Address     address     = new Address("Brandstrupsgade 12", "9000", "Aalborg");

            using (var context = new HasserisDbContext(options, true))
            {
                context.Customers.Add(new Private("Christoffer", "Hollensen", address, contactInfo));
                context.SaveChanges();
            }

            // Declare object to add
            Private customerToAdd = new Private("CholleAdded", "Holle", address, contactInfo);

            customerToAdd.ID = 2;

            // Serialize object so it can be used in our controller method
            var customerToAddJson = Newtonsoft.Json.JsonConvert.SerializeObject(customerToAdd);


            // Act
            // Use a clean instance of the context to run the test
            using (var context = new HasserisDbContext(options, true))
            {
                var customerController = new CustomerController(context); // getting access to that database

                // It selects from the same id so it will change the existing object in the database.
                customerController.AddPrivateCustomer(customerToAddJson);

                // Without getting a dependency on the method that retrieves all we will do it manually again.
                Private customer = (Private)context.Customers.FirstOrDefault(c => c.ID == 2);

                Assert.That(customer.Firstname, Is.EqualTo("CholleAdded"));
            }
        }
コード例 #7
0
 public VehicleController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #8
0
 public AuthenticationController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #9
0
ファイル: MitComponentController.cs プロジェクト: snuuby/P3-
 public MitComponentController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #10
0
 // Getting a reference to the model created by Entity Framework.
 public CalendarController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #11
0
        public SystemControl()
        {
            using (var db = new HasserisDbContext())
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();
                Employee tempEmployee = new Employee("Christopher", "Chollesen", "AdminPlus", 120, new ContactInfo("*****@*****.**", "41126263"), new Address("Sohngaardsholmparken", "9000", "Aalborg", "Til højre"));
                tempEmployee.AddLoginInfo("Cholle", "Cholle17");
                tempEmployee.IsAvailable = true;
                Employee tempEmployee_one = new Employee("Jakob", "Østenkjær", "AdminPlus", 150, new ContactInfo("*****@*****.**", "28943519"), new Address("Herningvej", "9220", "Aalborg", "Til højre"));
                tempEmployee_one.AddLoginInfo("Snuuby", "Jakob17");
                tempEmployee_one.IsAvailable = true;
                Employee tempEmployee_jakob = new Employee("Jacob", "Hasseris", "AdminPlus", 210, new ContactInfo("*****@*****.**", "30103010"), new Address("HasserisVej", "9220", "Aalborg", "Til højre"));
                tempEmployee_one.AddLoginInfo("Jacob", "Jacob17");
                tempEmployee_one.IsAvailable = true;
                db.Employees.Add(tempEmployee_jakob);
                Employee tempEmployee_two = new Employee("Kristian", "Eriksen", "AdminPlus", 150, new ContactInfo("*****@*****.**", "50734649"), new Address("Herningvej", "9220", "Aalborg", "Til højre"));
                tempEmployee_two.AddLoginInfo("Kristian", "Kristian17");
                tempEmployee_two.IsAvailable = true;

                Employee tempEmployee_three = new Employee("Daniel", "Heilskov", "AdminPlus", 150, new ContactInfo("*****@*****.**", "42438049"), new Address("Herningvej", "9220", "Aalborg", "Til højre"));
                tempEmployee_three.AddLoginInfo("Daniel", "Daniel17");
                tempEmployee_three.IsAvailable = true;

                Employee tempEmployee_four = new Employee("Simon", "Kanne", "AdminPlus", 150, new ContactInfo("*****@*****.**", "61466211"), new Address("Herningvej", "9220", "Aalborg", "Til højre"));
                tempEmployee_four.AddLoginInfo("Simon", "Simon17");
                tempEmployee_four.IsAvailable = true;

                Employee tempEmployee_five = new Employee("Mathias", "Møller", "AdminPlus", 150, new ContactInfo("*****@*****.**", "93958200"), new Address("Herningvej", "9220", "Aalborg", "Til højre"));
                tempEmployee_five.AddLoginInfo("Mathias", "Møller17");
                tempEmployee_five.IsAvailable = true;

                Employee tempEmployee_six = new Employee("Andreas", "Nichum", "Employee", 150, new ContactInfo("*****@*****.**", "24840884"), new Address("Herningvej", "9220", "Aalborg", "Til højre"));
                tempEmployee_six.AddLoginInfo("Andreas", "Andreas17");
                tempEmployee_six.IsAvailable = true;

                Customer tempCustomer     = new Private("Erik", "Larsen", new Address("Aalborg Vej", "9220", "Aalborg", "Første dør til højre"), new ContactInfo("*****@*****.**", "23131313"));
                Customer tempCustomer_one = new Public(new Address("Aalborghusvej", "9110", "Aalborg", "Anden dør"), new ContactInfo("*****@*****.**", "23131313"), "Hasseris Flytteforetning", "123123123123");

                Furniture tempFurniture = new Furniture("Sofa møbel", 10, "Sofa", 10);

                Equipment testEquipment     = new Vehicle("Stor lastbil", "Opel", "13131313");
                Equipment testEquipment_one = new Vehicle("Alimndelig bil", "Citroen", "13131313");
                testEquipment.IsAvailable     = true;
                testEquipment_one.IsAvailable = true;


                List <DateTime> testList = new List <DateTime>()
                {
                    new DateTime(2019, 11, 13), new DateTime(2019, 11, 14)
                };
                List <DateTime> testList_two = new List <DateTime>()
                {
                    new DateTime(2019, 11, 03), new DateTime(2019, 11, 04)
                };

                Delivery tempDelivery = new Delivery("Test Delivery", tempCustomer, new Address("Hasseris vej", "9220", "Aalborg", "Tredje dør til venstre"), 600, testList, "Giv erik noget", "28313131", "Foam", 5, 3);
                foreach (DateTime date in testList)
                {
                    PauseTimes temp = new PauseTimes();
                    temp.Date = date;
                    tempDelivery.PauseTimes.Add(temp);
                }

                Moving tempMoving = new Moving("Test Moving", tempCustomer_one, new Address("Kukux vej", "9000", "Aalborg", "første dør til venstre"), 700, testList_two, "Hjælp Lars med at flytte", "23131343", tempCustomer_one.Address, 5, true, 3);
                tempMoving.Furnitures.Add(tempFurniture);
                foreach (DateTime date in testList_two)
                {
                    PauseTimes temp = new PauseTimes();
                    temp.Date = date;
                    tempMoving.PauseTimes.Add(temp);
                }

                tempMoving.Equipment.Add(new TaskAssignedEquipment()
                {
                    Equipment = testEquipment
                });
                tempMoving.Equipment.Add(new TaskAssignedEquipment()
                {
                    Equipment = testEquipment_one
                });
                tempMoving.Employees.Add(new TaskAssignedEmployees()
                {
                    Employee = tempEmployee
                });
                tempMoving.Employees.Add(new TaskAssignedEmployees()
                {
                    Employee = tempEmployee_five
                });
                tempMoving.Employees.Add(new TaskAssignedEmployees()
                {
                    Employee = tempEmployee_one
                });
                tempDelivery.Employees.Add(new TaskAssignedEmployees()
                {
                    Employee = tempEmployee_six
                });
                tempDelivery.Employees.Add(new TaskAssignedEmployees()
                {
                    Employee = tempEmployee_two
                });
                tempDelivery.Equipment.Add(new TaskAssignedEquipment()
                {
                    Equipment = testEquipment_one
                });

                db.Tasks.Add(tempDelivery);
                db.Tasks.Add(tempMoving);
                db.SaveChanges();



                /*
                 * db.Employees.Add(tempEmployee);
                 * db.Employees.Add(tempEmployee_one);
                 * db.Employees.Add(tempEmployee_two);
                 * db.Employees.Add(tempEmployee_three);
                 * db.Employees.Add(tempEmployee_four);
                 * db.Employees.Add(tempEmployee_five);
                 * db.Employees.Add(tempEmployee_six);
                 *
                 * db.Customers.Add(tempCustomer);
                 * db.Customers.Add(tempCustomer_one);
                 *
                 * db.Equipment.Add(testEquipment);
                 * db.Equipment.Add(testEquipment_one);
                 * db.Furniture.Add(tempFurniture);
                 */



                foreach (Task ctxTask in db.Tasks)
                {
                    Console.WriteLine($"{ctxTask.Name}:");
                    if (ctxTask.Customer is Private)
                    {
                        Console.WriteLine($"{ctxTask.Customer.ID}: {((Private)ctxTask.Customer).Firstname} {((Private)ctxTask.Customer).Lastname}");
                    }
                    else if (ctxTask.Customer is Business)
                    {
                        Console.WriteLine($"{ctxTask.Customer.ID}: {((Business)ctxTask.Customer).Name}");
                    }
                    else
                    {
                        Console.WriteLine($"{((Public)ctxTask.Customer).ID}: {((Public)ctxTask.Customer).Name}");
                    }
                    foreach (var employee in ctxTask.Employees.Select(e => e.Employee))
                    {
                        Console.WriteLine($"{employee.ID}:  {employee.Firstname} {employee.Lastname}");
                    }
                    foreach (var equipment in ctxTask.Equipment.Select(e => e.Equipment))
                    {
                        Console.WriteLine($"{equipment.ID}: {equipment.Name}");
                    }
                    if (ctxTask is Moving)
                    {
                        Console.WriteLine($"Furniture:");

                        foreach (var furniture in ((Moving)ctxTask).Furnitures)
                        {
                            Console.WriteLine($"{furniture.ID}:  {furniture.Name}");
                        }
                    }
                    Console.WriteLine($"Date(s): ");

                    foreach (var date in ctxTask.Dates)
                    {
                        Console.WriteLine($"  {date.Date.DayOfYear}");
                    }
                }
                var test = db.Employees.FirstOrDefault();
                Console.WriteLine(test.ContactInfo.Email);
            }
        }
コード例 #12
0
 public ToolController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #13
0
ファイル: TaskController.cs プロジェクト: snuuby/P3-
 public TaskController(HasserisDbContext database)
 {
     this.database = database;
 }
コード例 #14
0
ファイル: FurnitureController.cs プロジェクト: snuuby/P3-
 public FurnituresController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #15
0
ファイル: InspectionController.cs プロジェクト: snuuby/P3-
 public InspectionController(HasserisDbContext database)
 {
     this.database = database;
 }
コード例 #16
0
ファイル: OfferController.cs プロジェクト: snuuby/P3-
 public OfferController(HasserisDbContext database)
 {
     this.database = database;
 }
コード例 #17
0
 public ImageController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #18
0
ファイル: EmployeeController.cs プロジェクト: snuuby/P3-
 public EmployeeController(HasserisDbContext sc)
 {
     database = sc;
 }
コード例 #19
0
ファイル: CustomerController.cs プロジェクト: snuuby/P3-
 public CustomerController(HasserisDbContext sc)
 {
     database = sc;
 }