public void StartNight_Gameroom()
        {
            IHotelTamagotchiContext c  = new FakeHotelTamagotchiContext();
            IHotelRoomRepository    hR = new HotelRoomRepository(c);
            ITamagotchiRepository   tR = new TamagotchiRepository(c);

            HotelRoomViewModel h = new HotelRoomViewModel()
            {
                Size = 5,
                Type = HotelRoomType.Gameroom,
            };

            hR.Add(h);

            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Name        = "Test",
                Alive       = true,
                HotelRoom   = h,
                HotelRoomId = h.Id,
                Boredom     = 50
            };

            tR.Add(t);

            NightController nC = new NightController(tR, hR);

            nC.StartNight();

            Assert.IsTrue(tR.Find(t.Id).Boredom == 0);
            Assert.IsTrue(tR.Find(t.Id).Pennies == 80);
        }
Exemplo n.º 2
0
        public void BookingController_CreateBooking()
        {
            IHotelTamagotchiContext c  = new FakeHotelTamagotchiContext();
            IHotelRoomRepository    hr = new HotelRoomRepository(c);
            ITamagotchiRepository   tr = new TamagotchiRepository(c);
            BookingController       bc = new BookingController(hr, tr);
            var ccMock = new Mock <ControllerContext>();

            ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser");
            ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Customer);
            bc.ControllerContext = ccMock.Object;
            FormCollection fc = new FormCollection();


            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Name  = "Test",
                Alive = true
            };

            tr.Add(t);
            HotelRoomViewModel h = new HotelRoomViewModel()
            {
                Size = 5,
                Type = HotelRoomType.Fightroom
            };

            hr.Add(h);
            fc.Add("1", "true,false");
            bc.Create(fc, h);
            Assert.AreEqual(t.ToModel().HotelRoomId, tr.Find(t.Id).HotelRoomId);
            tr.Remove(t);
            hr.Remove(h);
        }
        public void StartNight_Homeless()
        {
            IHotelTamagotchiContext c  = new FakeHotelTamagotchiContext();
            IHotelRoomRepository    hR = new HotelRoomRepository(c);
            ITamagotchiRepository   tR = new TamagotchiRepository(c);


            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Name  = "Test",
                Alive = true
            };
            TamagotchiViewModel t2 = new TamagotchiViewModel()
            {
                Name   = "Test2",
                Alive  = true,
                Health = 10,
            };

            tR.Add(t);
            tR.Add(t2);

            NightController nC = new NightController(tR, hR);

            nC.StartNight();

            Assert.IsTrue(tR.Find(t.Id).Boredom == 20);
            Assert.IsTrue(tR.Find(t.Id).Health == 80);

            Assert.IsTrue(tR.Find(t2.Id).Health == 0);
            Assert.IsTrue(tR.Find(t2.Id).Alive == false);
        }
Exemplo n.º 4
0
        public void Tamagotchi_invalid_validation()
        {
            // Arrange
            TamagotchiViewModel t1 = new TamagotchiViewModel()
            {
                Age = -1, Name = "Testestestest", Pennies = -1, Level = -1, Health = 101, Boredom = 101, Alive = alive
            };
            TamagotchiViewModel t2 = new TamagotchiViewModel()
            {
                Age = 0, Name = null, Pennies = pennies, Level = level, Health = health, Boredom = boredom, Alive = alive
            };

            // Act
            string NameLength   = "Your name can only be 10 letters long";
            string NameNull     = "You have to put in a name in the name field";
            string AgeCheck     = "You have to be atleast 0 days old";
            string PenniesCheck = "You can not have a negative amount of pennies";
            string LevelCheck   = "You can not have a negative amount of levels";
            string HealthCheck  = "Your health value must be between 0 and 100";
            string BoredomCheck = "Your boredom value must be between 0 and 100";

            var errors1 = t1.Validate(null);
            var errors2 = t2.Validate(null);

            //Assert

            Assert.AreEqual(NameLength, errors1.Where(x => x.ErrorMessage.Equals(NameLength)).FirstOrDefault().ErrorMessage);
            Assert.AreEqual(AgeCheck, errors1.Where(x => x.ErrorMessage.Equals(AgeCheck)).FirstOrDefault().ErrorMessage);
            Assert.AreEqual(PenniesCheck, errors1.Where(x => x.ErrorMessage.Equals(PenniesCheck)).FirstOrDefault().ErrorMessage);
            Assert.AreEqual(LevelCheck, errors1.Where(x => x.ErrorMessage.Equals(LevelCheck)).FirstOrDefault().ErrorMessage);
            Assert.AreEqual(HealthCheck, errors1.Where(x => x.ErrorMessage.Equals(HealthCheck)).FirstOrDefault().ErrorMessage);
            Assert.AreEqual(BoredomCheck, errors1.Where(x => x.ErrorMessage.Equals(BoredomCheck)).FirstOrDefault().ErrorMessage);

            Assert.AreEqual(NameNull, errors2.Where(x => x.ErrorMessage.Equals(NameNull)).FirstOrDefault().ErrorMessage);
        }
Exemplo n.º 5
0
        public void Tamagotchi_valid_validation()
        {
            // Arrange
            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Age = 0, Name = name, Pennies = pennies, Level = level, Health = health, Boredom = boredom, Alive = alive
            };
            // Act
            var errors = t.Validate(null);

            //Assert
            Assert.AreEqual(0, errors.Count());
        }
Exemplo n.º 6
0
        public void Tamagotchi_properties()
        {
            // Arrange
            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Age = age, Name = name, Pennies = pennies, Level = level, Health = health, Boredom = boredom, Alive = alive
            };

            // Act


            // Assert
            Assert.AreEqual(age, t.Age);
            Assert.AreEqual(name, t.Name);
            Assert.AreEqual(pennies, t.Pennies);
            Assert.AreEqual(level, t.Level);
            Assert.AreEqual(health, t.Health);
            Assert.AreEqual(boredom, t.Boredom);
            Assert.AreEqual(alive, t.Alive);
        }
        public void Test_Create()
        {
            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Name  = "Test_Creat",
                Alive = false
            };
            IHotelTamagotchiContext c  = new FakeHotelTamagotchiContext();
            ITamagotchiRepository   tr = new TamagotchiRepository(c);
            TamagotchiController    tc = new TamagotchiController(tr);
            var ccMock = new Mock <ControllerContext>();

            ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser");
            ccMock.SetupGet(x => x.HttpContext.Session["UserId"]).Returns(1);
            ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Customer);
            tc.ControllerContext = ccMock.Object;

            tc.Create(t);

            Assert.AreEqual(tr.Find(t.Id).ToModel(), t.ToModel());
        }
        public void Test_DeleteConfirmed()
        {
            TamagotchiViewModel t = new TamagotchiViewModel()
            {
                Name  = "Test_Remov",
                Alive = false
            };
            IHotelTamagotchiContext c  = new FakeHotelTamagotchiContext();
            ITamagotchiRepository   tr = new TamagotchiRepository(c);;
            TamagotchiController    tc = new TamagotchiController(tr);
            var ccMock = new Mock <ControllerContext>();

            ccMock.SetupGet(x => x.HttpContext.Session["User"]).Returns("testUser");
            ccMock.SetupGet(x => x.HttpContext.Session["UserId"]).Returns(1);
            ccMock.SetupGet(x => x.HttpContext.Session["Role"]).Returns(UserRole.Customer);
            tc.ControllerContext = ccMock.Object;

            tc.Create(t);
            tc.DeleteConfirmed(t.Id);

            Assert.IsFalse(tr.GetAll().Contains(t));
        }
Exemplo n.º 9
0
 public void SetChanged(TamagotchiViewModel entity)
 {
     _database.SetChanged(entity.ToModel());
     _database.SaveChanges();
 }
Exemplo n.º 10
0
 public void Remove(TamagotchiViewModel entity)
 {
     _database.Tamagotchi.Remove(entity.ToModel());
     _database.SaveChanges();
 }