Exemple #1
0
        public async Task DeleteAutopartShouldReduceTheListCount()
        {
            var list = new List <Autopart>()
            {
                new Autopart
                {
                    Id   = 1,
                    Name = "A",
                },
                new Autopart
                {
                    Id   = 2,
                    Name = "B",
                },
            };

            this.autopartRepository
            .Setup(x => x.AllAsNoTracking())
            .Returns(list.AsQueryable());

            this.autopartRepository
            .Setup(x => x.Delete(It.IsAny <Autopart>()))
            .Callback((Autopart autopart) => list.Remove(autopart));

            var service = new AutopartsService(
                this.carRepository.Object,
                this.autopartRepository.Object,
                this.imageService.Object);

            await service.DeleteByIdAsync(1);

            Assert.Single(list);
        }
Exemple #2
0
        public async Task AutpartsListShouldIncreaseWhenAddingNewAutopart()
        {
            var list = new List <Autopart>();

            this.autopartRepository
            .Setup(x => x.AllAsNoTracking())
            .Returns(list.AsQueryable());

            this.autopartRepository
            .Setup(x => x.AddAsync(It.IsAny <Autopart>()))
            .Callback((Autopart autopart) => list.Add(autopart));

            var service = new AutopartsService(
                this.carRepository.Object,
                this.autopartRepository.Object,
                this.imageService.Object);


            var file = MockObjects.GetMockFile().Object;

            var countOfFakeAutoparts = 2;

            for (int i = 0; i < countOfFakeAutoparts; i++)
            {
                await service.CreateAsync(
                    new CreateAutopartDTO
                {
                    Name   = $"Fake Autopart {i}",
                    Price  = 10,
                    Images = new List <IFormFile>()
                    {
                        file,
                        file,
                    },
                    CarManufacturerId = 2,
                    CarTypeId         = 2,
                    ModelId           = 2,
                },
                    $"fakeUser{i}",
                    $"fakeAutopart{i}");
            }

            Assert.Equal(countOfFakeAutoparts, list.Count());
        }