示例#1
0
        public IActionResult Add(FixtureForAddDto fixtureForAddDto)
        {
            var result = fixtureService.Add(fixtureForAddDto);

            if (result.Success)
            {
                return(CreatedAtAction("GetById", new { id = result.Data }, result.Message));
            }
            return(BadRequest(result.Message));
        }
示例#2
0
        public void Add_WhenAddedNewFixture_ShouldAddAndReturnId()
        {
            // Arrange
            FixtureForAddDto fixtureForAddDto = new FixtureForAddDto();
            var mockFixtureDal = new MockFixtureDal().MockAdd(new Fixture());
            var sut            = new FixtureManager(mockFixtureDal.Object);

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

            // Assert
            Assert.Equal(new Guid(), result.Data);
        }
示例#3
0
        public void FixtureForAddValidator_WhenDatePurchaseGreaterThanDateWarranty_ShouldHaveError()
        {
            // Arrange
            var model = new FixtureForAddDto()
            {
                DatePurchase = DateTime.Now.AddMinutes(-1),
                DateWarranty = DateTime.Now.AddHours(-1),
            };
            var sut = new FixtureForAddValidator();

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

            // Assert
            result.ShouldHaveValidationErrorFor(m => m.DateWarranty);
        }
        public static async Task <Uri> Add(FixtureForAddDto fixtureForAddDto)
        {
            using var client = new HttpClient();
            var uri = $"{APIAddresses.FixtureService}";

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

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

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

            throw new HttpFailureException(errorContent);
        }
示例#5
0
        private async Task AddFixture()
        {
            FixtureForAddDto fixtureForAddDto = new FixtureForAddDto()
            {
                CategoryId   = (cmbCategory.SelectedItem as dynamic).Value,
                DatePurchase = dtpPurchase.Value.Date,
                DateWarranty = dtpWarranty.Value.Date,
                Description  = txtDescription.Text,
                Name         = txtName.Text,
                PictureUrl   = "pic.lk", // TODO : picture link
                Price        = Convert.ToDecimal(txtPrice.Text),
                SupplierId   = (cmbSupplier.SelectedItem as dynamic).Value
            };

            await FixtureService.Add(fixtureForAddDto);

            MessageBox.Show(Messages.FixtureAdded);
            await LoadFixtureList();
        }
示例#6
0
        public IDataResult <Guid> Add(FixtureForAddDto fixtureForAddDto)
        {
            var fixture = new Fixture()
            {
                CategoryId        = fixtureForAddDto.CategoryId,
                CreatedAt         = DateTime.Now,
                DatePurchase      = fixtureForAddDto.DatePurchase,
                DateWarranty      = fixtureForAddDto.DateWarranty,
                Description       = fixtureForAddDto.Description,
                FixturePositionId = 1,
                Name       = fixtureForAddDto.Name,
                PictureUrl = fixtureForAddDto.PictureUrl,
                Price      = fixtureForAddDto.Price,
                SupplierId = fixtureForAddDto.SupplierId,
                UpdatedAt  = DateTime.Now
            };

            fixtureDal.Add(fixture);
            return(new SuccessDataResult <Guid>(fixture.Id, Messages.FixtureAdded));
        }
示例#7
0
        public void FixtureForAddValidator_TrueStory()
        {
            // Arrange
            var model = new FixtureForAddDto()
            {
                CategoryId   = 1,
                DatePurchase = DateTime.Now.AddMinutes(-2),
                DateWarranty = DateTime.Now.AddYears(2),
                Description  = "Desc Fixture T",
                Name         = "Fixture T",
                PictureUrl   = "picture.lk",
                Price        = 10000M,
                SupplierId   = 1
            };
            var sut = new FixtureForAddValidator();

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

            // Assert
            result.ShouldNotHaveAnyValidationErrors();
        }