public void CreateBrandWithMissingSpeakerBrandThrowsException() { var brandRepo = new Mock <IBrandRepository>(); var speakerRepo = new Mock <ISpeakerRepository>(); IBrandService brandService = new BrandService(brandRepo.Object, speakerRepo.Object); var brand = new Brand(); Exception e = Assert.Throws <InvalidDataException>(() => brandService.CreateBrand(brand)); Assert.Equal("Can not create a brand without a name", e.Message); }
public async Task DeleteBrandAsyncShouldReturnTrue() { var brandRepo = new Repository <Brand>(db); var brandService = new BrandService(brandRepo); await brandService.CreateBrand(new BrandCreateDtoModel { Name = "Audi", ImageAddress = "/Images/CarLogos/Audi-logo.png" }); var isDeleted = await brandService.DeleteBrandAsync(1); Assert.True(isDeleted); }
public void AddBrand_ValidBrand(int id, string brandName) { // arrange Brand brand = new Brand() { ID = id, BrandName = brandName }; BrandService service = new BrandService(repoMock.Object, validatorMock.Object); // act service.CreateBrand(brand); // assert Assert.Contains(brand, brandDatabase.Values); repoMock.Verify(repo => repo.AddBrand(It.Is <Brand>(b => b == brand)), Times.Once); validatorMock.Verify(validator => validator.ValidateBrand(It.Is <Brand>(b => b == brand)), Times.Once); }
public void CreateBrandSecureRepositoryIsCalled() { var brandRepo = new Mock <IBrandRepository>(); var speakerRepo = new Mock <ISpeakerRepository>(); IBrandService brandService = new BrandService(brandRepo.Object, speakerRepo.Object); var brand = new Brand() { SpeakerBrand = "Bose" }; var isCalled = false; brandRepo.Setup(x => x.CreateBrand(brand)).Callback(() => isCalled = true); brandService.CreateBrand(brand); Assert.True(isCalled); }
public void AddBrand_InvalidBrand(int id, string brandName, string errorExpected) { // arrange Brand brand = new Brand() { ID = id, BrandName = brandName }; validatorMock.Setup(mock => mock.ValidateBrand(It.IsAny <Brand>())).Callback <Brand>(brand => throw new ArgumentException(errorExpected)); BrandService service = new BrandService(repoMock.Object, validatorMock.Object); // act var ex = Assert.Throws <ArgumentException>(() => service.CreateBrand(brand)); // assert Assert.Equal(errorExpected, ex.Message); Assert.DoesNotContain(brand, brandDatabase.Values); repoMock.Verify(repo => repo.AddBrand(It.Is <Brand>(b => b == brand)), Times.Never); validatorMock.Verify(validator => validator.ValidateBrand(It.Is <Brand>(b => b == brand)), Times.Once); }