Ejemplo n.º 1
0
        public virtual ApiSpecialOfferResponseModel MapBOToModel(
            BOSpecialOffer boSpecialOffer)
        {
            var model = new ApiSpecialOfferResponseModel();

            model.SetProperties(boSpecialOffer.SpecialOfferID, boSpecialOffer.Category, boSpecialOffer.Description, boSpecialOffer.DiscountPct, boSpecialOffer.EndDate, boSpecialOffer.MaxQty, boSpecialOffer.MinQty, boSpecialOffer.ModifiedDate, boSpecialOffer.Rowguid, boSpecialOffer.StartDate, boSpecialOffer.Type);

            return(model);
        }
Ejemplo n.º 2
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiSpecialOfferResponseModel response = await client.SpecialOfferGetAsync(1);

            response.Should().NotBeNull();
        }
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiSpecialOfferResponseModel response = await this.SpecialOfferService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 4
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ISpecialOfferRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <SpecialOffer>(null));
            var service = new SpecialOfferService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.SpecialOfferModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLSpecialOfferMapperMock,
                                                  mock.DALMapperMockFactory.DALSpecialOfferMapperMock);

            ApiSpecialOfferResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 5
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiSpecialOfferResponseModel model = await client.SpecialOfferGetAsync(1);

            ApiSpecialOfferModelMapper mapper = new ApiSpecialOfferModelMapper();

            UpdateResponse <ApiSpecialOfferResponseModel> updateResponse = await client.SpecialOfferUpdateAsync(model.SpecialOfferID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Ejemplo n.º 6
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiSpecialOfferModelMapper();
            var model  = new ApiSpecialOfferResponseModel();

            model.SetProperties(1, "A", "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            ApiSpecialOfferRequestModel response = mapper.MapResponseToRequest(model);

            response.Category.Should().Be("A");
            response.Description.Should().Be("A");
            response.DiscountPct.Should().Be(1m);
            response.EndDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.MaxQty.Should().Be(1);
            response.MinQty.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Rowguid.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            response.StartDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Type.Should().Be("A");
        }
Ejemplo n.º 7
0
        public async void Create_Errors()
        {
            SpecialOfferControllerMockFacade mock = new SpecialOfferControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiSpecialOfferResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiSpecialOfferResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSpecialOfferRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSpecialOfferResponseModel> >(mockResponse.Object));
            SpecialOfferController controller = new SpecialOfferController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiSpecialOfferRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSpecialOfferRequestModel>()));
        }
Ejemplo n.º 8
0
        public async void All_Exists()
        {
            SpecialOfferControllerMockFacade mock = new SpecialOfferControllerMockFacade();
            var record  = new ApiSpecialOfferResponseModel();
            var records = new List <ApiSpecialOfferResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            SpecialOfferController controller = new SpecialOfferController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiSpecialOfferResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiSpecialOfferRequestModel> patch)
        {
            ApiSpecialOfferResponseModel record = await this.SpecialOfferService.Get(id);

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

                UpdateResponse <ApiSpecialOfferResponseModel> result = await this.SpecialOfferService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public async void TestGet()
        {
            ApiSpecialOfferResponseModel response = await this.Client.SpecialOfferGetAsync(1);

            response.Should().NotBeNull();
        }