Example #1
0
        public SalesManager(string file)
        {
            var fileParser = new SalesParser();
            var fileInfo   = fileParser.Parse(file);

            if (fileInfo != null)
            {
                Manager manager = new ManagerService().GetOrCreate(fileInfo.Manager);

                foreach (var saleItem in fileInfo.SaleItems)
                {
                    Client  client  = new ClientService().GetOrCreate(saleItem.Client);
                    Product product = new ProductService().GetOrCreate(saleItem.Product);

                    var sale = new SaleService();
                    sale.Create(
                        saleItem.Time,
                        manager.Id,
                        client.Id,
                        product.Id,
                        saleItem.Sum
                        );
                }
            }
        }
Example #2
0
        public async void Test_Return_Message_When_Quantity_Larger_Than_Stock_Create_Sale_Service()
        {
            var fakeContext = new FakeContext("Return_Message_When_Quantity_Larger_Than_Stock_Create_Sale_Service");

            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 sale    = new Sale();
                sale.ProductId = 1;
                sale.Quantity  = 300;
                var newSale = await service.Create(sale);

                Assert.Equal("{ Message = Quantidade indisponível no estoque. }", newSale.ToString());
            }
        }
Example #3
0
        public void Test_Return_Message_When_Product_NotFound_Create_Sale_Service()
        {
            var fakeContext = new FakeContext("Return_Message_When_Product_NotFound_Create_Sale_Service");

            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 sale    = new Sale();
                var newSale = service.Create(sale);

                Assert.Equal("{ Message = Produto não encontrado. }", newSale.Result.ToString());
            }
        }
Example #4
0
        public async void Create()
        {
            var mock  = new ServiceMockFacade <ISaleRepository>();
            var model = new ApiSaleRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Sale>())).Returns(Task.FromResult(new Sale()));
            var service = new SaleService(mock.LoggerMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.SaleModelValidatorMock.Object,
                                          mock.BOLMapperMockFactory.BOLSaleMapperMock,
                                          mock.DALMapperMockFactory.DALSaleMapperMock);

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

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.SaleModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSaleRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Sale>()));
        }
        public async void Create(Sale sale)
        {
            var itemSale = new SaleItem()
            {
                IdTrack     = 1,
                IdSale      = sale.Id,
                Cashback    = 5,
                IdDayOfWeek = 0
            };

            _saleRepositoryMock.Setup(r => r.Create(sale)).Returns(1);
            _saleItemRepositoryMock.Setup(r => r.Create(itemSale)).Returns(1);
            var result = _saleService.Create(sale);

            Assert.NotNull(result);

            _saleRepositoryMock.Verify(x => x.Create(sale), Times.Once());
        }
Example #6
0
        public async void Create_NoErrorsOccurred_ShouldReturnResponse()
        {
            var mock = new ServiceMockFacade <ISaleService, ISaleRepository>();

            var model = new ApiSaleServerRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Sale>())).Returns(Task.FromResult(new Sale()));
            var service = new SaleService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          mock.ModelValidatorMockFactory.SaleModelValidatorMock.Object,
                                          mock.DALMapperMockFactory.DALSaleMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeTrue();
            mock.ModelValidatorMockFactory.SaleModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSaleServerRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <Sale>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SaleCreatedNotification>(), It.IsAny <CancellationToken>()));
        }
        public async Task Test_OnCreateSale_Trigger()
        {
            _saleCreateDto.CusId     = cus_id;
            _saleCreateDto.discount  = discount;
            _saleCreateDto.total     = total;
            _saleCreateDto.netTotal  = net_total;
            _saleCreateDto.timestamp = timestamp;
            _sale.SaleId             = 1;

            _saleCreateDto.SaleDetails = new List <SaleDetailCreateDTO>()
            {
                new SaleDetailCreateDTO()
                {
                    SaleId   = 1,
                    Total    = total,
                    Qty      = qty,
                    Price    = price,
                    ItemName = item_name
                },
            };

            await _saleService.Create(_saleCreateDto);

            _saleRepo.Verify(a => a.InsertAsync(It.Is <Sale>(b =>
                                                             b.CusId.Equals(_saleCreateDto.CusId) &&
                                                             b.total.Equals(_saleCreateDto.total) &&
                                                             b.netTotal.Equals(_saleCreateDto.netTotal) &&
                                                             b.discount.Equals(_saleCreateDto.discount) &&
                                                             b.SalesDate.Equals(_saleCreateDto.timestamp)

                                                             )), Times.Once);

            _saleDetailRepo.Verify(a => a.InsertAsync(It.Is <SaleDetails>(b =>

                                                                          b.Price.Equals(_saleCreateDto.SaleDetails.First().Price) &&
                                                                          b.ItemName.Equals(_saleCreateDto.SaleDetails.First().ItemName) &&
                                                                          b.Qty.Equals(_saleCreateDto.SaleDetails.First().Qty)

                                                                          )), Times.Once);
        }
        public ActionResult Create(SaleViewModel input)
        {
            SaleViewModel cvm = new SaleViewModel();

            cvm.Sale_Product   = input.Sale_Product;
            cvm.Sale_UnPrice   = input.Sale_UnPrice;
            cvm.Sale_FristDate = input.Sale_FristDate;
            cvm.Sale_LastDate  = input.Sale_LastDate;
            SaleService    service = new SaleService();
            ProductService os      = new ProductService();

            if (service.Create(cvm))
            {
                os.updatesale(input.Sale_Product);
                return(RedirectToAction("Index", "dashboardSale"));
            }
            else
            {
                TempData["message"] = "有此產品了";
                return(RedirectToAction("Index", "dashboardSale"));
            }
        }
Example #9
0
        public async void Test_Create_Sale_Service()
        {
            var fakeContext = new FakeContext("Create_Sale_Service");

            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 sale    = new Sale();
                sale.ProductId = 1;
                sale.Quantity  = 10;
                var response = await service.Create(sale);

                var newSale = (from s in repository.GetAll()
                               where s.Quantity == 10
                               where s.ProductId == 1
                               select s).FirstOrDefault();

                Assert.IsType <Sale>(newSale);
                Assert.Equal("{ Message = Venda efetuada com sucesso. }", response.ToString());
                Assert.Equal(6, newSale.Id);
                Assert.Equal(688.80M, newSale.Total);
                Assert.Equal(2020, newSale.CreatedAt.Year);
            }
        }
Example #10
0
        public async void Create_ErrorsOccurred_ShouldReturnErrorResponse()
        {
            var mock          = new ServiceMockFacade <ISaleService, ISaleRepository>();
            var model         = new ApiSaleServerRequestModel();
            var validatorMock = new Mock <IApiSaleServerRequestModelValidator>();

            validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiSaleServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>()
            {
                new ValidationFailure("text", "test")
            })));
            var service = new SaleService(mock.LoggerMock.Object,
                                          mock.MediatorMock.Object,
                                          mock.RepositoryMock.Object,
                                          validatorMock.Object,
                                          mock.DALMapperMockFactory.DALSaleMapperMock);

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

            response.Should().NotBeNull();
            response.Success.Should().BeFalse();
            validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiSaleServerRequestModel>()));
            mock.MediatorMock.Verify(x => x.Publish(It.IsAny <SaleCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never());
        }