public async Task PartService_Should_Update_Part()
        {
            // Arrange
            SetUpUnitOfWork();
            var service = new PartService(_unitOfWork.Object, _mapper);
            var entity  = new PartDTO()
            {
                Name = "TestName",
                Code = "12345",
            };

            var newEntity = new PartDTO()
            {
                Name = "NewTestName",
                Code = "12345678",
            };

            await service.CreateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

            // Act
            entity.Name = newEntity.Name;
            entity.Code = newEntity.Code;
            await service.UpdateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.NotNull(entity);
            Assert.Equal(newEntity.Name, entity.Name);
            Assert.Equal(newEntity.Code, entity.Code);
        }
        public async Task PartService_Should_Create_Part_Async()
        {
            // Arrange
            SetUpUnitOfWork();
            var service        = new PartService(_unitOfWork.Object, _mapper);
            var expectedEntity = new PartDTO()
            {
                Name = "TestName",
                Code = "12345",
            };

            // Act
            var actualEntity = await service.CreateAsync(expectedEntity);

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.NotNull(actualEntity);
            Assert.Equal(expectedEntity.Name, actualEntity.Name);
            Assert.Equal(expectedEntity.Code, actualEntity.Code);
        }
Пример #3
0
        public async Task CreateAsyncShouldCreatePartWithValidData()
        {
            //Arrange
            var partRepository = this.GetConfiguredPartRepository(new List <Part>());
            var carRepoaitory  = this.GetConfiguredCarRepository();
            var partService    = new PartService(partRepository.Object, carRepoaitory.Object);

            //Act
            var result = await partService.CreateAsync(
                SampleCarId,
                SamplePartName,
                SamplePartNumber,
                SamplePartPrice,
                SamplePartQuantity);

            //Arrange
            var newPart = partRepository.Object.All();

            result
            .Should()
            .NotBeNull();

            newPart
            .Count()
            .Should()
            .BePositive();

            newPart
            .First()
            .Should()
            .Match <Part>(part => part.Name == SamplePartName)
            .And
            .Match <Part>(part => part.Number == SamplePartNumber)
            .And
            .Match <Part>(part => part.Price == SamplePartPrice)
            .And
            .Match <Part>(part => part.Quantity == SamplePartQuantity)
            .And
            .Match <Part>(part => part.ServiceId == SampleCarServiceId);
        }
        public async Task PartService_Should_Delete_Part_Async()
        {
            // Arrange
            SetUpUnitOfWork();
            var service = new PartService(_unitOfWork.Object, _mapper);
            var entity  = new PartDTO()
            {
                Name = "TestName",
                Code = "12345"
            };

            entity = await service.CreateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

            // Act
            await service.DeleteAsync(entity.Id);

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.Null(await service.GetAsync(entity.Id));
        }