Exemplo n.º 1
0
        public async void Test_Return_Message_When_NotFound_SaleController_Update()
        {
            var fakeContext = new FakeContext("Return_Message_When_NotFound_SaleController_Update");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository        = new SaleRepository(context);
                var productRepository = new ProductRepository(context);
                var updateMock        = new Mock <IUpdateProduct>();
                updateMock
                .Setup(x => x.UpdateStock(It.IsAny <Sale>(), It.IsAny <Sale>()));

                var messageMock = new Mock <IMessageHandler>();
                messageMock
                .Setup(x => x
                       .SendMessageAsync(It.IsAny <MessageType>(), It.IsAny <Sale>(), It.IsAny <UpdatedSale>()))
                .Returns(Task.CompletedTask);

                var service    = new SaleService(repository, messageMock.Object, updateMock.Object, productRepository);
                var controller = new SaleController(service);
                var sale       = new Sale();
                sale.ProductId = 1;
                sale.Quantity  = 40;
                var response = await controller.Update(6, sale);

                var okResult = response as NotFoundObjectResult;

                Assert.NotNull(okResult);
                Assert.Equal(404, okResult.StatusCode);
            }
        }
        private void NewEditExit_NewClick(object sender, EventArgs e)
        {
            try
            {
                switch (NewEditExit.BtnNewText)
                {
                case "&New":
                    this.NewControl();
                    break;

                case "&Save":
                    if (this.CheckRequiredFields())
                    {
                        SaleController saleController = new SaleController();
                        SaleInfo       saleInfo       = new SaleInfo();
                        CustomerInfo   custInfo       = new CustomerInfo();
                        SaleDetailInfo saleDetailInfo = new SaleDetailInfo();


                        GetCustomerInfo(custInfo);
                        GetSaleInfo(saleInfo);
                        GetSaleDetailInfo(saleDetailInfo);

                        saleController.Insert(saleInfo, custInfo, saleDetailInfo);

                        this.InitializeControls();
                        Globalizer.ShowMessage(MessageType.Information, "Saved Successfully");
                        this.ResetControl();
                    }
                    break;

                case "&Update":
                    if (this.CheckRequiredFields())
                    {
                        SaleController saleController = new SaleController();
                        SaleInfo       saleInfo       = new SaleInfo();
                        CustomerInfo   custInfo       = new CustomerInfo();
                        SaleDetailInfo saleDetailInfo = new SaleDetailInfo();

                        GetCustomerInfo(custInfo);
                        GetSaleInfo(saleInfo);
                        GetSaleDetailInfo(saleDetailInfo);

                        saleController.Update(saleInfo, custInfo, saleDetailInfo);

                        this.InitializeControls();

                        //this.ResetControl();
                        Globalizer.ShowMessage(MessageType.Information, "Updated Successfully");
                        this.ResetControl();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Globalizer.ShowMessage(MessageType.Critical, ex.Message);
            }
        }
Exemplo n.º 3
0
        public async void Update_NotFound()
        {
            SaleControllerMockFacade mock = new SaleControllerMockFacade();
            var mockResult = new Mock <UpdateResponse <ApiSaleServerResponseModel> >();

            mockResult.SetupGet(x => x.Success).Returns(false);
            mock.ServiceMock.Setup(x => x.Update(It.IsAny <int>(), It.IsAny <ApiSaleServerRequestModel>())).Returns(Task.FromResult <UpdateResponse <ApiSaleServerResponseModel> >(mockResult.Object));
            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiSaleServerResponseModel>(null));
            SaleController controller = new SaleController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, new ApiSaleServerModelMapper());

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

            IActionResult response = await controller.Update(default(int), new ApiSaleServerRequestModel());

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }