예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }