Exemplo n.º 1
0
        public void Shop_Returns_With_Correct_View()
        {
            //Arange
            var product_data_mock = new Mock <IProductData>();

            var products = new[] {
                new ProductDTO(1, "Product_1", 1, 10m, "img_1.png", new BrandDTO(1, "Brand_1", 1, 1), new SectionDTO(1, "Section_1", 1, null)),
                new ProductDTO(2, "Product_2", 1, 20m, "img_2.png", new BrandDTO(2, "Brand_2", 2, 1), new SectionDTO(2, "Section_2", 2, null)),
                new ProductDTO(3, "Product_3", 1, 30m, "img_3.png", new BrandDTO(3, "Brand_3", 3, 1), new SectionDTO(3, "Section_3", 3, null)),
            };

            int expected_product_count = 3;
            int expected_brand_id      = 4;
            int expected_section_id    = 2;

            product_data_mock.Setup(p => p.GetProducts(It.IsAny <ProductFilter>())).Returns(() => products);

            //Act
            CatalogueController controller = new CatalogueController(product_data_mock.Object);

            //Assert
            ViewResult viewResult = Xunit.Assert.IsType <ViewResult>(controller.Shop(expected_brand_id, expected_section_id));

            var model = Xunit.Assert.IsAssignableFrom <CatalogueViewModel>(viewResult.Model);

            Assert.AreEqual(expected_product_count, model.Products.ToList().Count);
            Assert.AreEqual(expected_brand_id, model.BrandId);
            Assert.AreEqual(expected_section_id, model.SectionId);
        }
Exemplo n.º 2
0
        // Catalogues
        private void btnCataloguesSave_Click(object sender, EventArgs e)
        {
            // Valiations:

            if (tbCataloguesShortName.Text.Length == 0)
            {
                errorProvider.SetError(tbCataloguesShortName, "Must provide a value.");
            }
            else
            {
                errorProvider.SetError(tbCataloguesShortName, "");
            }

            // Save new/changes:

            int    id        = 0;
            string shortName = tbCataloguesShortName.Text;
            string longName  = tbCataloguesLongName.Text;

            if (emCatalogues == EditingModes.Add)
            {
                id = 0;
            }
            else
            {
                id = currentCatalogue.Id;
            }

            Catalogue candidate = new Catalogue(id, shortName, longName);

            if (emCameras == EditingModes.Add)
            {
                id = CatalogueController.AddCatalogue(candidate);
            }
            else
            {
                CatalogueController.EditCatalogue(id, candidate);
            }

            // Reload data:

            lblStatus.Text   = "Issuing catalogue saving command... ";
            currentCatalogue = CatalogueController.GetCatalogues(new List <int>()
            {
                id
            })[0];
            LoadCatalogueData(currentCatalogue);
            PrepareDataLists();
            lblStatus.Text += "Complete.";
        }
Exemplo n.º 3
0
        public void Details_Returns_With_Correct_View()
        {
            //Arange
            var product_data_mock = new Mock <IProductData>();

            const int     expected_product_id    = 1;
            const decimal expected_product_price = 10m;

            var expected_product_name  = $"Name_{expected_product_id}";
            var expected_product_image = $"img{expected_product_id}.png";
            var expected_brand_name    = $"Brand of product {expected_product_id}";
            var expected_section_name  = $"Section of product {expected_product_id}";

            product_data_mock.Setup(p => p.GetProductById(It.IsAny <int>()))
            .Returns <int>(id => new ProductDTO(
                               id,
                               $"Name_{id}",
                               1,
                               expected_product_price,
                               $"img{id}.png",
                               new BrandDTO(1, $"Brand of product {id}", 1, 1),
                               new SectionDTO(1, $"Section of product {id}", 1, null)
                               ));

            //Act
            var controller = new CatalogueController(product_data_mock.Object);

            //Assert
            Assert.IsInstanceOfType(controller.Details(expected_product_id), typeof(ViewResult));
            var model = (controller.Details(expected_product_id) as ViewResult).Model as ProductViewModel;

            Assert.AreEqual(model.Id, expected_product_id);
            Assert.AreEqual(model.Name, expected_product_name);
            Assert.AreEqual(model.Price, expected_product_price);
            Assert.AreEqual(model.ImageUrl, expected_product_image);
            Assert.AreEqual(model.Brand, expected_brand_name);
        }
Exemplo n.º 4
0
 public CatalogueControllerTests()
 {
     controller = new CatalogueController(new СatalogueService("Server=gsqldev;Database=Garage-Dev;User Id=appLogin;Password = Pa$$W0rd!"));
 }
Exemplo n.º 5
0
 private void ProvisonNewController()
 {
     _controller = new CatalogueController(provider.GetService(typeof(UnitOfWork)) as UnitOfWork);
 }
Exemplo n.º 6
0
        private void ClearData()
        {
            listCameras       = CameraController.GetCameras();
            listCatalogues    = CatalogueController.GetCatalogues();
            listColorSpaces   = ColorSpaceController.GetColorSpaces();
            listFileFormats   = FileFormatController.GetFileFormats();
            listOptics        = OpticsController.GetOptics();
            listPhotographers = PhotographerController.GetPhotographers();
            listScopes        = ScopeController.GetScopes();
            listSites         = SiteController.GetSites();

            tbCollectionId.Text = "(adding)";
            tbDateTime.Text     = "";
            tbComments.Text     = "";
            tbFile.Text         = "";
            tbMetadataFile.Text = "";
            tbObjectId.Text     = "";
            tbObjectTitle.Text  = "";
            tbResolutionX.Text  = "";
            tbResolutionY.Text  = "";
            tbTotalFrames.Value = 1;

            cbCamera.Items.Clear();
            foreach (var item in listCameras)
            {
                cbCamera.Items.Add(item.LongName);
            }

            cbCatalogue.Items.Clear();
            foreach (var item in listCatalogues)
            {
                cbCatalogue.Items.Add(item.LongName);
            }

            cbColorSpace.Items.Clear();
            foreach (var item in listColorSpaces)
            {
                cbColorSpace.Items.Add(item.Name);
            }

            cbFileFormat.Items.Clear();
            foreach (var item in listFileFormats)
            {
                cbFileFormat.Items.Add(item.LongName);
            }

            cbPhotographer.Items.Clear();
            foreach (var item in listPhotographers)
            {
                cbPhotographer.Items.Add(item.GetInformalName());
            }

            cbScope.Items.Clear();
            foreach (var item in listScopes)
            {
                cbScope.Items.Add(item.GetScopeName());
            }

            clbOptics.Items.Clear();
            foreach (var item in listOptics)
            {
                clbOptics.Items.Add(item.Id + "|  " + item.GetOpticName());
            }

            cbSite.Items.Clear();
            foreach (var item in listSites)
            {
                cbSite.Items.Add(item.Name);
            }

            lblStatus.Text = "Loaded all assets.";
        }
Exemplo n.º 7
0
        void PrepareDataLists()
        {
            // Populate all hard-coded combo-box values.

            cbOpticType.Items.Clear();
            foreach (var item in Enum.GetValues(typeof(Optic.OpticTypes)))
            {
                cbOpticType.Items.Add(item);
            }

            cbScopeMountType.Items.Clear();
            foreach (var item in Enum.GetValues(typeof(Scope.MountTypes)))
            {
                cbScopeMountType.Items.Add(item);
            }

            cbSiteLongtitudeType.Items.Clear();
            foreach (var item in Enum.GetValues(typeof(Site.LongtitudeTypes)))
            {
                cbSiteLongtitudeType.Items.Add(item);
            }

            cbSiteLatitudeType.Items.Clear();
            foreach (var item in Enum.GetValues(typeof(Site.LatitudeTypes)))
            {
                cbSiteLatitudeType.Items.Add(item);
            }

            // Query database for all values.
            listCameras       = CameraController.GetCameras();
            listCatalogues    = CatalogueController.GetCatalogues();
            listColorSpaces   = ColorSpaceController.GetColorSpaces();
            listFileFormats   = FileFormatController.GetFileFormats();
            listOptics        = OpticsController.GetOptics();
            listPhotographers = PhotographerController.GetPhotographers();
            listScopes        = ScopeController.GetScopes();
            listSites         = SiteController.GetSites();

            // Populate list boxes.
            lbCameras.Items.Clear();
            foreach (var item in listCameras)
            {
                lbCameras.Items.Add(item.Id + " " + item.LongName + " " + (item.MaxResolution.Width * item.MaxResolution.Height / 1000000).ToString() + "MP");
            }

            lbCatalogues.Items.Clear();
            foreach (var item in listCatalogues)
            {
                lbCatalogues.Items.Add(item.Id + " " + item.LongName);
            }

            lbColorSpaces.Items.Clear();
            foreach (var item in listColorSpaces)
            {
                lbColorSpaces.Items.Add(item.Id + " " + item.Name);
            }

            lbFileFormats.Items.Clear();
            foreach (var item in listFileFormats)
            {
                lbFileFormats.Items.Add(item.Id + " " + item.LongName);
            }

            lbOptics.Items.Clear();
            foreach (var item in listOptics)
            {
                lbOptics.Items.Add(item.Id + " " + item.Value + " " + item.OpticType.ToString());
            }

            lbPhotographers.Items.Clear();
            foreach (var item in listPhotographers)
            {
                lbPhotographers.Items.Add(item.Id + " " + item.LastName + ", " + item.FirstName);
            }

            lbScopes.Items.Clear();
            foreach (var item in listScopes)
            {
                lbScopes.Items.Add(item.Id + " " + item.Manufacturer + " " + item.Name);
            }

            lbSites.Items.Clear();
            foreach (var item in listSites)
            {
                lbSites.Items.Add(item.Id + " " + item.Name);
            }

            // Populate specific database fields for every tab.

            cbCamerasColorSpaces.Items.Clear();
            foreach (var item in listColorSpaces)
            {
                cbCamerasColorSpaces.Items.Add(item.Name);
            }
        }