public void GetAllNames_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.GetAllNames();

            // Assert
            int expectedCount = 0;

            Assert.AreEqual(expectedCount, allSuppliers.Count, "List of all suppliers is not empty");
        }
        public void GetAllNames_ReturnsACorrectListOfSupplierNames_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 allSupplierNames = supplierBusiness.GetAllNames();

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

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