Exemplo n.º 1
0
        public void ÅrstidMetode(int value)
        {
            //Arrange
            Studerende studerende = new Studerende("test1", value, 1);

            //Act

            string årstid = studerende.Årstid();

            //Assert

            Assert.AreEqual("Vinter", studerende.Årstid());
        }
        public void TestEfterårÅrstid(int måned)
        {
            //Arrange

            Studerende studerende = new Studerende("test1", måned, 1);

            //Act

            string årstid = studerende.Årstid();

            //Assert

            Assert.AreEqual("Efterår", årstid);
        }
        public void TestForkertÅrstid(int måned)
        {
            //Arrange

            Studerende studerende = new Studerende("test1", måned, 1);

            //Act

            string årstid = studerende.Årstid();

            //Assert

            Assert.Fail();
        }
        public HttpResponseMessage Post(
            //[FromUri] string firstname, [FromUri] string lastname, [FromUri] string Username, [FromUri] string password, [FromUri] string homeroomClass)
            [FromBody]Models.Student student)
        {
            var numberOfErrors = 0;

            //var json = jsonBytes.ConvertToString();

            //var student = json.DeserializeJson<Models.Student>();

            Action<BookingSystemDataContext> submitChanges = db =>
            {
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    numberOfErrors++;
                    Debug.WriteLine("DEBUG: " + e.Message);
                }
            };

            var classId = 0;
            var cls = _db.Holds.FirstOrDefault(h => h.Navn.Equals(student.HomeRoomClass.Name));

            // checks if cls exits in table
            if (cls != null)
            {
                // checks if it is an eal mail and if it exists in the database
                if (student.Username.Contains("@edu.eal.dk") && _db.Brugers.FirstOrDefault(b => b.Brugernavn.Equals(student.Username)) == null)
                {
                    classId = cls._id;
                    student.Username.Replace("@edu.eal.dk", ""); // remove the ending

                    submitChanges(_db);
                    Debug.WriteLine("Homeroom name: " + student.HomeRoomClass.Name);
                    Debug.WriteLine("Finished searching through holds, number of errors: " + numberOfErrors);

                    Navn name = new Navn
                    {
                        Fornavn = student.Name.FirstName,
                        Efternavn = student.Name.LastName
                    };

                    _db.Navns.InsertOnSubmit(name);

                    submitChanges(_db);
                    Debug.WriteLine("Finished adding a name, number of errors: " + numberOfErrors);

                    Bruger user = new Bruger
                    {
                        Navn_id = name._id,
                        Brugernavn = student.Username,
                        Password = student.Password
                    };

                    _db.Brugers.InsertOnSubmit(user);

                    submitChanges(_db);
                    Debug.WriteLine("Finished adding a user, number of errors: " + numberOfErrors);

                Studerende stud = new Studerende
                {
                    Godkendt = 0,
                    Bruger_id = user._id,
                    Hold_id = classId
                };

                _db.Studerendes.InsertOnSubmit(stud);

                submitChanges(_db);
                Debug.WriteLine("Finished adding a student, number of errors: " + numberOfErrors);
                }
                else numberOfErrors++;
            }
            else
            {
                numberOfErrors++;
                Debug.WriteLine("DEBUG: Couldn't find the specified homeroom");
            }
            var message = new HttpResponseMessage();

            if (numberOfErrors != 0)
                message.Forbidden("Errors: " + numberOfErrors);
            else message.OK("{\"Response\":\"OK\"}");

            return message;
        }