public void GetAll_ReturnsAnEmptyList_WhenThereAreNoSuppliers()
        {
            // Arrange
            var suppliers = new List <Supplier>().AsQueryable();

            var supplierMockDbSet = new Mock <DbSet <Supplier> >();

            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.Provider).Returns(suppliers.Provider);
            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.Expression).Returns(suppliers.Expression);
            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.ElementType).Returns(suppliers.ElementType);
            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.GetEnumerator()).Returns(suppliers.GetEnumerator());

            var mockContext = new Mock <EazyCartContext>();

            mockContext.Setup(c => c.Suppliers).Returns(supplierMockDbSet.Object);

            var supplierBusiness = new SupplierBusiness(mockContext.Object);

            // Act
            var allSuppliers = supplierBusiness.GetAll();

            // Assert
            int expectedCount = 0;

            Assert.AreEqual(expectedCount, allSuppliers.Count, "List of all suppliers is not empty");
        }
示例#2
0
        // method to test, need remove when done this project
        private void MenuEditSupplier_Click(object sender, RoutedEventArgs e)
        {
            //If found a ListSuplier, selected for Tabcontrol
            var index = TabControlManagement.GetIndexByTitle(MainTabControl, UsecaseStringContants.editSupplier);

            if (index >= 0)
            {
                MainTabControl.SelectedIndex = index;
            }
            //If not found tab was ListSuplier, add and selected
            else
            {
                SupplierBusiness supplierBusiness = new SupplierBusiness();
                var supplier = supplierBusiness.GetAll()[0];
                SupplierViewModel supplierViewModel = new SupplierViewModel()
                {
                    SupplierId   = supplier.SupplierId,
                    SupplierName = supplier.SupplierName,
                    Description  = supplier.Description
                };
                EditSupplierUserControl editSupplierUserControl = new EditSupplierUserControl(supplierViewModel);
                CustomTabItem           customTabItem           = new CustomTabItem()
                {
                    Title   = UsecaseStringContants.editSupplier,
                    Content = editSupplierUserControl
                };
                MainTabControl.Items.Add(customTabItem);
                MainTabControl.SelectedItem = customTabItem;
            }
            CurrenTabTitle.Content = UsecaseStringContants.editSupplier;
            this.Title             = UsecaseStringContants.editSupplier;
        }
        public void GetAll_ReturnsACorrectListOfSuppliers_WhenNotEmpty()
        {
            // Arrange
            var suppliers = new List <Supplier>
            {
                new Supplier {
                    Name = "TestSupplier1", Id = 1
                },
                new Supplier {
                    Name = "TestSupplier2", Id = 2
                },
                new Supplier {
                    Name = "TestSupplier3", Id = 3
                }
            }.AsQueryable();

            var supplierMockDbSet = new Mock <DbSet <Supplier> >();

            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.Provider).Returns(suppliers.Provider);
            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.Expression).Returns(suppliers.Expression);
            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.ElementType).Returns(suppliers.ElementType);
            supplierMockDbSet.As <IQueryable <Supplier> >().Setup(m => m.GetEnumerator()).Returns(suppliers.GetEnumerator());

            var mockContext = new Mock <EazyCartContext>();

            mockContext.Setup(c => c.Suppliers).Returns(supplierMockDbSet.Object);

            var supplierBusiness = new SupplierBusiness(mockContext.Object);

            // Act
            var allSuppliers = supplierBusiness.GetAll();

            // Assert
            string expectedFirstSupplierName  = "TestSupplier1";
            string expectedSecondSupplierName = "TestSupplier2";
            string expectedThirdSupplierName  = "TestSupplier3";

            Assert.AreEqual(expectedFirstSupplierName, allSuppliers[0].Name, "First names do not match.");
            Assert.AreEqual(expectedSecondSupplierName, allSuppliers[1].Name, "Second names do not match.");
            Assert.AreEqual(expectedThirdSupplierName, allSuppliers[2].Name, "Third names do not match");
        }