public async Task <IHttpActionResult> Get(int id)
        {
            ManufacturerService manufacturerService = CreateManufacturerService();
            var manufacturer = await manufacturerService.GetManufacturerById(id);

            return(Ok(manufacturer));
        }
        public void GetManufacturerById_NoManufacturerFound_ExpectNullReferenceException(int id)
        {
            manufacturers = new List <Manufacturer>()
            {
                new Manufacturer {
                    ManufacturerId = 2, Name = "Toyota"
                },
                new Manufacturer {
                    ManufacturerId = 3, Name = "Peugeot"
                },
                new Manufacturer {
                    ManufacturerId = 4, Name = "Ford"
                },
            };

            IManufacturerService service      = new ManufacturerService(repoMock.Object, null);
            Manufacturer         manufacturer = null;

            var ex = Assert.Throws <NullReferenceException>(() =>
            {
                manufacturer = service.GetManufacturerById(id);
            });

            Assert.Equal("Manufacturer with this ID not found", ex.Message);
            Assert.Null(manufacturer);

            repoMock.Verify(repo => repo.ReadManufacturerById(It.IsAny <int>()), Times.Once);
        }
        public void GetManufacturerById(int id, string name)
        {
            manufacturers = new List <Manufacturer>()
            {
                new Manufacturer {
                    ManufacturerId = 1, Name = "Toyota"
                },
                new Manufacturer {
                    ManufacturerId = 2, Name = "Peugeot"
                },
                new Manufacturer {
                    ManufacturerId = 3, Name = "Ford"
                },
            };

            IManufacturerService service      = new ManufacturerService(repoMock.Object, null);
            Manufacturer         manufacturer = service.GetManufacturerById(id);

            Assert.Equal(manufacturer.ManufacturerId, id);
            Assert.Equal(manufacturer.Name, name);
            repoMock.Verify(repo => repo.ReadManufacturerById(It.IsAny <int>()), Times.Once);
        }
        public void GetManufacturerById_IdIsNotPositive_ExpectArgumentException(int id)
        {
            manufacturers = new List <Manufacturer>()
            {
                new Manufacturer {
                    ManufacturerId = 1, Name = "Toyota"
                }
            };

            IManufacturerService service      = new ManufacturerService(repoMock.Object, null);
            Manufacturer         manufacturer = null;

            var ex = Assert.Throws <ArgumentException>(() =>
            {
                manufacturer = service.GetManufacturerById(id);
            });

            Assert.Equal("ID of the manufacturer to find must be a positive integer", ex.Message);
            Assert.Null(manufacturer);

            repoMock.Verify(repo => repo.ReadManufacturerById(It.IsAny <int>()), Times.Never);
        }