public void PostCallsTheLogicToAddTheNewSale()
        {
            var model = new SaleModel();

              sut.Create(model);

              logic.Verify(it => it.AddSale(model));
        }
Exemple #2
0
        public ActionResult Create()
        {
            var model = new SaleModel
              {
            Date = DateTime.Today.ToString(Constants.DATE_FORMAT),
            Items = new List<SaleItemModel> { new SaleItemModel() }
              };

              return View(model);
        }
Exemple #3
0
        public ActionResult Create(SaleModel model)
        {
            logic.AddSale(model);

              return RedirectToAction("Create");
        }
Exemple #4
0
            public void ThrowsIfThereAreMissingProducts()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});

                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                Action Act = () => sut.AddSale(model);
                Act.ShouldThrow<Exception>().WithMessage("Unknown product [def]");
            }
Exemple #5
0
            public void UpdatesTheStock()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 5.50m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Name = "abc", Quantity = 22.35m});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "6"},
                  },
                };

                sut.AddSale(model);

                stocks.Should().HaveCount(1);
                stocks[0].Quantity.Should().Be(21.12m);
            }
Exemple #6
0
            public void DoesNotCommitTheTransactionIfThereAreMissingProducts()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 12.34m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});

                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                try
                {
                  sut.AddSale(model);
                }
                catch (Exception)
                {
                  // ignore
                }

                transaction.Verify(it => it.Commit(), Times.Never());
            }
Exemple #7
0
            public void DoesNotAddTheRootObjectIfAllItemsAreInvalid()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "1/1/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = null, Quantity = "1", Price = "1"},
                new SaleItemModel {ProductName = "b", Quantity = "", Price = "2"},
                new SaleItemModel {ProductName = "c", Quantity = "3", Price = ""},
                  },
                };

                sut.AddSale(model);

                sales.Should().BeEmpty();
            }
Exemple #8
0
            public void CommitsTheTransaction()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 5.50m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Name = "abc", Quantity = 22.35m});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "6"},
                  },
                };

                sut.AddSale(model);

                transaction.Verify(it => it.Commit());
            }
Exemple #9
0
            public void AddsTheCorrectValuesToTheRepository()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc"});
                products.Add(new Product {Id = 2, Name = "def"});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});
                stocks.Add(new Stock {Id = 2, ProductId = 2, Quantity = 10.05m});
                var model = new SaleModel
                {
                  CompanyName = "Microsoft",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddSale(model);

                sales.Should().HaveCount(1);
                var sale = sales[0];
                sale.ShouldBeEquivalentTo(new Sale
                {
                  Id = 1,
                  Company = new Company {Id = 1, Name = "Microsoft"},
                  Date = new DateTime(2000, 2, 3),
                  Items = new Collection<SaleItem>
                  {
                new SaleItem {Product = new Product {Id = 1, Name = "abc"}, ProductId = 1, Quantity = 1.23m, Price = 4.00m,},
                new SaleItem {Product = new Product {Id = 2, Name = "def"}, ProductId = 2, Quantity = 5.67m, Price = 8.00m,}
                  }
                });
                repository.Verify(it => it.SaveChanges());
            }
Exemple #10
0
            public void AddsTheCompanyIfNeeded()
            {
                companies.Add(new Company {Id = 1, Name = "Microsoft"});
                products.Add(new Product {Id = 1, Name = "abc", SalePrice = 1.23m});
                products.Add(new Product {Id = 2, Name = "def", SalePrice = 1.23m});
                stocks.Add(new Stock {Id = 1, ProductId = 1, Quantity = 22.35m});
                stocks.Add(new Stock {Id = 2, ProductId = 2, Quantity = 10.05m});
                var model = new SaleModel
                {
                  CompanyName = "Google",
                  Date = "2/3/2000",
                  Items = new[]
                  {
                new SaleItemModel {ProductName = "abc", Quantity = "1.23", Price = "4"},
                new SaleItemModel {ProductName = "def", Quantity = "5.67", Price = "8"},
                  },
                };

                sut.AddSale(model);

                companies.Should().HaveCount(2);
                companies[1].Name.Should().Be("Google");
            }