Ejemplo n.º 1
0
        public void CreateDroneNoManufacturerException()
        {
            var           droneRepo = new Mock <IDroneRepository>();
            IDroneService service   = new DroneService(droneRepo.Object);
            Drone         drone     = new Drone()
            {
                Id = 1,

                /*Manufacturer = new Manufacturer()
                 * {
                 *  Id = 1,
                 *  Name = "Phantom",
                 *  Drones = new List<Drone>()
                 *  {
                 *      new Drone()
                 *  }
                 * },*/
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                ImageURL    = "www.imgUrl.com"
            };

            Exception e = Assert.Throws <ArgumentException>(() => service.Create(drone));

            Assert.Equal("Manufacturer cannot be null or empty", e.Message);
        }
Ejemplo n.º 2
0
        public void CreateDroneEnsureRepositoryIsCalled()
        {
            var           droneRepo = new Mock <IDroneRepository>();
            IDroneService service   = new DroneService(droneRepo.Object);

            var isCalled = false;

            var drone = new Drone()
            {
                Id           = 1,
                Manufacturer = new Manufacturer()
                {
                    Id     = 1,
                    Name   = "Phantom",
                    Drones = new List <Drone>()
                    {
                        new Drone()
                    }
                },
                ProductName = "B15",
                Price       = 500,
                Details     = "Handsome",
                ImageURL    = "www.imgUrl.com"
            };

            droneRepo.Setup(x => x.Create(drone)).Callback(() => isCalled = true).Returns(drone);

            service.Create(drone);

            Assert.True(isCalled);
        }