Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            Guid ebookId;
            int  position;

            if (context.Request.QueryString.AllKeys.Contains("ebook") &&
                Guid.TryParse(context.Request.QueryString["ebook"], out ebookId) &&
                context.Request.QueryString.AllKeys.Contains("position") &&
                int.TryParse(context.Request.QueryString["position"], out position))
            {
                using (var db = new EbookManagerDbContext())
                {
                    var catalogRepository = new CatalogRepository(db);
                    var ebookPart         = catalogRepository.GetEbookPart(ebookId, position);
                    if (ebookPart != null)
                    {
                        context.Response.Clear();
                        context.Response.ContentType = ebookPart.ContentType;
                        context.Response.AddHeader("Content-Disposition", "attachment; filename=" + ebookPart.FileName);
                        context.Response.BinaryWrite(ebookPart.PartContent);
                        context.Response.End();
                        return;
                    }
                }
            }

            context.Response.StatusCode        = 404;
            context.Response.StatusDescription = "Not Found";
            context.Response.End();
        }
Ejemplo n.º 2
0
 public static async Task <List <Catalog> > GetAll()
 {
     using (DbHelper db = new DbHelper())
     {
         return(await CatalogRepository.GetAll(db));
     }
 }
Ejemplo n.º 3
0
        private void GivenTheCatalogHasBeenCreated(Catalog catalog)
        {
            GivenIdentitySeedsAreReset();
            var repository = new CatalogRepository();

            repository.Create(catalog);
        }
Ejemplo n.º 4
0
        public void Cannot_Update_Catalog_With_Duplicated_Name()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };

            CatalogRepository.Add(catalog);

            var catalog2 = new NoteCatalog
            {
                Name        = "GasLog2",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = false,
                Description = "testing note2"
            };

            CatalogRepository.Add(catalog2);

            catalog.Name = catalog2.Name;

            // Act
            var result = CatalogRepository.Update(catalog);

            // Assert
            Assert.Null(result);
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 5
0
        public void CanNot_Add_Already_Existed_NoteCatalog_To_DataSource()
        {
            // Arrange
            CatalogRepository.Add(new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note",
            });

            var cat = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = false,
                Description = "testing note",
            };

            // Act
            var savedRec = CatalogRepository.Add(cat);

            // Assert
            Assert.Null(savedRec);
            Assert.True(cat.Id <= 0, "cat.Id <=0");
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 6
0
        public void Can_Update_Catalog()
        {
            // Arrange - update name
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };

            CatalogRepository.Add(catalog);

            catalog.Name = "GasLog2";

            // Act
            var result = CatalogRepository.Update(catalog);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("GasLog2", result.Name);

            // Arrange - update description
            catalog.Description = "new testing note";

            // Act
            result = CatalogRepository.Update(catalog);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("new testing note", result.Description);
        }
Ejemplo n.º 7
0
        public void Cannot_Delete_Catalog_With_Note_Associated()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };
            var savedCatalog = CatalogRepository.Add(catalog);

            var note = new HmmNote
            {
                Subject          = "Testing subject",
                Content          = "Testing content",
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Author           = _author,
                Catalog          = savedCatalog
            };

            NoteRepository.Add(note);

            // Act
            var result = CatalogRepository.Delete(catalog);

            // Assert
            Assert.False(result, "Error: deleted catalog with note attached to it");
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 8
0
        public void Cannot_Delete_NonExists_Catalog_From_DataSource()
        {
            // Arrange
            var catalog = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = true,
                Description = "testing note"
            };

            CatalogRepository.Add(catalog);

            var catalog2 = new NoteCatalog
            {
                Name        = "GasLog2",
                Render      = _render,
                Schema      = "TestSchema",
                IsDefault   = false,
                Description = "testing note"
            };

            // Act
            var result = CatalogRepository.Delete(catalog2);

            // Assert
            Assert.False(result);
            Assert.False(CatalogRepository.ProcessMessage.Success);
            Assert.Single(CatalogRepository.ProcessMessage.MessageList);
        }
Ejemplo n.º 9
0
        public void TablatureIdByReferenceTestMethod()
        {
            ICatalogRepository        _repository;
            Dictionary <Guid, string> fileRefs;

            try
            {
                _repository = new CatalogRepository(_fileDirectory);
                Assert.IsNotNull(_repository);

                fileRefs = new Dictionary <Guid, string>();
                fileRefs.Add(new Guid("4BBD4A60-5EDF-40B2-BF91-7687E3A94755"), "francis-cabrel-je-l-aime-a-mourir-guitar-tab");
                fileRefs.Add(new Guid("6d492da3-d317-403f-bb80-ae717370ec88"), "guitar/oasis/dont-look-back-in-anger");

                foreach (KeyValuePair <Guid, string> fileRef in fileRefs)
                {
                    Guid?g = _repository.GetTablatureId(fileRef.Value);

                    Assert.IsNotNull(g);
                    Assert.AreEqual <Guid>(fileRef.Key, g.Value);

                    g = null;
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                fileRefs    = null;
                _repository = null;
            }
        }
Ejemplo n.º 10
0
        public void Cannot_Delete_NoteRender_With_CatalogAssociated()
        {
            // Arrange
            var render = new NoteRender
            {
                Name        = "DefaultRender",
                Namespace   = "NameSpace",
                IsDefault   = true,
                Description = "Description"
            };
            var savedRender = RenderRepository.Add(render);
            var catalog     = new NoteCatalog
            {
                Name        = "GasLog",
                Render      = savedRender,
                Schema      = "Scheme",
                IsDefault   = true,
                Description = "testing Catalog"
            };

            CatalogRepository.Add(catalog);

            // Act
            var result = RenderRepository.Delete(render);

            // Assert
            Assert.False(result, "Error: deleted render with catalog attached to it");
            Assert.False(RenderRepository.ProcessMessage.Success);
            Assert.Single(RenderRepository.ProcessMessage.MessageList);
        }
        public async Task <ActionResult> EditEBook(Guid ebookId)
        {
            using (var db = new EbookManagerDbContext())
            {
                var catalogRepository = new CatalogRepository(db);
                var ebook             = await catalogRepository.GetEbookAsync(ebookId);

                if (ebook == null)
                {
                    throw new HttpException(404, "not found");
                }

                var model = new EditEbookModel();
                model.Id              = ebook.Id;
                model.Summary         = ebook.Summary;
                model.Base64Thumbnail = Convert.ToBase64String(ebook.Thumbnail);
                model.Title           = ebook.Title;
                model.PartsCount      = ebook.Parts.Count;

                foreach (var part in ebook.Parts)
                {
                    model.ExistingParts.Add(EbookPartViewModel.FromEbookPart(part));
                }

                return(View(model));
            }
        }
Ejemplo n.º 12
0
        public void CatalogHierarchyFileTestMethod()
        {
            ICatalogRepository _repository;
            CatalogHierarchyCollectionLevel hierarchyList;

            try
            {
                _repository = new CatalogRepository(_fileDirectory);
                Assert.IsNotNull(_repository);

                hierarchyList = _repository.ListHierarchyLevels();

                Assert.IsNotNull(hierarchyList);
                Assert.IsNotNull(hierarchyList.HierarchyLevels);
                Assert.AreNotEqual <int>(0, hierarchyList.HierarchyLevels.Count());

                foreach (CatalogHierarchyLevel hier in hierarchyList.HierarchyLevels)
                {
                    Assert.AreNotEqual <Guid>(Guid.Empty, hier.Id);
                    Assert.IsNotNull(hier.Name);
                    Assert.AreNotEqual <string>(string.Empty, hier.Name);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                _repository   = null;
                hierarchyList = null;
            }
        }
        public async Task <ActionResult> Add(AddEbookModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new EbookManagerDbContext())
            {
                var catalogRepository = new CatalogRepository(db);
                var ebook             = new Ebook();
                ebook.Id      = Guid.NewGuid();
                ebook.Summary = model.Summary;
                ebook.Title   = model.Title;

                ebook.Thumbnail = new byte[model.Thumbnail.ContentLength];
                model.Thumbnail.InputStream.Read(ebook.Thumbnail, 0, ebook.Thumbnail.Length);

                try
                {
                    await catalogRepository.AddEbookAsync(ebook);

                    return(RedirectToRoute("editEbook", new { ebookId = ebook.Id }));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("InsertError", e);
                    return(View(model));
                }
            }
        }
Ejemplo n.º 14
0
        protected override void OnViewLoaded(object view)
        {
            base.OnViewLoaded(view);

            if (CatalogId <= 0)
            {
                throw new ArgumentException("CatalogId is not set in CatalogPageViewModel.");
            }

            var catalog = CatalogRepository.Get(CatalogId);

            if (catalog == null)
            {
                return;
            }

            CatalogReader = CatalogReaderFactory.Create(catalog);

            if (StartSearch && SavedInTombstone)
            {
                LoadState(ToString());
                if (!string.IsNullOrEmpty(SearchQuery))
                {
                    Search();
                }
            }
        }
Ejemplo n.º 15
0
        public void CatalogReferencesFileTestMethod()
        {
            ICatalogRepository _repository;
            CatalogHierarchyTabReferenceCollection refs;

            try
            {
                _repository = new CatalogRepository(_fileDirectory);
                Assert.IsNotNull(_repository);

                refs = _repository.ListReferences();

                Assert.IsNotNull(refs);
                Assert.IsNotNull(refs.Refs);
                Assert.AreNotEqual <int>(0, refs.Refs.Count());

                foreach (CatalogHierarchyTabReference _ref in refs.Refs)
                {
                    Assert.AreNotEqual <Guid>(Guid.Empty, _ref.Id);
                    Assert.IsNotNull(_ref.Name);
                    Assert.AreNotEqual <string>(string.Empty, _ref.Name);
                    Assert.IsNotNull(_ref.UrlPath);
                    Assert.AreNotEqual <string>(string.Empty, _ref.UrlPath);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
            finally
            {
                refs        = null;
                _repository = null;
            }
        }
Ejemplo n.º 16
0
        public void Can_Update_Note_Catalog()
        {
            // Arrange
            var xmlDoc = new XmlDocument();

            xmlDoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-16\"?><root><time>2017-08-01</time></root>");
            var note = new HmmNote
            {
                Author           = _author,
                Catalog          = _catalog,
                Description      = "testing note",
                CreateDate       = DateTime.Now,
                LastModifiedDate = DateTime.Now,
                Subject          = "testing note is here",
                Content          = xmlDoc.InnerXml
            };

            NoteRepository.Add(note);
            Assert.True(NoteRepository.ProcessMessage.Success);

            // changed the note catalog
            note.Catalog = CatalogRepository.GetEntities().FirstOrDefault(cat => !cat.IsDefault);

            // Act
            var savedRec = NoteRepository.Update(note);

            // Assert
            Assert.NotNull(savedRec);
            Assert.NotNull(savedRec.Catalog);
            Assert.NotNull(note.Catalog);
            Assert.Equal("Gas Log", savedRec.Catalog.Name);
            Assert.Equal("Gas Log", note.Catalog.Name);
        }
Ejemplo n.º 17
0
        protected override void OnViewLoaded(object view)
        {
            base.OnViewLoaded(view);

            if (CatalogId <= 0)
            {
                throw new ArgumentException("CatalogId is not set in CatalogPageViewModel.");
            }

            _catalog = CatalogRepository.Get(CatalogId);
            if (_catalog == null)
            {
                return;
            }

            _catalogAuthorizationService = _catalogAuthorizationFactory.GetAuthorizationService(_catalog);
            NotifyOfPropertyChange("IsAuthorized");

            CatalogReader = CatalogReaderFactory.Create(_catalog);

            if (SavedInTombstone)
            {
                LoadState(ToString());
            }

            LoadItems();
        }
Ejemplo n.º 18
0
        protected List <Catalog> ThenThereShouldBeResults(int expectedCount)
        {
            var repository = new CatalogRepository();
            var entities   = repository.GetAll();

            Assert.Equal(expectedCount, entities.Count);
            return(entities);
        }
Ejemplo n.º 19
0
 public UnitOfWork(SecurityDbContext context)
 {
     _context            = context;
     UserRepository      = new UserRepository(_context);
     UserGroupRepository = new UserGroupRepository(_context);
     CatalogRepository   = new CatalogRepository(_context);
     ResourceRepository  = new ResourceRepository(_context);
     TagRepository       = new TagRepository(_context);
 }
Ejemplo n.º 20
0
 private void SetupTestEnv()
 {
     InsertSeedRecords();
     _validator = new NoteValidator(NoteRepository);
     _author    = AuthorRepository.GetEntities().FirstOrDefault();
     _catalog   = CatalogRepository.GetEntities().FirstOrDefault();
     Assert.NotNull(_author);
     Assert.NotNull(_catalog);
 }
Ejemplo n.º 21
0
        protected void WhenCatalogsAreCreated(params Catalog[] entities)
        {
            var repository = new CatalogRepository();

            foreach (var entity in entities)
            {
                repository.Create(entity);
            }
        }
        public override void OnActionExecuting(HttpActionContext context)
        {
            CatalogRepository catalogRepository = new CatalogRepository(new MyRoomDbContext());
            bool hasChildrens = catalogRepository.HasCatalogChildrens((int)context.ActionArguments["key"]);
            if (!hasChildrens)
                throw new HttpResponseException(context.Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Please, delete the modules childrens"));


        }
Ejemplo n.º 23
0
        public void GetNotExistingProduct()
        {
            var repository = new CatalogRepository();

            //Assert
            var product = repository.GetByName("testtest");

            Assert.IsNotNull(product);
        }
Ejemplo n.º 24
0
        public void can_display_item()
        {
            var session = CustomerSessionService.CustomerSession;

            //Generate data
            const string catalogId = "testcatlog";

            Item[] items = null;
            CreateFullGraphCatalog(catalogId, ref items);
            SqlStoreSampleDatabaseInitializer.CreateFulfillmentCenter((EFStoreRepository)StoreRepository);
            SqlStoreSampleDatabaseInitializer.CreateStores((EFStoreRepository)StoreRepository);

            //Modify data
            var item = items.First();

            item.IsBuyable   = true;
            item.MaxQuantity = 10;
            item.MinQuantity = 1;
            CatalogRepository.Update(item);
            CatalogRepository.UnitOfWork.Commit();

            var priceListAssigment = GeneratePrices(items, catalogId);
            var price = priceListAssigment.Pricelist.Prices.First(x => x.ItemId == item.ItemId);

            //Add price discount 50%
            const int discountPercent = 50;
            var       promotion       = AddCatalogPromotion(catalogId, string.Format(Resources.PromotionExpression_Item0, item.ItemId));

            AddCatalogReward(promotion, discountPercent, RewardAmountType.Relative);


            //var catalog = CatalogRepository.Catalogs.First(x => x.CatalogId == item.CatalogId);
            var category = CatalogRepository.CategoryItemRelations.First(x => x.ItemId == item.ItemId);

            var priceListHelper = Locator.GetInstance <PriceListClient>();

            session.Pricelists = priceListHelper.GetPriceListStack(catalogId, session.Currency, session.GetCustomerTagSet(), false);
            Assert.Equal(priceListAssigment.Pricelist.PricelistId, session.Pricelists[0]);

            session.CatalogId  = catalogId;
            session.CategoryId = category.CategoryId;

            var controller = (CatalogController)DependencyResolver.Current.GetService(typeof(CatalogController));
            var result     = controller.DisplayItem(item.Code) as ViewResult;
            var model      = result.Model as CatalogItemWithPriceModel;

            Assert.Equal(result.ViewName, "Item");                //Default view
            Assert.NotNull(model);
            Assert.NotNull(model.Price);                          // price returned
            Assert.Equal(model.Price.Currency, session.Currency); // curecncy matches
            Assert.Equal(model.Price.SalePrice, price.Sale.Value * discountPercent * 0.01m);
            Assert.True(model.CatalogItem.ItemId.Equals(item.ItemId), "Requested and returned itemId do not match");
            Assert.True(model.Availability.IsAvailable, "Item is not available");             //item is available
        }
        public async Task <ActionResult> ConfirmDelete(Guid ebookId)
        {
            using (var db = new EbookManagerDbContext())
            {
                var catalogRepository = new CatalogRepository(db);
                await catalogRepository.DeleteEbookAsync(ebookId);

                TempData["Success"] = "L'eBook a été supprimé";
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 26
0
        public void AddProductWithoutQuantity()
        {
            var testObject = new Product()
            {
                Name = "nametestproduct", Description = "this is a test"
            };

            var repository = new CatalogRepository();

            repository.Create(testObject);
        }
Ejemplo n.º 27
0
        public async Task <HttpResponseMessage> GetEbooks()
        {
            using (var db = new EbookManagerDbContext())
            {
                var userName          = "******";
                var catalogRepository = new CatalogRepository(db);
                var userEbooks        = await catalogRepository.LoadUserCatalog(userName);

                return(Request.CreateResponse(HttpStatusCode.OK, userEbooks));
            }
        }
        public async Task <ActionResult> EditEBook(EditEbookModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new EbookManagerDbContext())
            {
                var catalogRepository = new CatalogRepository(db);
                var ebook             = await catalogRepository.GetEbookAsync(model.Id);

                if (ebook == null)
                {
                    throw new HttpException(404, "not found");
                }

                ebook.Title   = model.Title;
                ebook.Summary = model.Summary;

                if (model.Thumbnail != null)
                {
                    ebook.Thumbnail = new byte[model.Thumbnail.ContentLength];
                    model.Thumbnail.InputStream.Read(ebook.Thumbnail, 0, ebook.Thumbnail.Length);
                }

                if (model.Parts != null)
                {
                    foreach (var part in model.Parts)
                    {
                        if (part == null)
                        {
                            continue;
                        }

                        var ebookPart = new EbookPart();
                        ebookPart.EbookId     = ebook.Id;
                        ebookPart.PartContent = new byte[part.ContentLength];
                        part.InputStream.Read(ebookPart.PartContent, 0, ebookPart.PartContent.Length);
                        ebookPart.Position    = ebook.Parts.Count;
                        ebookPart.ContentType = part.ContentType;
                        ebookPart.FileName    = System.IO.Path.GetFileName(part.FileName);

                        ebook.Parts.Add(ebookPart);
                    }
                }

                await catalogRepository.UpdateBookAsync(ebook);

                TempData["Success"] = "L'eBook a été sauvegardé";
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 29
0
        public async Task <HttpResponseMessage> GetMyEbooks()
        {
            using (var db = new EbookManagerDbContext())
            {
                var userName = User.Identity.Name;

                var catalogRepository = new CatalogRepository(db);
                var ebooks            = await catalogRepository.LoadUserCatalogWithPartCount(userName);

                return(Request.CreateResponse(ebooks.Select(e => new { Id = e.Item1.Id, Summary = e.Item1.Summary, Title = e.Item1.Title, Thumbnail = e.Item1.Thumbnail, PartCount = e.Item2 })));
            }
        }
Ejemplo n.º 30
0
        // GET api/<controller>
        public CatalogListModel <PackageInfo> Get(int page, int rows)
        {
            int totalRecords;
            var model = new CatalogListModel <PackageInfo>
            {
                Page    = page,
                Records = rows,
                Rows    = CatalogRepository.Search <PackageInfo>(string.Empty, page, rows, out totalRecords),
                Total   = (totalRecords / rows) + 1,
            };

            return(model);
        }
Ejemplo n.º 31
0
 public async Task <HttpResponseMessage> GetEbookPart(Guid ebookId, int index)
 {
     using (var db = new EbookManagerDbContext())
     {
         var catalogRepository = new CatalogRepository(db);
         var part     = catalogRepository.GetEbookPart(ebookId, index);
         var response = new HttpResponseMessage(HttpStatusCode.OK);
         response.Content = new ByteArrayContent(part.PartContent);
         response.Content.Headers.ContentLength = part.PartContent.Length;
         response.Content.Headers.ContentType   = new System.Net.Http.Headers.MediaTypeHeaderValue(part.ContentType);
         return(response);
     }
 }