Example #1
0
        public void Execute(CreateSaleModel model)
        {
            var date = _dateService.GetDate();

            var customer = _database.Customers
                           .Single(p => p.Id == model.CustomerId);

            var employee = _database.Employees
                           .Single(p => p.Id == model.EmployeeId);

            var product = _database.Products
                          .Single(p => p.Id == model.ProductId);

            var quantity = model.Quantity;

            var sale = _factory.Create(
                date,
                customer,
                employee,
                product,
                quantity);

            _database.Sales.Add(sale);

            _database.Save();

            _inventory.NotifySaleOcurred(product.Id, quantity);
        }
        public void SetUp()
        {
            var customer = new Customer
            {
                Id = CustomerId
            };

            var employee = new Employee
            {
                Id = EmployeeId
            };

            var product = new Product
            {
                Id    = ProductId,
                Price = UnitPrice
            };

            _model = new CreateSaleModel()
            {
                CustomerId = CustomerId,
                EmployeeId = EmployeeId,
                ProductId  = ProductId,
                Quantity   = Quantity
            };

            _sale = new Sale();

            _mocker = new AutoMoqer();

            _mocker.GetMock <IDateService>()
            .Setup(p => p.GetDate())
            .Returns(Date);

            SetUpDbSet(p => p.Customers, customer);
            SetUpDbSet(p => p.Employees, employee);
            SetUpDbSet(p => p.Products, product);
            SetUpDbSet(p => p.Sales);

            _mocker.GetMock <ISaleFactory>()
            .Setup(p => p.Create(
                       Date,
                       customer,
                       employee,
                       product,
                       Quantity))
            .Returns(_sale);

            _command = _mocker.Create <CreateSaleCommand>();
        }