Example #1
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);
        }
Example #2
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);
        }
Example #3
0
        public void TestPriceFromIsLargerThanPriceTo()
        {
            // Arrange
            EventCtrl eCtrl     = new EventCtrl();
            double    priceFrom = 100;
            double    priceTo   = 50;
            // Act
            var e = eCtrl.CreateEvent("Event", "Evently event",
                                      2, priceFrom, priceTo, "Right here", DateTime.Now, true, null);

            // Assert
            Assert.Fail();
        }
Example #4
0
 public Event CreateEvent(string title, string description, int numOfParticipants, double priceFrom, double priceTo, string location, DateTime datetime, bool isPublic, User admin)
 {
     try
     {
         Event        e = eCtrl.CreateEvent(title, description, numOfParticipants, priceFrom, priceTo, location, datetime, isPublic, admin);
         Registration r = rCtrl.CreateRegistration(e.Admin, e);
         uCtrl.AddRegistration(e.Admin, r);
         return(e);
     }
     catch (ArgumentException ae)
     {
         throw new FaultException(ae.Message);
     }
     catch (DateInPastException dipe)
     {
         throw new FaultException(dipe.Message);
     }
 }
Example #5
0
        public void TestSignUpForEvent()
        {
            var user  = new UserCtrl().CreateUser("Fornavn", "Efternavn", "*****@*****.**" + Guid.NewGuid(), "123456");
            var eCtrl = new EventCtrl();
            var e     = eCtrl.CreateEvent("dsd", "dewdc", 23, 213.3, 21312.3, "here", DateTime.Now.AddHours(5), false, user);


            // Act
            eCtrl.SignUpForEvent(user.Email, e.Id);

            // Assert
            using (var ctx = new DALContext())
            {
                var reg = new UserCtrl().FindByEmail(user.Email).Registrations[0];

                var found = ctx.Registrations.Find(reg.Id);
                Assert.AreEqual(reg.Id, found.Id);
            }
        }
Example #6
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);
        }
        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);
        }
Example #8
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
        }
Example #9
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));
            }
        }