Exemple #1
0
        private async Task <ApiTransactionHistoryResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiTransactionHistoryRequestModel();

            model.SetProperties(2m, DateTime.Parse("1/1/1988 12:00:00 AM"), 2, 2, 2, 2, DateTime.Parse("1/1/1988 12:00:00 AM"), "B");
            CreateResponse <ApiTransactionHistoryResponseModel> result = await client.TransactionHistoryCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
 public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiTransactionHistoryRequestModel model)
 {
     this.ActualCostRules();
     this.ModifiedDateRules();
     this.ProductIDRules();
     this.QuantityRules();
     this.ReferenceOrderIDRules();
     this.ReferenceOrderLineIDRules();
     this.TransactionDateRules();
     this.TransactionTypeRules();
     return(await this.ValidateAsync(model, id));
 }
        public virtual async Task <IActionResult> Create([FromBody] ApiTransactionHistoryRequestModel model)
        {
            CreateResponse <ApiTransactionHistoryResponseModel> result = await this.TransactionHistoryService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/TransactionHistories/{result.Record.TransactionID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
        public virtual async Task <CreateResponse <ApiTransactionHistoryResponseModel> > Create(
            ApiTransactionHistoryRequestModel model)
        {
            CreateResponse <ApiTransactionHistoryResponseModel> response = new CreateResponse <ApiTransactionHistoryResponseModel>(await this.TransactionHistoryModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolTransactionHistoryMapper.MapModelToBO(default(int), model);
                var record = await this.TransactionHistoryRepository.Create(this.DalTransactionHistoryMapper.MapBOToEF(bo));

                response.SetRecord(this.BolTransactionHistoryMapper.MapBOToModel(this.DalTransactionHistoryMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiTransactionHistoryRequestModel> PatchModel(int id, JsonPatchDocument <ApiTransactionHistoryRequestModel> patch)
        {
            var record = await this.TransactionHistoryService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiTransactionHistoryRequestModel request = this.TransactionHistoryModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public void MapModelToBO()
        {
            var mapper = new BOLTransactionHistoryMapper();
            ApiTransactionHistoryRequestModel model = new ApiTransactionHistoryRequestModel();

            model.SetProperties(1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            BOTransactionHistory response = mapper.MapModelToBO(1, model);

            response.ActualCost.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductID.Should().Be(1);
            response.Quantity.Should().Be(1);
            response.ReferenceOrderID.Should().Be(1);
            response.ReferenceOrderLineID.Should().Be(1);
            response.TransactionDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TransactionType.Should().Be("A");
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ITransactionHistoryRepository>();
            var model = new ApiTransactionHistoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <TransactionHistory>())).Returns(Task.FromResult(new TransactionHistory()));
            var service = new TransactionHistoryService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.TransactionHistoryModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLTransactionHistoryMapperMock,
                                                        mock.DALMapperMockFactory.DALTransactionHistoryMapperMock);

            CreateResponse <ApiTransactionHistoryResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.TransactionHistoryModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiTransactionHistoryRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <TransactionHistory>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ITransactionHistoryRepository>();
            var model = new ApiTransactionHistoryRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new TransactionHistoryService(mock.LoggerMock.Object,
                                                        mock.RepositoryMock.Object,
                                                        mock.ModelValidatorMockFactory.TransactionHistoryModelValidatorMock.Object,
                                                        mock.BOLMapperMockFactory.BOLTransactionHistoryMapperMock,
                                                        mock.DALMapperMockFactory.DALTransactionHistoryMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.TransactionHistoryModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual BOTransactionHistory MapModelToBO(
            int transactionID,
            ApiTransactionHistoryRequestModel model
            )
        {
            BOTransactionHistory boTransactionHistory = new BOTransactionHistory();

            boTransactionHistory.SetProperties(
                transactionID,
                model.ActualCost,
                model.ModifiedDate,
                model.ProductID,
                model.Quantity,
                model.ReferenceOrderID,
                model.ReferenceOrderLineID,
                model.TransactionDate,
                model.TransactionType);
            return(boTransactionHistory);
        }
        public virtual async Task <UpdateResponse <ApiTransactionHistoryResponseModel> > Update(
            int transactionID,
            ApiTransactionHistoryRequestModel model)
        {
            var validationResult = await this.TransactionHistoryModelValidator.ValidateUpdateAsync(transactionID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolTransactionHistoryMapper.MapModelToBO(transactionID, model);
                await this.TransactionHistoryRepository.Update(this.DalTransactionHistoryMapper.MapBOToEF(bo));

                var record = await this.TransactionHistoryRepository.Get(transactionID);

                return(new UpdateResponse <ApiTransactionHistoryResponseModel>(this.BolTransactionHistoryMapper.MapBOToModel(this.DalTransactionHistoryMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiTransactionHistoryResponseModel>(validationResult));
            }
        }
Exemple #11
0
        public void CreatePatch()
        {
            var mapper = new ApiTransactionHistoryModelMapper();
            var model  = new ApiTransactionHistoryRequestModel();

            model.SetProperties(1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

            JsonPatchDocument <ApiTransactionHistoryRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiTransactionHistoryRequestModel();

            patch.ApplyTo(response);
            response.ActualCost.Should().Be(1m);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.ProductID.Should().Be(1);
            response.Quantity.Should().Be(1);
            response.ReferenceOrderID.Should().Be(1);
            response.ReferenceOrderLineID.Should().Be(1);
            response.TransactionDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TransactionType.Should().Be("A");
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiTransactionHistoryRequestModel model)
        {
            ApiTransactionHistoryRequestModel request = await this.PatchModel(id, this.TransactionHistoryModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiTransactionHistoryResponseModel> result = await this.TransactionHistoryService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiTransactionHistoryRequestModel> patch)
        {
            ApiTransactionHistoryResponseModel record = await this.TransactionHistoryService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiTransactionHistoryRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiTransactionHistoryResponseModel> result = await this.TransactionHistoryService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }