Пример #1
0
        public void TestCreateEvent()
        {
            var      ctrl  = new EventCtrl();
            UserCtrl uCtrl = new UserCtrl();
            var      u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");


            Event e = new Event
            {
                Title             = "test title" + Guid.NewGuid(),
                Description       = "This is a long description\ncontaining newlines",
                NumOfParticipants = 5,
                PriceFrom         = 100.0,
                PriceTo           = 200.0,
                Location          = "Sofiendalsvej 60",
                Datetime          = DateTime.Now.AddHours(1), //+1 hour from now to not trigger the past date exception
                IsPublic          = true,
                Admin             = u
            };

            // Act
            Event output = ctrl.CreateEvent(e.Title, e.Description, e.NumOfParticipants, e.PriceFrom, e.PriceTo, e.Location, e.Datetime, e.IsPublic, u);


            // Assert
            Assert.AreEqual(e.Title, output.Title);
        }
Пример #2
0
        public void TestAddItem()
        {
            // Arrange
            ComponentCtrl cCtrl = new ComponentCtrl();
            EventCtrl     eCtrl = new EventCtrl();
            UserCtrl      uCtrl = new UserCtrl();
            var           u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");

            // Act
            var evnt     = eCtrl.CreateEvent("E Title", "E Desc", 42, 42, 42, "E Location", DateTime.Now.AddDays(5), true, u);
            var category = cCtrl.CreateCategory("Cat Name", "Cat desc", null);

            eCtrl.AddCategory(evnt, category);
            var category2 = cCtrl.CreateCategory("Cat2 Name2", "Cat2 desc2", category);

            eCtrl.AddCategory(evnt, category2);
            var item = cCtrl.CreateItem("Item Name", "Item Desc", 42, category2, evnt);

            eCtrl.AddItem(evnt, category2, item);

            // Assert
            var foundCategory = cCtrl.FindCategoryById(category2.Id);
            var foundItem     = ((Item)((Category)evnt.Components[1]).Components[0]);

            Assert.IsNotNull(foundItem);
            Assert.IsTrue(foundCategory.Components.Count == 1);
            Assert.IsTrue(foundCategory.Components[0].Id == foundItem.Id);
        }
Пример #3
0
 //Creates user with 'name', 'email' and 'password'
 public string CreateUser(string name, string mail, string password)
 {
     try
     {
         return(userCtrl.CreateUser(name, mail, password));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #4
0
        public void testCreateDublicateUser()
        {
            var      g     = Guid.NewGuid();
            UserCtrl uCtrl = new UserCtrl();
            User     user  = new User
            {
                Firstname = "Niklas",
                Lastname  = "Jørgensen",
                Email     = "*****@*****.**" + g,
                Password  = "******"
            };

            uCtrl.CreateUser(user.Firstname, user.Lastname, user.Email, user.Password);

            try
            {
                uCtrl.CreateUser(user.Firstname, user.Lastname, user.Email, user.Password);
                Assert.Fail();
            }
            catch (DublicateUserException)
            {
            }
        }
Пример #5
0
 public void CreateUser(string firstName, string lastName, string email, string password)
 {
     try
     {
         uCtrl.CreateUser(firstName, lastName, email, password);
     }
     catch (DublicateUserException)
     {
         throw new FaultException("Brugeren eksisterer allerede");
     }
     catch (ArgumentException argE)
     {
         throw new FaultException(argE.Message);
     }
 }
Пример #6
0
        public void SystemTestAddCategoryToCategory()
        {
            EventCtrl     eCtrl   = new EventCtrl();
            ComponentCtrl cCtrl   = new ComponentCtrl();
            UserCtrl      uCtrl   = new UserCtrl();
            IService      service = new Service();

            User  u = uCtrl.CreateUser("System Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");
            Event e = service.CreateEvent("System Test Event", "Test", 2, 20, 100, "Right here", DateTime.Now.AddHours(5), true, u);

            service.AddCategoryToEvent(e.Id, "System Test Cat 1", "Cat 1", null);
            e = service.FindEventById(e.Id);

            service.AddCategoryToEvent(e.Id, "System Test Cat 2", "Cat 2",
                                       e.Components.Where(c => c.Title == "System Test Cat 1" && c is Category).FirstOrDefault());

            Assert.IsTrue(true);
        }
Пример #7
0
        public bool CreateLogin(string email, string password, string firstname, string lastname, string address, int zipcode, long phonenumber)
        {
            bool lykkes = false;

            email     = email.ToString().Trim().ToLower();
            password  = password.Trim();
            firstname = firstname.Trim();
            lastname  = lastname.Trim();
            address   = address.Trim();

            if (email.Length >= 6 && password.Length >= 4 && firstname.Length >= 2 && lastname.Length >= 2 && address.Length >= 4 && zipcode > 999 && phonenumber > 0)
            {
                if (email.Contains("@") && email.Contains("."))
                {
                    User exists = uCtrl.GetUser(email);

                    if (exists == null)
                    {
                        Customer c = new Customer();
                        c.Email     = email;
                        c.Password  = password;
                        c.FirstName = firstname;
                        c.LastName  = lastname;
                        c.Address   = address;
                        c.City      = cityCtrl.Get(zipcode);
                        c.Role      = "User";
                        c.CPR       = 0000000000;
                        c.Confirmed = false;

                        if (uCtrl.CreateUser(c))
                        {
                            lykkes = true;
                        }
                    }
                    else if (exists != null)
                    {
                        lykkes = false;
                    }
                }
            }
            return(lykkes);
        }
Пример #8
0
        public void CreateUserTest()
        {
            UserCtrl uCtrl = new UserCtrl();
            User     user  = new User
            {
                Firstname = "Niklas",
                Lastname  = "Jørgensen",
                Email     = "*****@*****.**" + Guid.NewGuid(), // To avoid creating the same user when rerunning the test
                Password  = "******"
            };

            uCtrl.CreateUser(user.Firstname, user.Lastname, user.Email, user.Password);

            using (var ctx = new DALContext())
            {
                User foundUser = ctx.Users.Where(u => u.Email == user.Email).FirstOrDefault();
                Assert.IsNotNull(foundUser);
                Assert.AreEqual(user.Firstname, foundUser.Firstname);
            }
        }
Пример #9
0
        public void TestAddCategoryToCategory()
        {
            // Arrange
            EventCtrl     eCtrl = new EventCtrl();
            ComponentCtrl cCtrl = new ComponentCtrl();
            UserCtrl      uCtrl = new UserCtrl();
            var           u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");
            var           e     = eCtrl.CreateEvent("Testing Event", "Test", 2, 20, 100, "Right here", DateTime.Now.AddHours(5), true, u);
            var           c1    = cCtrl.CreateCategory("Testing Category Lvl 1", "Test", null);

            // Act
            eCtrl.AddCategory(e, c1);

            var c2 = cCtrl.CreateCategory("Testing Category Lvl 2", "Test", c1);
            var e2 = eCtrl.FindById(e.Id);

            eCtrl.AddCategory(e2, c2);

            Assert.IsTrue(c2.Parent.Id == c1.Id);
            Assert.IsTrue(c2.EventId == e.Id);
        }
Пример #10
0
        public void CreateRegistrationTest()
        {
            // Arrange
            UserCtrl         uCtrl = new UserCtrl();
            var              user  = uCtrl.CreateUser("Jesper", "Jørgensen", "*****@*****.**" + Guid.NewGuid(), "123456");
            EventCtrl        eCtrl = new EventCtrl();
            var              eve   = eCtrl.CreateEvent("Hej", "nej", 5, 5.5, 6.5, "42", DateTime.Now.AddHours(5), false, user);
            RegistrationCtrl rCtrl = new RegistrationCtrl();

            // Act
            var reg = rCtrl.CreateRegistration(user, eve);

            //Assert
            user = uCtrl.UpdateUserInfo(user);
            eve  = eCtrl.FindById(eve.Id);

            bool userHasReg  = user.Registrations.Select(x => x.Id).Contains(reg.Id);
            bool eventHasReg = eve.Registrations.Select(x => x.Id).Contains(reg.Id);

            Assert.IsTrue(userHasReg);
            Assert.IsTrue(eventHasReg);
        }
Пример #11
0
        public void TestAddComponent()
        {
            // Arrange
            EventCtrl eCtrl = new EventCtrl();
            UserCtrl  uCtrl = new UserCtrl();
            var       u     = uCtrl.CreateUser("Test User", "Test User", "test" + Guid.NewGuid() + "@email.com", "password");

            var e = eCtrl.CreateEvent("Event", "Evently event",
                                      2, 20, 100, "Right here", DateTime.Now, true, u);
            Category c = new ComponentCtrl().CreateCategory("Cat", "CateCat", null);

            //Act
            eCtrl.AddCategory(e, c);

            //Assert
            var foundEvent = eCtrl.FindById(e.Id);

            Assert.IsTrue(foundEvent.Components.Count == 1);
            var foundComponent = foundEvent.Components.First();

            Assert.IsTrue(c.Id == foundComponent.Id);
            Assert.IsTrue(foundComponent is Category); // it returns true if an instance is in the inheritance tree
        }
Пример #12
0
        public void TestRegisterToEvent()
        {
            // Arrange
            var ctrl  = new EventCtrl();
            var uCtrl = new UserCtrl();

            Event e = new Event
            {
                Title             = "test title" + Guid.NewGuid(),
                Description       = "This is a long description\ncontaining newlines",
                NumOfParticipants = 5,
                PriceFrom         = 100.0,
                PriceTo           = 200.0,
                Location          = "Sofiendalsvej 60",
                Datetime          = DateTime.Now.AddHours(1), //+1 hour from now to not trigger the past date exception
                IsPublic          = true
            };
            var   user     = uCtrl.CreateUser("efrgfvd", "fss", "*****@*****.**" + Guid.NewGuid(), "dsasdc");
            Event newEvent = ctrl.CreateEvent(e.Title, e.Description, e.NumOfParticipants, e.PriceFrom, e.PriceTo, e.Location, e.Datetime, e.IsPublic, user);

            // Act
            ctrl.RegisterToEvent(newEvent, user);

            // Assert
            using (var ctx = new DAL.DALContext())
            {
                user     = uCtrl.FindByEmail(user.Email);
                newEvent = ctrl.FindById(newEvent.Id);
                var reg = user.Registrations[0];

                Assert.AreEqual(reg.User, user);
                Assert.AreEqual(reg.Event.Id, newEvent.Id);
                Assert.IsTrue(user.Registrations.Contains(reg));

                Assert.IsTrue(newEvent.Registrations.Exists(r => r.Id == reg.Id));
            }
        }
Пример #13
0
        //private RatingCtrl _ratingCtrl;

        public int CreateUser(User user)
        {
            _userCtrl = new UserCtrl();
            return(_userCtrl.CreateUser(user));
        }