public void Throw_WhenPassedParameterIsNull() { //Arrange var brands = new Mock <IEfGenericRepository <Brand> >(); var brandsService = new BrandsService(brands.Object); //Act & Assert Assert.Throws <ArgumentNullException>(() => brandsService.Create(null)); }
public ActionResult <Brand> Create([FromBody] Brand newBrand) { try { return(Ok(_ss.Create(newBrand))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void InvokeRepositoryMethodAddOnce_WhenPassedParameterIsValid() { //Arrange var brands = new Mock <IEfGenericRepository <Brand> >(); brands.Setup(x => x.Add(It.IsAny <Brand>())).Verifiable(); var brandsService = new BrandsService(brands.Object); var brand = DataHelper.GetBrand(); //Act brandsService.Create(brand); //Assert brands.Verify(x => x.Add(It.IsAny <Brand>()), Times.Once); }