Esempio n. 1
0
        public void GetAllData_EmptyManufactures_0()
        {
            var result = new List <Manufacturer>
            {
                new Manufacturer
                {
                    Id      = 1,
                    Country = "1",
                    Name    = "1n"
                },
                new Manufacturer
                {
                    Id      = 2,
                    Country = "2",
                    Name    = "2n"
                }
            };

            var mock = new Mock <IAsyncRepository>();

            mock.Setup(s => s.GetAll <Manufacturer>())
            .Returns <string>(_ =>
            {
                return(result);
            });
            var repository = mock.Object;

            var service          = new ManufacturerService(repository);
            var allManufacturers = service.GetAllManufacturers();

            Assert.Equal(result.Count, allManufacturers.Count);
        }
        private void BindManufacturers()
        {
            var manufacturers = ManufacturerService.GetAllManufacturers();

            if (manufacturers.Count > 0)
            {
                rptrManufacturers.DataSource = manufacturers;
                rptrManufacturers.DataBind();
            }
        }
        public void GetAllManufacturers_Should_BeCalled_IfParamsAreValid()
        {
            // Arrange
            var mockedDbSet         = new Mock <IEfCarSystemDbSetCocoon <Manufacturer> >();
            var manufacturerService = new ManufacturerService(mockedDbSet.Object);

            // Act
            manufacturerService.GetAllManufacturers();

            // Assert
            mockedDbSet.Verify(rep => rep.All(), Times.Once);
        }
        public void GetAllManufacturers_Should_ThrowArgumentNullException_IfPassedManufacturersAreNull()
        {
            // Arrange
            var mockedDbSet         = new Mock <IEfCarSystemDbSetCocoon <Manufacturer> >();
            var manufacturerService = new ManufacturerService(mockedDbSet.Object);

            // Act
            IEnumerable <Manufacturer> expectedManufacturersResult = null;

            mockedDbSet.Setup(rep => rep.All()).Returns(() => expectedManufacturersResult.AsQueryable());

            // Assert
            Assert.Throws <ArgumentNullException>(() => manufacturerService.GetAllManufacturers());
        }
        public void GetAllManufacturers_Should_ReturnEmptyCollection_IfThereAreNoManufacturersAdded()
        {
            // Arrange
            var mockedDbSet         = new Mock <IEfCarSystemDbSetCocoon <Manufacturer> >();
            var manufacturerService = new ManufacturerService(mockedDbSet.Object);

            // Act
            IEnumerable <Manufacturer> expectedManufacturersResult = new List <Manufacturer>();

            mockedDbSet.Setup(rep => rep.All()).Returns(() => expectedManufacturersResult.AsQueryable());

            // Assert
            Assert.IsEmpty(manufacturerService.GetAllManufacturers());
        }
        public void GetAllManufacturersWithCurrentPageIsNegativeThrowsException()
        {
            var manufacturerRepo = new Mock <IManufacturerRepository>();
            IManufacturerService manufacturerService = new ManufacturerService(manufacturerRepo.Object);

            var filter = new Filter()
            {
                ItemsPerPage = 1,
                CurrentPage  = -1,
            };

            var e = Assert.Throws <ArgumentException>(() => manufacturerService.GetAllManufacturers(filter));

            Assert.Equal("The items per page and current page have to be positive numbers", e.Message);
        }
        public void GetAllManufacturers_ListIsNull_ExpectNullReferenceException()
        {
            manufacturers = null;
            List <Manufacturer>  listOfManufacturers = null;
            IManufacturerService service             = new ManufacturerService(repoMock.Object, null);

            var ex = Assert.Throws <NullReferenceException>(() =>
            {
                listOfManufacturers = service.GetAllManufacturers();
            });

            Assert.Equal("List of manufacturers does not exist", ex.Message);
            Assert.Null(listOfManufacturers);

            repoMock.Verify(repo => repo.ReadAllManufacturers(), Times.Once);
        }
        public void GetAllManufacturers_Should_ReturnCorrectCollection_IfCalled()
        {
            // Arrange
            var mockedDbSet         = new Mock <IEfCarSystemDbSetCocoon <Manufacturer> >();
            var manufacturerService = new ManufacturerService(mockedDbSet.Object);

            // Act
            IEnumerable <Manufacturer> expectedManufacturersResult = new List <Manufacturer>()
            {
                new Manufacturer(), new Manufacturer()
            };

            mockedDbSet.Setup(rep => rep.All()).Returns(() => expectedManufacturersResult.AsQueryable());

            // Assert
            Assert.AreEqual(manufacturerService.GetAllManufacturers(), expectedManufacturersResult);
        }
        public void GetAllManufacturers(int count)
        {
            manufacturers = new List <Manufacturer>();
            for (int i = 0; i < count; i++)
            {
                manufacturers.Add(new Manufacturer {
                    ManufacturerId = i
                });
            }

            IManufacturerService service = new ManufacturerService(repoMock.Object, null);
            int result = service.GetAllManufacturers().Count;

            Assert.Equal(result, manufacturers.Count);

            repoMock.Verify(repo => repo.ReadAllManufacturers(), Times.Once);
        }
        public void GetAllManufacturersEnsureRepositoryIsCalled()
        {
            var manufacturerRepo = new Mock <IManufacturerRepository>();
            IManufacturerService manufacturerService = new ManufacturerService(manufacturerRepo.Object);

            var isCalled = false;
            var filter   = new Filter();


            manufacturerRepo.Setup(x => x.GetAllManufacturers(filter)).Callback(() => isCalled = true).Returns(new List <Manufacturer>()
            {
                new Manufacturer()
                {
                    Id     = 1,
                    Name   = "Test",
                    Drones = null
                }
            });

            manufacturerService.GetAllManufacturers(filter);

            Assert.True(isCalled);
        }