public void GetKvest_ObjectReturn()
        {
            mock.Setup(m => m.KvestRooms.GetAll()).Returns(rooms);
            mock.Setup(m => m.KvestRooms.Get(rooms.ElementAt(0).Id)).Returns(rooms.ElementAt(0));
            KvestRoomService service = new KvestRoomService(mock.Object);
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <KvestRoom, KvestRoomDTO>()).CreateMapper();

            KvestRoomDTO kvest = service.GetKvest(1);
            KvestRoomDTO ex    = mapper.Map <KvestRoom, KvestRoomDTO>(rooms.ElementAt(0));


            Assert.IsNotNull(kvest);
        }
        public void GetKvest_ErrorReturn()
        {
            try
            {
                mock.Setup(m => m.KvestRooms.GetAll()).Returns(rooms);
                mock.Setup(m => m.KvestRooms.Get(rooms.ElementAt(0).Id)).Returns(rooms.ElementAt(0));
                KvestRoomService service = new KvestRoomService(mock.Object);
                var mapper = new MapperConfiguration(cfg => cfg.CreateMap <KvestRoom, KvestRoomDTO>()).CreateMapper();

                KvestRoomDTO kvest = service.GetKvest(77);
                //KvestRoomDTO ex = mapper.Map<KvestRoom, KvestRoomDTO>(rooms.ElementAt(0));

                Assert.Fail();
            }
            catch (ValidationException) { }
        }
        public void MakeKvest(KvestRoomDTO data)
        {
            AgeCategory dalDataAge = Database.AgeCategories.Get(data.AgeCategoryId);
            UsersValue  dalDataVal = Database.UsersValues.Get(data.UsersValueId);

            if (dalDataAge == null || dalDataVal == null)
            {
                throw new ValidationException("Data - info/type is not found", "");
            }
            KvestRoom DATA = new KvestRoom
            {
                Name            = data.Name,
                UsersValueId    = dalDataVal.ID,
                AgeCategoryId   = dalDataAge.Id,
                PriceForOneUser = data.PriceForOneUser,
            };

            Database.KvestRooms.Create(DATA);
            Database.Save();
        }
Beispiel #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0 && textBox2.Text.Length > 0)
            {
                var          mapper = new MapperConfiguration(cfg => cfg.CreateMap <KvestRoom, KvestRoomDTO>()).CreateMapper();
                KvestRoomDTO kvest  = mapper.Map <KvestRoom, KvestRoomDTO>(new KvestRoom {
                    Name = textBox1.Text, UsersValueId = usersValue, AgeCategoryId = ageCategory, PriceForOneUser = Convert.ToInt32(textBox2.Text)
                });

                kvestService.MakeKvest(kvest);
                //if (prog.AddKvestRoom(textBox1.Text, usersValue, ageCategory, Convert.ToInt32(textBox2.Text)))
                //{
                MessageBox.Show("Kvest-room was added succesfully!!!");
                CleanItems();
                //}
            }
            else
            {
                MessageBox.Show("You shoud edit all rows. Try again!");
            }
        }
        public void MakeKvest_IncreaseListCount()
        {
            KvestRoomDTO kvest = new KvestRoomDTO()
            {
                Name = "Nut", PriceForOneUser = 200, UsersValueId = 2, AgeCategoryId = 1,
            };

            mock.Setup(m => m.UsersValues.Get(kvest.UsersValueId)).Returns(user);
            mock.Setup(m => m.AgeCategories.Get(kvest.AgeCategoryId)).Returns(age);
            mock.Setup(m => m.KvestRooms.GetAll()).Returns(rooms);
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <KvestRoomDTO, KvestRoom>()).CreateMapper();
            KvestRoomService service = new KvestRoomService(mock.Object);

            service.MakeKvest(kvest);
            KvestRoom example = mapper.Map <KvestRoomDTO, KvestRoom>(kvest);

            rooms.Add(example);

            mock.Verify(lw => lw.KvestRooms.Create(It.IsAny <KvestRoom>()),
                        Times.Once());
            Assert.AreEqual(rooms.Count(), 5);
        }