public void EntityToModelMagazineMapperNull()
 {
     Magazine magazine = null;
     MagazineMapper magazineMapper=new MagazineMapper();
     MagazineBusinessModel magazineBusiness = magazineMapper.Map(magazine);
     Assert.IsNull(magazineBusiness);
 }
示例#2
0
        public void UpdateMagazine(MagazineBusinessModel magazineBusinessModel)
        {
            var mapper = new MagazineMapper();

            var magazineOld = this.uow.Items.GetById(magazineBusinessModel.Id) as Magazine;
           
            magazineOld.Tags.Clear();

            var magazineMapped = mapper.Map(magazineBusinessModel);

            foreach (var tag in magazineBusinessModel.Tags)
            {
                var t = this.uow.Tags.GetById(tag.id);
                magazineOld.Tags.Add(t);
            }

            magazineOld.Name = magazineMapped.Name;
            magazineOld.Issue = magazineMapped.Issue;
            magazineOld.PageCount = magazineMapped.PageCount;
            magazineOld.Publisher = magazineMapped.Publisher;
            magazineOld.Year = magazineMapped.Year;

            this.uow.Items.Update(magazineOld);

            this.uow.Commit();
        }
        public TagScoreMapperTests()
        {
            this.mapper = new TagScoreMapper();

            Fixture fixture = new Fixture{RepeatCount = 1};
            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));

            Reader reader = fixture.Create<Reader>();
            ReaderMapper readerMapper = new ReaderMapper();
            var readerModel = readerMapper.Map(reader);

            // item is book
            Book book = fixture.Create<Book>();
            this.entityWithBook = new TagScore{Id = 1, Item = book, Reader = reader, Score = 0.5f};
            BookMapper bookMapper = new BookMapper();
            var bookModel = bookMapper.Map(book);
            this.modelWithBook = new TagScoreBusinessModel{Item = bookModel, Reader = readerModel, Score = 0.5f};
            
            // item is disk
            Disk disk = fixture.Create<Disk>();
            this.entityWithDisk = new TagScore { Id = 1, Item = disk, Reader = reader, Score = 0.5f };
            DiskMapper diskMapper = new DiskMapper();
            var diskModel = diskMapper.Map(disk);
            this.modelWithDisk = new TagScoreBusinessModel{Item = diskModel, Reader = readerModel, Score = 0.5f};

            // item is magazine
            Magazine magazine = fixture.Create<Magazine>();
            this.entityWithMagazine = new TagScore { Id = 1, Item = magazine, Reader = reader, Score = 0.5f };
            MagazineMapper magazineMapper = new MagazineMapper();
            var magazineModel = magazineMapper.Map(magazine);
            this.modelWithMagazine =
                new TagScoreBusinessModel { Item = magazineModel, Reader = readerModel, Score = 0.5f };
        }
示例#4
0
        public void UpdateMagazine(MagazineBusinessModel magazineBusinessModel)
        {
            var mapper = new MagazineMapper();

            var magazineOld = this.uow.Items.GetById(magazineBusinessModel.Id) as Magazine;

            magazineOld.Tags.Clear();

            var magazineMapped = mapper.Map(magazineBusinessModel);

            foreach (var tag in magazineBusinessModel.Tags)
            {
                var t = this.uow.Tags.GetById(tag.id);
                magazineOld.Tags.Add(t);
            }

            magazineOld.Name      = magazineMapped.Name;
            magazineOld.Issue     = magazineMapped.Issue;
            magazineOld.PageCount = magazineMapped.PageCount;
            magazineOld.Publisher = magazineMapped.Publisher;
            magazineOld.Year      = magazineMapped.Year;

            this.uow.Items.Update(magazineOld);

            this.uow.Commit();
        }
示例#5
0
        public void ModelToEntityMagazineMapperNull()
        {
            MagazineBusinessModel magazineBusiness = null;
            MagazineMapper        magazineMapper   = new MagazineMapper();
            Magazine magazine = magazineMapper.Map(magazineBusiness);

            Assert.IsNull(magazine);
        }
示例#6
0
        public TagScoreMapperTests()
        {
            this.mapper = new TagScoreMapper();

            Fixture fixture = new Fixture {
                RepeatCount = 1
            };

            fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
            fixture.Behaviors.Add(new OmitOnRecursionBehavior());
            fixture.Customizations.Add(new TypeRelay(typeof(Item), typeof(Book)));

            Reader       reader       = fixture.Create <Reader>();
            ReaderMapper readerMapper = new ReaderMapper();
            var          readerModel  = readerMapper.Map(reader);

            // item is book
            Book book = fixture.Create <Book>();

            this.entityWithBook = new TagScore {
                Id = 1, Item = book, Reader = reader, Score = 0.5f
            };
            BookMapper bookMapper = new BookMapper();
            var        bookModel  = bookMapper.Map(book);

            this.modelWithBook = new TagScoreBusinessModel {
                Item = bookModel, Reader = readerModel, Score = 0.5f
            };

            // item is disk
            Disk disk = fixture.Create <Disk>();

            this.entityWithDisk = new TagScore {
                Id = 1, Item = disk, Reader = reader, Score = 0.5f
            };
            DiskMapper diskMapper = new DiskMapper();
            var        diskModel  = diskMapper.Map(disk);

            this.modelWithDisk = new TagScoreBusinessModel {
                Item = diskModel, Reader = readerModel, Score = 0.5f
            };

            // item is magazine
            Magazine magazine = fixture.Create <Magazine>();

            this.entityWithMagazine = new TagScore {
                Id = 1, Item = magazine, Reader = reader, Score = 0.5f
            };
            MagazineMapper magazineMapper = new MagazineMapper();
            var            magazineModel  = magazineMapper.Map(magazine);

            this.modelWithMagazine =
                new TagScoreBusinessModel {
                Item = magazineModel, Reader = readerModel, Score = 0.5f
            };
        }
 public void ModelToEntityMagazineMapperTest()
 {
     MagazineMapper magazineMapper=new MagazineMapper();
     Magazine magazine = magazineMapper.Map(modelToMap);
     Assert.AreEqual(entitytoMap.Id, magazine.Id);
     Assert.AreEqual(entitytoMap.Issue,magazine.Issue);
     Assert.AreEqual(entitytoMap.Name,magazine.Name);
     Assert.AreEqual(entitytoMap.PageCount,magazine.PageCount);
     Assert.AreEqual(entitytoMap.Publisher,magazine.Publisher);
     Assert.AreEqual(entitytoMap.Year,magazine.Year);
     Assert.IsNotNull(magazine);
 }
 public void EntityToModelMagazineMapperTest()
 {
     MagazineMapper magazineMapper=new MagazineMapper();
     MagazineBusinessModel magazineBusiness = magazineMapper.Map(entitytoMap);
     Assert.AreEqual(entitytoMap.Id, magazineBusiness.Id);
     Assert.AreEqual(entitytoMap.Issue,magazineBusiness.Issue);
     Assert.AreEqual(entitytoMap.Name,magazineBusiness.Name);
     Assert.AreEqual(entitytoMap.PageCount,magazineBusiness.PageCount);
     Assert.AreEqual(entitytoMap.Publisher,magazineBusiness.Publisher);
     Assert.AreEqual(entitytoMap.Year,magazineBusiness.Year);
     Assert.IsNotNull(magazineBusiness);
 }
示例#9
0
        public List<MagazineBusinessModel> GetAllMagazines()
        {
            MagazineMapper mapper = new MagazineMapper();
            List<Magazine> list = this.uow.Items.GetAll().OfType<Magazine>().ToList();
            List<MagazineBusinessModel> listBusinessModels = new List<MagazineBusinessModel>();
            foreach (Magazine magazine in list)
            {
                listBusinessModels.Add(mapper.Map(magazine));
            }

            return listBusinessModels;
        }
示例#10
0
        public void ModelToEntityMagazineMapperTest()
        {
            MagazineMapper magazineMapper = new MagazineMapper();
            Magazine       magazine       = magazineMapper.Map(modelToMap);

            Assert.AreEqual(entitytoMap.Id, magazine.Id);
            Assert.AreEqual(entitytoMap.Issue, magazine.Issue);
            Assert.AreEqual(entitytoMap.Name, magazine.Name);
            Assert.AreEqual(entitytoMap.PageCount, magazine.PageCount);
            Assert.AreEqual(entitytoMap.Publisher, magazine.Publisher);
            Assert.AreEqual(entitytoMap.Year, magazine.Year);
            Assert.IsNotNull(magazine);
        }
示例#11
0
        public void EntityToModelMagazineMapperTest()
        {
            MagazineMapper        magazineMapper   = new MagazineMapper();
            MagazineBusinessModel magazineBusiness = magazineMapper.Map(entitytoMap);

            Assert.AreEqual(entitytoMap.Id, magazineBusiness.Id);
            Assert.AreEqual(entitytoMap.Issue, magazineBusiness.Issue);
            Assert.AreEqual(entitytoMap.Name, magazineBusiness.Name);
            Assert.AreEqual(entitytoMap.PageCount, magazineBusiness.PageCount);
            Assert.AreEqual(entitytoMap.Publisher, magazineBusiness.Publisher);
            Assert.AreEqual(entitytoMap.Year, magazineBusiness.Year);
            Assert.IsNotNull(magazineBusiness);
        }
示例#12
0
        public List <MagazineBusinessModel> GetAllMagazines()
        {
            MagazineMapper  mapper = new MagazineMapper();
            List <Magazine> list   = this.uow.Items.GetAll().OfType <Magazine>().ToList();
            List <MagazineBusinessModel> listBusinessModels = new List <MagazineBusinessModel>();

            foreach (Magazine magazine in list)
            {
                listBusinessModels.Add(mapper.Map(magazine));
            }

            return(listBusinessModels);
        }
示例#13
0
        public ItemBusinessModel GetItemInfoById(int id)
        {
            var item = this.uow.Items.GetById(id);
            ItemBusinessModel itemBusinessModel;

            if (item is Book)
            {
                itemBusinessModel = new BookMapper().Map(item as Book);
            }
            else if (item is Magazine)
            {
                itemBusinessModel = new MagazineMapper().Map(item as Magazine);
            }
            else
            {
                itemBusinessModel = new DiskMapper().Map(item as Disk);
            }

            return(itemBusinessModel);
        }
        public ItemBusinessModel GetItemInfoById(int id)
        {
            var item = this.uow.Items.GetById(id);
            ItemBusinessModel itemBusinessModel;
            if (item is Book)
            {
                itemBusinessModel = new BookMapper().Map(item as Book);
            }
            else if (item is Magazine)
            {
                itemBusinessModel = new MagazineMapper().Map(item as Magazine);
            }
            else
            {
                itemBusinessModel = new DiskMapper().Map(item as Disk);
            }

            return itemBusinessModel;
        }