Beispiel #1
0
        public IActionResult Add(SupplierForAddDto supplierForAddDto)
        {
            var result = supplierService.Add(supplierForAddDto);

            if (result.Success)
            {
                return(CreatedAtAction("GetById", new { id = result.Data }, result.Message));
            }
            return(BadRequest(result.Message));
        }
Beispiel #2
0
        public void Add_WhenAddedNewSupplier_ShouldAddAndReturnId()
        {
            // Arrange
            var supplierForAddDto = new SupplierForAddDto();
            var mockSupplierDal   = new MockSupplierDal().MockAdd(new Supplier());
            var sut = new SupplierManager(mockSupplierDal.Object);

            // Act
            var result = sut.Add(supplierForAddDto);

            // Assert
            Assert.Equal(new int(), result.Data);
        }
        public IDataResult <int> Add(SupplierForAddDto supplierForAddDto)
        {
            var supplier = new Supplier()
            {
                CreatedAt   = DateTime.Now,
                Description = supplierForAddDto.Description,
                IsEnable    = true,
                Name        = supplierForAddDto.Name,
                UpdatedAt   = DateTime.Now
            };

            supplierDal.Add(supplier);
            return(new SuccessDataResult <int>(supplier.Id, Messages.SupplierAdded));
        }
Beispiel #4
0
        public void SupplierForAddValidator_TrueStory()
        {
            // Arrange
            var model = new SupplierForAddDto()
            {
                Description = "Desc Supplier T",
                Name        = "Supplier T"
            };
            var sut = new SupplierForAddValidator();

            // Act
            var result = sut.TestValidate(model);

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }
Beispiel #5
0
        public static async Task <Uri> Add(SupplierForAddDto supplierForAddDto)
        {
            using var client = new HttpClient();
            var uri = $"{APIAddresses.SupplierService}";

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FormAccessToken.Token);
            var response = await client.PostAsJsonAsync(uri, supplierForAddDto);

            if (response.IsSuccessStatusCode)
            {
                return(response.Headers.Location);
            }

            var errorContent = response.Content.ReadFromJsonAsync <ErrorDetail>().Result;

            throw new HttpFailureException(errorContent);
        }