public void GetProducts(int savedItems, string filter, int pageIndex, int pageSize, int totalItems, int renderedItems)
        {
            List <Product>       modelsToSave = new List <Product>();
            IItemsList <Product> productsList = null;

            for (int i = 1; i <= savedItems; i++)
            {
                Product model = this.CreateDefaultModel();

                model.Name           = model.Name + $" { i.ToString() }";
                model.Description    = model.Description + $" { i.ToString() }";
                model.AgeRestriction = model.AgeRestriction + i;
                model.Company        = model.Company + $" { i.ToString() }";
                model.Price          = model.Price + i;

                modelsToSave.Add(model);
            }

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(CreateUpdatesSavedEntityId))))
            {
                modelsToSave.ForEach(x => { uow.Products.Add(x); uow.Complete(); });
                productsList = uow.Products.GetProducts(filter, pageIndex, pageSize);

                Assert.Equal(totalItems, productsList.TotalItemsCount);
                Assert.Equal(renderedItems, productsList.RenderedItemsCount);
                Assert.Equal(renderedItems, productsList.Items.Count());
            }
        }
Ejemplo n.º 2
0
        public void UpdatesSavesAllowedFields()
        {
            Product originalModel   = this.CreateDefaultModel();
            Product savedModel      = this.CreateDefaultModel();
            string  updatedPostfix  = "-Modified";
            int     updatedIcrement = 1;

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(UpdatesSavesAllowedFields))))
            {
                uow.Products.Add(savedModel);
                uow.Complete();

                savedModel.Name           = originalModel.Name + updatedPostfix;
                savedModel.Description    = originalModel.Description + updatedPostfix;
                savedModel.AgeRestriction = originalModel.AgeRestriction + updatedIcrement;
                savedModel.Company        = originalModel.Company + updatedPostfix;
                savedModel.Price          = originalModel.Price + updatedIcrement;
                uow.Complete();

                savedModel = uow.Products.Get(savedModel.ProductId);

                Assert.Equal(originalModel.Name + updatedPostfix, savedModel.Name);
                Assert.Equal(originalModel.Description + updatedPostfix, savedModel.Description);
                Assert.Equal(originalModel.AgeRestriction + updatedIcrement, savedModel.AgeRestriction);
                Assert.Equal(originalModel.Company + updatedPostfix, savedModel.Company);
                Assert.Equal(originalModel.Price + updatedIcrement, savedModel.Price);
            }
        }
        public void CreateUpdatesSavedEntityId()
        {
            List <Product> models = new List <Product>();

            for (int i = 1; i <= 5; i++)
            {
                Product model = this.CreateDefaultModel();

                model.Name           = model.Name + $" { i.ToString() }";
                model.Description    = model.Description + $" { i.ToString() }";
                model.AgeRestriction = model.AgeRestriction + i;
                model.Company        = model.Company + $" { i.ToString() }";
                model.Price          = model.Price + i;

                models.Add(model);
            }

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(CreateUpdatesSavedEntityId))))
            {
                int previousId = 0;

                models.ForEach
                (
                    x =>
                {
                    uow.Products.Add(x);
                    uow.Complete();
                    Assert.True(x.ProductId > previousId);
                    previousId = x.ProductId;
                }
                );
            }
        }
Ejemplo n.º 4
0
        public void GetAllFetchsAnExistingEntities()
        {
            int modelsToSave = 10;
            int savedModels  = 0;

            List <Product> models = new List <Product>();

            for (int i = 1; i <= modelsToSave; i++)
            {
                Product model = this.CreateDefaultModel();

                model.Name           = model.Name + $" { i.ToString() }";
                model.Description    = model.Description + $" { i.ToString() }";
                model.AgeRestriction = model.AgeRestriction + i;
                model.Company        = model.Company + $" { i.ToString() }";
                model.Price          = model.Price + i;

                models.Add(model);
            }

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(CreateUpdatesSavedEntityId))))
            {
                models.ForEach
                (
                    x =>
                {
                    uow.Products.Add(x);
                    uow.Complete();
                }
                );

                savedModels = uow.Products.GetAll().Count();
                Assert.Equal(modelsToSave, savedModels);
            }
        }
Ejemplo n.º 5
0
        public void CreateSavesSingleRecordOnDatabase()
        {
            int expectedSavedModelsCount = 1;
            int savedModelsCount         = 0;

            Product modelToSave = this.CreateDefaultModel();

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(CreateSavesSingleRecordOnDatabase))))
            {
                uow.Products.Add(modelToSave);
                uow.Complete();

                savedModelsCount = uow.Products.GetAll().Count();
                Assert.Equal(expectedSavedModelsCount, savedModelsCount);
            }
        }
Ejemplo n.º 6
0
        public void GetFetchsAnExistingEntity()
        {
            Product modelToSave = this.CreateDefaultModel();
            Product savedModel  = null;

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(GetFetchsAnExistingEntity))))
            {
                uow.Products.Add(modelToSave);
                uow.Complete();

                savedModel = uow.Products.Get(modelToSave.ProductId);
                Assert.NotNull(savedModel);

                Assert.Equal(modelToSave.Name, savedModel.Name);
                Assert.Equal(modelToSave.Description, savedModel.Description);
                Assert.Equal(modelToSave.AgeRestriction, savedModel.AgeRestriction);
                Assert.Equal(modelToSave.Company, savedModel.Company);
                Assert.Equal(modelToSave.Price, savedModel.Price);
            }
        }
Ejemplo n.º 7
0
        public void RemoveDeletesEntityFromDatabase()
        {
            Product model             = this.CreateDefaultModel();
            int     beforeRemoveCount = 0;
            int     afterDeleteCount  = 0;

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(RemoveDeletesEntityFromDatabase))))
            {
                uow.Products.Add(model);
                uow.Complete();

                beforeRemoveCount = uow.Products.GetAll().Count();

                uow.Products.Remove(model);
                uow.Complete();

                afterDeleteCount = uow.Products.GetAll().Count();

                Assert.Equal(beforeRemoveCount - 1, afterDeleteCount);
            }
        }
Ejemplo n.º 8
0
        public void CreateSavesToDatabase()
        {
            Product defaultModel = this.CreateDefaultModel();
            Product modelToSave  = this.CreateDefaultModel();
            Product savedModel   = null;

            using (UnitOfWork uow = new UnitOfWork(UnoSquareContextFactory.Create(nameof(CreateSavesToDatabase))))
            {
                uow.Products.Add(modelToSave);
                uow.Complete();

                // get entity from db
                savedModel = uow.Products.Get(modelToSave.ProductId);
                Assert.NotNull(savedModel);

                Assert.Equal(defaultModel.Name, savedModel.Name);
                Assert.Equal(defaultModel.Description, savedModel.Description);
                Assert.Equal(defaultModel.AgeRestriction, savedModel.AgeRestriction);
                Assert.Equal(defaultModel.Company, savedModel.Company);
                Assert.Equal(defaultModel.Price, savedModel.Price);
            }
        }