Exemplo n.º 1
0
        public void GetListOCByStringId_ValueReturned()
        {
            int i = 1;
            IEnumerable <ListOfCountry> ex;

            ex = new List <ListOfCountry> {
                new ListOfCountry()
                {
                    Id        = list.ElementAt(0).Id,
                    CountryId = list.ElementAt(0).CountryId,
                    TourId    = list.ElementAt(0).TourId
                }
            };
            mock.Setup(m => m.ListOfCountries.GetAll()).Returns(list);
            mock.Setup(m => m.ListOfCountries.GetName(i.ToString())).Returns(ex);
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ListOfCountry, ListOfCountryDTO>()).CreateMapper();
            ListOfCountryService service = new ListOfCountryService(mock.Object);
            //ISerialize<ListOfCountryDTO> serialize = new ListOCSerialize();

            //string example = serialize.serializeVary(mapper.Map<ListOfCountry, ListOfCountryDTO>(list.ElementAt(0)));

            ListOfCountryDTO data = service.GetListOC(i.ToString());

            Assert.IsNotNull(data);
        }
Exemplo n.º 2
0
        public void GetListOCById_ValueReturned()
        {
            mock.Setup(m => m.ListOfCountries.GetAll()).Returns(list);
            mock.Setup(m => m.ListOfCountries.Get(1)).Returns(list.ElementAt(0));
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ListOfCountry, ListOfCountryDTO>()).CreateMapper();
            ListOfCountryService service = new ListOfCountryService(mock.Object);
            //ISerialize<ListOfCountryDTO> serialize = new ListOCSerialize();

            //string example = serialize.serializeVary(mapper.Map<ListOfCountry, ListOfCountryDTO>(list.ElementAt(0)));

            ListOfCountryDTO data = service.GetListOC(1);

            Assert.IsNotNull(data);
        }
Exemplo n.º 3
0
        public void EditList_CapableReturned()
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ListOfCountryDTO, ListOfCountry>()).CreateMapper();
            ListOfCountryDTO listDTO = new ListOfCountryDTO()
            {
                Id = 3, CountryId = 9, TourId = 7
            };

            mock.Setup(m => m.Tours.Get(listDTO.TourId)).Returns(tour);
            mock.Setup(m => m.Countries.Get(listDTO.CountryId)).Returns(country);
            mock.Setup(m => m.ListOfCountries.GetAll()).Returns(list);
            ListOfCountryService service = new ListOfCountryService(mock.Object);

            var listOC = mapper.Map <ListOfCountryDTO, ListOfCountry>(listDTO);

            service.EditListOC((listDTO));//JsonSerializer.Serialize

            mock.Verify(lw => lw.ListOfCountries.Update(It.IsAny <ListOfCountry>()),
                        Times.Once());
            Assert.AreNotEqual(listOC, list.Where(p => p.Id == listDTO.Id));
        }
Exemplo n.º 4
0
        public void MakeList_CapableReturned()
        {
            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ListOfCountryDTO, ListOfCountry>()).CreateMapper();
            ListOfCountryDTO listDTO = new ListOfCountryDTO()
            {
                CountryId = 4, TourId = 7
            };

            mock.Setup(m => m.Tours.Get(listDTO.TourId)).Returns(tour);
            mock.Setup(m => m.Countries.Get(listDTO.CountryId)).Returns(country);
            mock.Setup(m => m.ListOfCountries.GetAll()).Returns(list);
            ListOfCountryService service = new ListOfCountryService(mock.Object);

            service.MakeList((listDTO));//JsonSerializer.Serialize

            var listOC = mapper.Map <ListOfCountryDTO, ListOfCountry>(listDTO);

            list.Add(listOC);

            Assert.AreEqual(list.Count(), 5);
        }
        public void EditListOC(ListOfCountryDTO DTO)//(TourDTO tourDTO)
        {
            //ListOCDeserialize deserialize = new ListOCDeserialize();
            //ListOfCountryDTO DTO = deserialize.deserializeVary(Vary);

            Tour tour = Database.Tours.Get(DTO.TourId);

            if (tour == null)
            {
                throw new ValidationException("Data - info/type is not found", "");
            }
            ListOfCountry data = new ListOfCountry
            {
                Id        = DTO.Id,
                CountryId = DTO.CountryId,
                TourId    = DTO.TourId,
            };

            Database.ListOfCountries.Update(data);
            Database.Save();
        }
        public void MakeList(ListOfCountryDTO listOCDDTO)//(ListOfCountryDTO listOCDDTO)
        {
            //IDeserialize<ListOfCountryDTO> deserializeList = new ListOCDeserialize();
            //ListOfCountryDTO listOCDDTO = deserializeList.deserializeVary(data);

            Tour    tour    = Database.Tours.Get(listOCDDTO.TourId);
            Country country = Database.Countries.Get(listOCDDTO.CountryId);

            // валидация
            if (tour == null || country == null)
            {
                throw new ValidationException("Data - country/tour is not found", "");
            }
            ListOfCountry listOC = new ListOfCountry
            {
                TourId    = listOCDDTO.TourId,
                CountryId = listOCDDTO.CountryId,
            };

            Database.ListOfCountries.Create(listOC);
            Database.Save();
        }