Пример #1
0
        public async Task ManufacturerService_Should_Update_Manufacturer()
        {
            // Arrange
            SetUpUnitOfWork();
            var service = new ManufacturerService(_unitOfWork.Object, _mapper);
            var entity  = new ManufacturerDTO()
            {
                Name = "TestName",
            };

            var newEntity = new ManufacturerDTO()
            {
                Name = "NewTestName",
            };

            await service.CreateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

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

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.NotNull(entity);
            Assert.Equal(newEntity.Name, entity.Name);
        }
        public async Task <IActionResult> Create([FromBody] ManufacturerRequest request)
        {
            try
            {
                await manufacturerService.CreateAsync(request);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Пример #3
0
        public async Task ManufacturerService_Should_Create_Manufacturer_Async()
        {
            // Arrange
            SetUpUnitOfWork();
            var service        = new ManufacturerService(_unitOfWork.Object, _mapper);
            var expectedEntity = new ManufacturerDTO()
            {
                Name = "TestName",
            };

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

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.NotNull(actualEntity);
            Assert.Equal(expectedEntity.Name, actualEntity.Name);
        }
Пример #4
0
        public async Task ManufacturerService_Should_Delete_Manufacturer_Async()
        {
            // Arrange
            SetUpUnitOfWork();
            var service = new ManufacturerService(_unitOfWork.Object, _mapper);
            var entity  = new ManufacturerDTO()
            {
                Name = "TestName",
            };

            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));
        }