Exemplo n.º 1
0
        public static void ImportFromExcel(string path)
        {
            List <ArticleModel> ArticlesFromExcel = ExcelEditor.ArticlesFromExcel(path);

            CheckAndCreateReferences(ArticlesFromExcel);
            SQLiteConnection con   = new SQLiteConnection(InventoryDBSqliteConnection.LoadConnectionString());
            string           query = "INSERT INTO Articles (ArticleID, Description, ID_Category, Pricing, Quantity, ID_Project, SupplierPartNumber, ManufacturerPartNumber, ID_Manufacturer, ID_Supplier, ID_Status, Created, LastUpdate, ID_Location) VALUES (@ArticleID, @Description, @ID_Category, @Pricing, @Quantity, @ID_Project, @SupplierPartNumber, @ManufacturerPartNumber, @ID_Manufacturer, @ID_Supplier, @ID_Status, @Created, @LastUpdate, @ID_Location)";
            SQLiteCommand    cmd   = new SQLiteCommand(query, con);

            con.Open();
            foreach (ArticleModel article in ArticlesFromExcel)
            {
                if (ArticleController.checkSupplierAndManufacturerPartNumber(article.ManufacturerPartNumber, article.SupplierPartNumber).Count == 0)
                {
                    cmd.Parameters.AddWithValue("@ArticleID", article.ArticleID);
                    cmd.Parameters.AddWithValue("@Description", article.Description);
                    cmd.Parameters.AddWithValue("@ID_Category", getThreeDigits(article.ArticleID.ToString()));
                    cmd.Parameters.AddWithValue("@Pricing", article.Pricing);
                    cmd.Parameters.AddWithValue("@Quantity", article.Quantity);
                    cmd.Parameters.AddWithValue("@ID_Project", article.ID_Project);
                    cmd.Parameters.AddWithValue("@SupplierPartNumber", article.SupplierPartNumber);
                    cmd.Parameters.AddWithValue("@ManufacturerPartNumber", article.ManufacturerPartNumber);
                    cmd.Parameters.AddWithValue("@ID_Manufacturer", ManufacturerController.getManufacturerID(article.Manufacturer));
                    cmd.Parameters.AddWithValue("@ID_Supplier", SupplierController.getSupplierID(article.Supplier));
                    cmd.Parameters.AddWithValue("@ID_Status", StatusController.getStatusID(article.Status));
                    cmd.Parameters.AddWithValue("@Created", article.Created);
                    cmd.Parameters.AddWithValue("@LastUpdate", DateTime.Now.ToString("dd/MM/yyyy"));
                    cmd.Parameters.AddWithValue("@ID_Location", LocationController.getLocationID(article.Location));
                    cmd.ExecuteNonQuery();
                }
            }
            con.Close();
            MessageBox.Show("Import done succesfully, Please restart the Application");
            //MessageBox.Show(article.ArticleID + ": " + article.Description + " was added successfully");
        }
        public async Task Delete_manufacturer_response_bad_request_with_message_when_manufacturer_hooked_with_product()
        {
            var cancellationToken = new CancellationToken();

            var expectedManufacturer =
                await _catalogContextFixture.Context.Manufacturers.ToListAsync(cancellationToken);

            if (expectedManufacturer.IsNullOrEmpty())
            {
                expectedManufacturer = await SeedManufacturer(cancellationToken);
            }

            Assert.NotEmpty(expectedManufacturer);

            var id = (await _catalogContextFixture.Context.Manufacturers.FirstOrDefaultAsync(
                          cancellationToken)).Id;
            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response = await manufacturerController.DeleteManufacturerAsync(id, cancellationToken);

            var responseMessage = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Contains("Message", responseMessage.Value.ToString());
        }
Exemplo n.º 3
0
        public async Task Should_AttachPicture_Returns200()
        {
            //arrange
            var addedPicture = await AddPicture();

            var manufacturerBeforeAttachedPicture = await CreateManufacturer();

            //act
            var attachResponse = await Client.PostAsJsonAsync(ManufacturerController.AttachPicture(manufacturerBeforeAttachedPicture.Id, addedPicture.Id),
                                                              new { });

            var manufacturerAfterAttachedPicture = await GetManufacturer(manufacturerBeforeAttachedPicture.Id);

            //assert
            attachResponse.StatusCode.Should().Be(HttpStatusCode.OK);
            manufacturerBeforeAttachedPicture.Id.Should().NotBeEmpty();
            manufacturerBeforeAttachedPicture.Description.Should().NotBeEmpty();
            manufacturerBeforeAttachedPicture.Name.Should().NotBeEmpty();
            manufacturerBeforeAttachedPicture.Pictures.Should().HaveCount(0);

            manufacturerAfterAttachedPicture.Id.Should().NotBeEmpty();
            manufacturerAfterAttachedPicture.Description.Should().NotBeEmpty();
            manufacturerAfterAttachedPicture.Name.Should().NotBeEmpty();
            manufacturerAfterAttachedPicture.Pictures.Should().HaveCount(1);

            var picture = manufacturerAfterAttachedPicture.Pictures.First();

            picture.Id.Should().Be(addedPicture.Id);
            picture.Description.Should().Be(addedPicture.Description);
            picture.Url.Should().Be(addedPicture.Url);
            picture.FileName.Should().Be(addedPicture.FileName);
            picture.MimeTypeId.Should().Be(addedPicture.MimeTypeId);
            picture.PictureAddedAt.Should().BeCloseTo(addedPicture.PictureAddedAt, TimeSpan.FromSeconds(1));
            picture.FileStorageUploadId.Should().Be(addedPicture.FileStorageUploadId);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var carController          = new CarsController();
            var detailController       = new DetailsController();
            var manufacturerController = new ManufacturerController();
            var manufacturerService    = new ManufacturerService();
            //var allCars = carController.GetAll();
            //var carById = carController.GetId(1);
            var allDetails = detailController.GetAll();

            //var detailById = detailController.GetId(2);
            //detailController.Insert(null);
            //detailController.Update(null);
            //detailController.Delete(1002);


            carController.Add(null);
            //carController.Update(null);
            //carController.Delete(6);

            var allManufacturers = manufacturerController.GetAll();
            //var richcars = manufacturerController.GetRich();
            var mostexpensive = manufacturerService.GetMostExpensive();

            Console.ReadKey();
        }
        Update_manufacturer_response_bad_request_with_message_when_item_image_url_or_image_name_is_not_provided()
        {
            var cancellationToken = new CancellationToken();
            // Arrange
            var expectedManufacturer =
                await _catalogContextFixture.Context.Manufacturers.ToListAsync(cancellationToken);

            if (expectedManufacturer.IsNullOrEmpty())
            {
                expectedManufacturer = await SeedManufacturer(cancellationToken);
            }

            Assert.NotEmpty(expectedManufacturer);

            // ReSharper disable once PossibleNullReferenceException
            var id = expectedManufacturer[0].Id;

            expectedManufacturer[0].ImageName = "";
            expectedManufacturer[0].ImageUrl  = "";
            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response =
                await manufacturerController.UpdateManufacturerAsync(id, expectedManufacturer[0], cancellationToken);

            var responseMessage = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Contains("Message", responseMessage.Value.ToString());
        }
        public async Task Update_manufacturer_response_not_found_with_message_when_item_not_exists()
        {
            var cancellationToken = new CancellationToken();
            // Arrange
            var expectedManufacturer =
                await _catalogContextFixture.Context.Manufacturers.ToListAsync(cancellationToken);

            if (expectedManufacturer.IsNullOrEmpty())
            {
                expectedManufacturer = await SeedManufacturer(cancellationToken);
            }

            Assert.NotEmpty(expectedManufacturer);

            // ReSharper disable once PossibleNullReferenceException
            var id = expectedManufacturer.LastOrDefault().Id++;

            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response =
                await manufacturerController.UpdateManufacturerAsync(id, expectedManufacturer[0], cancellationToken);

            var responseMessage = Assert.IsType <NotFoundObjectResult>(response);

            Assert.Contains("Message", responseMessage.Value.ToString());
        }
Exemplo n.º 7
0
        public void CanGetListOfManufacturers_ReturnListOfManufaturers()
        {
            //Arrange

            Mock <IManufacturerRepository> manufacturerMock = new Mock <IManufacturerRepository>();

            manufacturerMock.Setup(m => m.Manufacturers).Returns(new Manufacturer[] {
                new Manufacturer {
                    ManufacturerId = 1, Name = "Avon"
                },
                new Manufacturer {
                    ManufacturerId = 2, Name = "PJM"
                },
                new Manufacturer {
                    ManufacturerId = 1, Name = "Valvex"
                }
            }.AsQueryable <Manufacturer>());

            ManufacturerController manufacturerController = new ManufacturerController(manufacturerMock.Object);

            //Act
            Manufacturer[] result = GetViewModel <IQueryable <Manufacturer> >(manufacturerController.List()).ToArray();

            //Assert

            Assert.Equal(3, result.Length);
            Assert.Equal("Avon", result[0].Name);
            Assert.Equal("PJM", result[1].Name);
            Assert.Equal("Valvex", result[2].Name);
        }
Exemplo n.º 8
0
 public ManufacturerControllerTests()
 {
     _mock.Setup(c => c.Manufacturers).Returns(new List <Manufacturer>()
     {
         new Manufacturer()
         {
             Id      = 1,
             Name    = "Adidas",
             Country = "England",
         },
         new Manufacturer()
         {
             Id      = 2,
             Name    = "Nike",
             Country = "China",
         },
         new Manufacturer()
         {
             Id      = 3,
             Name    = "Reebok",
             Country = "Germany",
         },
     }.AsQueryable());
     _controller = new ManufacturerController(_mock.Object);
 }
        public void IndexExceptionCase()
        {
            #region
            mockManufacturerRepository = new Mock <IManufacturerRepository>();

            // Prepare the return data for GetAllQuotation() method.
            var manufacturerList = new List <Manufacture>();
            manufacturerList.Add(new Manufacture {
                Manufacturer_Id = 1, Manufacturer_Name = "Sony"
            });

            // Mock up the GetAllQuotation() repository method with expected return values.
            mockManufacturerRepository.Setup(m => m.GetAllManufacturer()).Returns(manufacturerList);


            manufacturercontroller = new ManufacturerController(mockManufacturerRepository.Object);
            #endregion

            // Now invoke the Index action.
            var actionResult = manufacturercontroller.Index("test", "test") as ViewResult;

            // Validate the expected result.
            ViewResult expectedResult = new ViewResult();
            Assert.IsNotNull("Error", actionResult.ViewName);
        }
Exemplo n.º 10
0
 //Fill the full suggestion list with manufacturer names
 private void OnFocus_ManufacturerShowFullSuggestionList(object sender, RoutedEventArgs e)
 {
     tvrCategory.Visibility                = Visibility.Hidden;
     listfullSuggestions.Visibility        = Visibility.Visible;
     listfullSuggestions.DisplayMemberPath = "Name";
     listfullSuggestions.SelectedValuePath = "Name";
     listfullSuggestions.ItemsSource       = ManufacturerController.getManufacturerList();
     itsME = "Manufacturer";
 }
Exemplo n.º 11
0
        /// <summary>
        /// Loads the manufacturer.
        /// </summary>
        private void LoadManufacturer()
        {
            ManufacturerCollection manufacturerCollection = new ManufacturerController().FetchAll();

            manufacturerCollection.OrderByAsc(Manufacturer.Columns.Name);
            ddlManufacturer.DataSource     = manufacturerCollection;
            ddlManufacturer.DataTextField  = Manufacturer.Columns.Name;
            ddlManufacturer.DataValueField = Manufacturer.Columns.ManufacturerId;
            ddlManufacturer.DataBind();
        }
Exemplo n.º 12
0
        public void firstTest()
        {
            var manufacturerRepo = new ManufacturerRepo(db);
            var controller       = new ManufacturerController(db);
            int expected         = 3;
            var viewResult       = Assert.IsType <ViewResult>(controller.Index());
            var model            = Assert.IsType <List <Manufacturer> >(viewResult.Model);
            int actual           = model.Count;

            Assert.Equal(expected, actual);
        }
Exemplo n.º 13
0
        private async Task <ManufacturerViewModel> GetManufacturer(Guid id)
        {
            var httpResponse = await Client.GetAsync(ManufacturerController.Get(id));

            var manufacturer = await httpResponse
                               .Content
                               .ReadAsJsonAsync <ManufacturerViewModel>();

            httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);

            return(manufacturer);
        }
        Get_manufacturer_list_response_bad_request_with_message_when_pagination_index_is_negative_or_page_size_zero_or_negative()
        {
            var cancellationToken = new CancellationToken();

            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response = await manufacturerController.GetListManufacturersAsync(cancellationToken, 0, -10);

            var responseMessage = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Contains("Message", responseMessage.Value.ToString());
        }
        public async Task Post_manufacturer_response_bad_request_with_message_when_manufacturer_null()
        {
            var cancellationToken = new CancellationToken();

            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response = await manufacturerController.AddNewManufacturerAsync(null, cancellationToken);

            var badRequestResponse = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Contains("Message", badRequestResponse.Value.ToString());
        }
Exemplo n.º 16
0
        /// <summary>
        /// Loads the manufacturers.
        /// </summary>
        private void LoadManufacturers()
        {
            ManufacturerCollection manufacturerCollection = new ManufacturerController().FetchAll();

            if (manufacturerCollection.Count > 0)
            {
                dgManufacturers.DataSource            = manufacturerCollection;
                dgManufacturers.ItemDataBound        += new DataGridItemEventHandler(dgManufacturers_ItemDataBound);
                dgManufacturers.Columns[0].HeaderText = LocalizationUtility.GetText("hdrDelete");
                dgManufacturers.Columns[1].HeaderText = LocalizationUtility.GetText("hdrName");
                dgManufacturers.DataBind();
            }
        }
        public async Task Get_manufacturer_image_by_id_response_bad_request_with_message_when_id_less_or_equals_zero()
        {
            var id = 0;
            var cancellationToken = new CancellationToken();

            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response = await manufacturerController.GetManufacturerImageAsync(id, cancellationToken);

            var responseMessage = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Contains("Message", responseMessage.Value.ToString());
        }
Exemplo n.º 18
0
        private async Task <ManufacturerViewModel> CreateManufacturer()
        {
            var name        = Guid.NewGuid().ToString();
            var description = Guid.NewGuid().ToString();
            var command     = new CreateManufacturerCommand(name, description);

            const HttpStatusCode expectedStatusCode = HttpStatusCode.Created;

            var response = await Client.PostAsJsonAsync(ManufacturerController.Create(), command);

            response.StatusCode.Should().Be(expectedStatusCode);

            return(await response.Content.ReadAsJsonAsync <ManufacturerViewModel>());
        }
Exemplo n.º 19
0
        public void SetupContext()
        {
            MockHelpers.MockUserManager <ApplicationUser>();
            _mockRepositoryManufacturer = new Mock <IManufacturRepository>();
            _manufacturerController     = new ManufacturerController(_dbContext, _mockRepositoryManufacturer.Object);

            _manufacturers = new List <Manufacturer>
            {
                new Manufacturer {
                    ManufacturerId = 1, Name = "DJI", IsActive = true
                },
                new Manufacturer {
                    ManufacturerId = 2, Name = "GoPro", IsActive = false
                }
            };
        }
Exemplo n.º 20
0
        public async Task Should_GetList_Returns200()
        {
            //arrange
            const int pageSize  = 25;
            const int pageIndex = 0;

            //act
            var httpResponse = await Client.GetAsync(ManufacturerController.GetList());

            var manufacturers = await httpResponse
                                .Content
                                .ReadAsJsonAsync <PaginatedItems <CategoryViewModel> >();

            //assert
            manufacturers.PageSize.Should().Be(pageSize);
            manufacturers.PageIndex.Should().Be(pageIndex);
            manufacturers.Data.Should().HaveCount(GlobalConstants.ProductServiceManufacturersSeeded);
        }
Exemplo n.º 21
0
 //Fill the autocomple suggestion list and fill it with manufacturer
 private void AutoCompleteManufacturer(object sender, KeyEventArgs e)
 {
     if (txtManufacturer.Text != "" && ManufacturerController.searchManufacturer(txtManufacturer.Text).Count > 0)
     {
         listSuggestions.ItemsSource = ManufacturerController.searchManufacturer(txtManufacturer.Text);
         itsME = "Manufacturer";
         Thickness margin = listSuggestions.Margin;
         margin.Top                 = 95;
         listSuggestions.Margin     = margin;
         listSuggestions.Visibility = Visibility.Visible;
         if (e.Key == Key.Down)
         {
             listSuggestions.Focus();
         }
     }
     else
     {
         listSuggestions.Visibility = Visibility.Hidden;
     }
 }
Exemplo n.º 22
0
        public void TestManufacturerDelete()
        {
            // Arrange
            var fakeManufacturer = FakeManufacturers().First();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Manufacturer.DeleteById(fakeManufacturer.Id));

            var controller = new ManufacturerController(mockBusinessLogic.Object);

            // Act
            var result = controller.Delete(fakeManufacturer.Id);

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Exemplo n.º 23
0
        public void TestManufacturerGetByIdNotFound()
        {
            // Arrange
            var id = Guid.NewGuid();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Manufacturer.GetById(id))
            .Returns(null as Manufacturer);

            var controller = new ManufacturerController(mockBusinessLogic.Object);

            // Act
            var result = controller.Get(id);

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
Exemplo n.º 24
0
        public async Task Should_GetCount_Returns200()
        {
            //arrange
            var httpResponseList = await Client.GetAsync(ManufacturerController.GetList());

            var manufacturers = await httpResponseList
                                .Content
                                .ReadAsJsonAsync <PaginatedItems <ManufacturerViewModel> >();

            var listCount = manufacturers.Data.Count();

            //act
            var httpResponseCount = await Client.GetAsync(ManufacturerController.Count());

            var manufacturersCount = await httpResponseCount
                                     .Content
                                     .ReadAsJsonAsync <int>();

            //assert
            manufacturersCount.Should().Be(listCount);
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            var detailController       = new DetailsController();
            var carsController         = new CarsController();
            var manufacturerController = new ManufacturerController();

            var det      = detailController.GetDetails();
            var vehicles = carsController.GetСars();

            var carViewModel = new CarViewModel()
            {
                Id   = 6,
                Name = "PAZIK",
            };

            var hz = detailController.GetDetails();

            var getmanufacturer = manufacturerController.GetAll();

            var getall = manufacturerController.GetCarManufacturerModels();
        }
Exemplo n.º 26
0
        public static void CheckAndCreateReferences(List <ArticleModel> ArticlesFromExcel)
        {
            foreach (ArticleModel article in ArticlesFromExcel)
            {
                if (ManufacturerController.getManufacturerID(article.Manufacturer) == 0)
                {
                    ManufacturerModel manufacturer = new ManufacturerModel()
                    {
                        Name = article.Manufacturer
                    };
                    ManufacturerController.addManufacturer(manufacturer);
                }
                if (SupplierController.getSupplierID(article.Supplier) == 0)
                {
                    SupplierModel supplier = new SupplierModel()
                    {
                        Name = article.Supplier
                    };
                    SupplierController.addSupplier(supplier);
                }

                if (LocationController.getLocationID(article.Location) == 0)
                {
                    LocationModel location = new LocationModel()
                    {
                        Location = article.Location
                    };
                    LocationController.addLocation(location);
                }
                if (StatusController.getStatusID(article.Status) == 0)
                {
                    StatusModel status = new StatusModel()
                    {
                        Status = article.Status
                    };
                    StatusController.addStatus(status);
                }
            }
        }
Exemplo n.º 27
0
        public void TestManufacturerAll()
        {
            // Arrange
            var expectedManufacturers = FakeManufacturers();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Manufacturer.All())
            .Returns(expectedManufacturers);

            var controller = new ManufacturerController(mockBusinessLogic.Object);

            // Act
            var obtainedManufacturers = controller.Get();

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsNotNull(obtainedManufacturers);
            Assert.AreEqual(expectedManufacturers.Count(), obtainedManufacturers.Count());
        }
        public async Task Post_manufacturer_response_bad_request_with_message_when_manufacturer_exists()
        {
            var cancellationToken = new CancellationToken();
            //Arrange
            var expectedManufacturer =
                await _catalogContextFixture.Context.Manufacturers.ToListAsync(cancellationToken);

            if (expectedManufacturer.IsNullOrEmpty())
            {
                expectedManufacturer = await SeedManufacturer(cancellationToken);
            }

            // Act
            var manufacturerController = new ManufacturerController(_catalogContextFixture.Context,
                                                                    _fileUtilityFixture.FileUtility, _settings);
            var response =
                await manufacturerController.AddNewManufacturerAsync(expectedManufacturer[0], cancellationToken);

            var badRequestResponse = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Contains("Message", badRequestResponse.Value.ToString());
        }
Exemplo n.º 29
0
        public void TestManufacturerCreate()
        {
            // Arrange
            var fakeManufacturer = FakeManufacturers().First();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Manufacturer.Create(fakeManufacturer))
            .Returns(fakeManufacturer.Id);

            var controller = new ManufacturerController(mockBusinessLogic.Object);

            // Act
            var result = controller.Post(fakeManufacturer);
            var createdManufacturerCode = (result as OkNegotiatedContentResult <Guid>).Content;

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsNotNull(createdManufacturerCode);
            Assert.AreEqual(fakeManufacturer.Id, createdManufacturerCode);
        }
Exemplo n.º 30
0
        public void TestManufacturerGetById()
        {
            // Arrange
            var expectedManufacturer = FakeManufacturers().First();

            var mockBusinessLogic = new Mock <ISportStoreBusinessLogic>();

            mockBusinessLogic
            .Setup(bl => bl.Manufacturer.GetById(expectedManufacturer.Id))
            .Returns(expectedManufacturer);

            var controller = new ManufacturerController(mockBusinessLogic.Object);

            // Act
            var result = controller.Get(expectedManufacturer.Id);
            var obtainedManufacturer = (result as OkNegotiatedContentResult <Manufacturer>).Content;

            // Assert
            mockBusinessLogic.VerifyAll();

            Assert.IsNotNull(obtainedManufacturer);
            Assert.AreEqual(expectedManufacturer.Id, obtainedManufacturer.Id);
        }