示例#1
0
        public async void ReturnCreateView()
        {
            var result = await sut.Create();

            var vr = Assert.IsType <ViewResult>(result);

            Assert.Equal("Create", vr.ViewName);
        }
示例#2
0
        public async void Test_Return_Message_BadRequest_SaleController_Create()
        {
            var fakeContext = new FakeContext("Test_Return_Message_BadRequest_SaleController_Create");

            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  = 400;
                var response = await controller.Create(sale);

                var okResult = response as BadRequestObjectResult;

                Assert.NotNull(okResult);
                Assert.Equal(400, okResult.StatusCode);
            }
        }
示例#3
0
 private void btnAddProduct_Click(object sender, EventArgs e)
 {
     if (sale == null)
     {
         sale = saleController.Create(selectedCustomer);
     }
     subProductForTransactionController.Create(selectedSubProduct, sale);
     LoadSaleItems();
     txtProduct.Text = string.Empty;
     txtProduct.Focus();
 }
示例#4
0
        public async void Create_Errors()
        {
            SaleControllerMockFacade mock = new SaleControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiSaleServerResponseModel> >(null as ApiSaleServerResponseModel);
            var mockRecord   = new ApiSaleServerResponseModel();

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSaleServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSaleServerResponseModel> >(mockResponse.Object));
            SaleController controller = new SaleController(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 ApiSaleServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSaleServerRequestModel>()));
        }
        private void btnSell_Click(object sender, EventArgs e)
        {
            quote.Lock();
            quote.Selled = true;
            quoteController.SaveOrUpdate(quote);
            Sale sale = saleController.Create(quote);

            foreach (SubProductForTransaction subProductForTransaction in quote.SubProductsForTransactions)
            {
                SubProductForTransaction item = subProductForTransactionController.Create(subProductForTransaction.SubProduct, sale);
                item.Quantity  = subProductForTransaction.Quantity;
                item.UnitPrice = subProductForTransaction.UnitPrice;
                subProductForTransactionController.SaveOrUpdate(item);
            }
            MessageBox.Show(string.Format("Se ha creado una venta para {0} \"{1}\" {2} con los datos de esta cotización.", selectedCustomer.Name, selectedCustomer.NickName, selectedCustomer.LastName));
            Sales s = new Sales(sale);

            s.MdiParent = this.MdiParent;
            s.Show();
            this.Dispose();
        }
示例#6
0
        public async void Create_No_Errors()
        {
            SaleControllerMockFacade mock = new SaleControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiSaleServerResponseModel> .CreateResponse(null as ApiSaleServerResponseModel);

            mockResponse.SetRecord(new ApiSaleServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiSaleServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiSaleServerResponseModel> >(mockResponse));
            SaleController controller = new SaleController(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 ApiSaleServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiSaleServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiSaleServerRequestModel>()));
        }